Skip to main content

Python wrapper for ot-sanitizer

Project description

pyots (PYthon OT Sanitizer)

Python wrapper for OpenType Sanitizer, also known as just "OTS". It is similar to and partially based on ots-python, but builds OTS as a Python C Extension (instead of as an executable and calling through subprocess as ots-python does).

NOTE: Although this package is similar to ots-python, it is not a drop-in replacement for it, as the Python API is different.

Requirements

The project builds pip-installable wheels for Python 3.6, 3.7, 3.8, or 3.9 under Mac or Linux. It is possible this project will build and run with other Pythons and other operating systems, but it has only been tested with the listed configurations.

Installation with pip

If you just want to use pyots, you can simply run pip install pyots (in one of the supported platforms/Python versions) which will install pre-built, compiled, ready-to-use Python wheels. Then you can skip down to the Use section.

Installation/setup for developing pyots

If you'd like to tinker with the pyots code, you will want to get your local setup ready:

  • clone this repo
  • run python setup.py download to download the OTS source (which is not included in this project). You can modify the version value in setup.cfg under [download] to specify a different version of OTS. You'll also need to change the sha256 hash value that corresponds to the OTS tar.xz package. Note that this scheme has some limitations: OTS sources older than 8.1.3 might not build correctly since they used different build systems. Also, versions newer than the one specified in this repo might require adjustments in order to build correctly. What can we say, we're dependent on ots...
  • to build and install pyots after downloading OTS, you can run python setup.py install or pip install .

Testing

There is a test suite defined for exercising the Python extension. It makes use (and assumes the presence of) the downloaded OTS library source's test font data in src/ots so ensure you have run python setup.py download and have the ots folder under src. Invoke the tests with python -m pytest tests OR pytest tests (make sure you specify tests folder, otherwise pytest will discover and attempt to execute other Python tests within the ots tree, which will probably fail)

Use

Simplest case:

import pyots
result = pyots.sanitize('/path/to/font/file.ttf')

result is an OTSResult (namedtuple/lightweight object) with 3 attributes:

  • sanitized Boolean indicating whether the file was successfully sanitized
  • modified Boolean indicating whether the file was modified* during sanitization
  • messages Tuple of message strings generated during sanitization (may be empty)
  • Note: currently the back-end OTS code always modifies fonts that are successfully sanitized. Thus modified will be True for all cases where sanitized is True. Usually the modification is only to the modification date and related checksums. Thus, it might be possible to devise a better detection of modification, i.e. ignoring head.modified and other inconsequential modifications, but that was out-of-scope for this work.

Example: sanitizing a folder of font files

# sanitize a folder of fonts. Print messages for any that were not successfully sanitized.
import pyots
import os

foldername = 'path/to/folder'
for filename in os.listdir(foldername):
    filepath = os.path.join(foldername, filename)
    result = pyots.sanitize(filepath)
    if not result.sanitized:
      print('{}:\n{}'.format(filepath, "\n".join([m for m in result.messages])))

Options for sanitize()

  • Specify keyword output=<path_to_output_file> to the sanitize() command and the sanitized file will be saved to that location
  • Use quiet=True for sanitize() to suppress messages
  • Specify font_index=<index_in_TTC> when sanitizing a Collection (OTC/TTC) file and you want to sanitize only a particular index within the Collection (otherwise all will be sanitized per OTS's default behavior)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyots-8.1.4.post1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distributions

pyots-8.1.4.post1-cp39-cp39-manylinux2010_x86_64.whl (887.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pyots-8.1.4.post1-cp39-cp39-macosx_10_14_x86_64.whl (328.5 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

pyots-8.1.4.post1-cp38-cp38-manylinux2010_x86_64.whl (887.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyots-8.1.4.post1-cp38-cp38-macosx_10_14_x86_64.whl (328.5 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pyots-8.1.4.post1-cp37-cp37m-manylinux2010_x86_64.whl (888.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

pyots-8.1.4.post1-cp37-cp37m-macosx_10_14_x86_64.whl (328.5 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pyots-8.1.4.post1-cp36-cp36m-manylinux2010_x86_64.whl (887.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

pyots-8.1.4.post1-cp36-cp36m-macosx_10_14_x86_64.whl (328.5 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

Details for the file pyots-8.1.4.post1.tar.gz.

File metadata

  • Download URL: pyots-8.1.4.post1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1.tar.gz
Algorithm Hash digest
SHA256 70afd9ac678d2ea0fc5bc8c0082f261124260177fc746ff5046296cf16e9cc8e
MD5 00fa3e738744e141b08237e394e547e1
BLAKE2b-256 7915ef0d58afa2c2404255dbc7454d3841f6174bcae5110a2155b4dbea8aba5a

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 887.6 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 92f57d4c040ec9d2fd79b4c9e05335151447ed4821e4b1aa3539515f8c03e94e
MD5 14c9d29f51fe058af4fa20ceb465d49d
BLAKE2b-256 668bbc1a592b16230e5ae498f8334364acd715714fbacc0f282ec4c92ea193a0

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 328.5 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a5a166073b9c98490e1e3a2d9ac1f3145c48dac51a50f524f6ed0a9e43fafdec
MD5 a3e900b7602807edd1f9549e20c21872
BLAKE2b-256 1ea27311f6c328727b716243704f0f5647abbfb590ffad8f53314141bc6749d6

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 887.9 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c1ba0075738750218abcf4fef8bb5aaa804517a091802e04a5a3b0f9d36429c7
MD5 2b4bcfdbe1b1315db823881de7aa224e
BLAKE2b-256 c84750b66ad15b00cabd949535ba3b8d54c8597743dadf245d98d0c1d77d1d4e

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 328.5 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 82c99362d41ecc79a9e4e86e6374c1d457ac6229043a3260fa89a562dfd36c49
MD5 46ed41be8dcf55d9c5278853845c646f
BLAKE2b-256 8ad567d84809c86d4c4ea95dade47f6f09dd794241acac6d3525c13299dbec5b

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 888.2 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 494161c04a3dc980f2a1663ee65da84f654f17357eea69af3db38f2d82d9332a
MD5 a81321852542c3a39a26d05d313f8d91
BLAKE2b-256 f1011efc2af7ad0333213e5b2428e46d82d9d1d8c0c1fbd4d2af1b9d4ffe42b0

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 328.5 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ae926b9c69e699dcef1daa7f4c1081a10d3fdf62480a6de0fe6f2b47554acd78
MD5 2c71dc058a465ccbecf16b17e8994b64
BLAKE2b-256 cb6a782a85baaadc9182c10b3a23ef373bc0300ad515f77e6e685d56de754ddd

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 887.5 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c942cf1f2593e8bf8b3f98c145bed7e2cd4348a72f5e71ec3962bae931aa0bca
MD5 588cae2cc6126bc51ff20a1ddba2e41f
BLAKE2b-256 20b5e077919efb671919c0bae65ee4ed534d977a3adbcb1c9567f2012d8811fe

See more details on using hashes here.

File details

Details for the file pyots-8.1.4.post1-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyots-8.1.4.post1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 328.5 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.post1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 33027064a7bf8dc44964841c4c9df7fbb9b0a043b017d0c37793ab392dec34c2
MD5 e02ce3e1af1275cf4cce32fd52f4539e
BLAKE2b-256 9215d4f6e51d8d32050a2891d39e1ada750ab6e3dccc55d035f5ab286f0a95a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page