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.3.post1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distributions

pyots-8.1.3.post1-cp39-cp39-manylinux2010_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

pyots-8.1.3.post1-cp39-cp39-macosx_10_14_x86_64.whl (390.6 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

pyots-8.1.3.post1-cp38-cp38-manylinux2010_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyots-8.1.3.post1-cp38-cp38-macosx_10_14_x86_64.whl (390.6 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pyots-8.1.3.post1-cp37-cp37m-manylinux2010_x86_64.whl (3.8 MB view details)

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

pyots-8.1.3.post1-cp37-cp37m-macosx_10_14_x86_64.whl (390.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pyots-8.1.3.post1-cp36-cp36m-manylinux2010_x86_64.whl (3.8 MB view details)

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

pyots-8.1.3.post1-cp36-cp36m-macosx_10_14_x86_64.whl (390.7 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1.tar.gz
Algorithm Hash digest
SHA256 c33fc0ba74d4802b458edfbc77ddc84323cc6122a1daa60d95eddbc93212567a
MD5 2cf0a7b273508c97a8eedad6cbba9069
BLAKE2b-256 e9ef2ff9c6d0e5a40698d147aaea92cd5fe82156a473027a96f28005d3999038

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c41eebf92da7c9746385e6398bb369acd3a76352095c6e6a49f2207ecc893060
MD5 90410eb655d42db2fc8db8946d02a956
BLAKE2b-256 acd704490c5bc250309e590c141e6c64e839327e451ad1ca6797cf0fa4b76703

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.6 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e3d730e3a6e0dd803c5593f08920290ffa6ac7df6dda0182236e8c3689b62d2a
MD5 65e24c21277c254601182327b195c2ab
BLAKE2b-256 9246800df5d03384675c346c851593392ffb9449cd1e5c9f64c391c611458fad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3d12c52695ed68abaeae92a8bd2466c264f67efbb3f4fee22b80187e37632d90
MD5 a8086d05d1f133e164a185e24b805f84
BLAKE2b-256 e872a31e857462666c672a7b7066a58c6cabfecd1e0be9cdeb4f8609e4b607c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.6 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a1ca2a03f47d0243ba576d74db8b1a10c4fec00b6ed4ccfee8b06c928fbb8e4a
MD5 afcd44a62aca26f6ef6cd12565797694
BLAKE2b-256 365907ae2b9c8bde619d2cab4d2c98a91a020991e613f0924952e9b279477546

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6973c6e707b6b5841f7d7cc63c65b85222521a728b8887dbd56de3b2baf293f7
MD5 a879cea0cf8ae9b7d705a1e47e8b5acc
BLAKE2b-256 65cb30093ecc231435f670ceefb3c0a9d715d91d9cf8bae56432488b2d497bc8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.7 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d2fc1dd55c0b011478e7dcf8bb5aa910dac84c8224e99b69cb6cab2cf8152c5f
MD5 b8fed2386ba521859de5830eb74107bd
BLAKE2b-256 f52ffa0596030ca9f84374d18fe23ab74f6983079975525ea7360bf5e6b64006

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.8 MB
  • 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9e221e3104c989b2bb318238b036a8f2006e801ee38ccc83c78e1f2f9fcffd9b
MD5 556a6c001ebc90e1f548e229a5dd23bf
BLAKE2b-256 d57c0035cdc96b3bac69cc39d721fc685274b4a3306ec2455ec3601ede9e5f01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3.post1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.7 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/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for pyots-8.1.3.post1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 9e650927f4c4abd12639e154db8f035ac7bfacf9c47991a04aeaff3b3d1ae330
MD5 1c2a4e954dad7a637de7a275248b1f7e
BLAKE2b-256 37975641be639e3e8fef21b39dd191e00ac65cd183271372d8ab883cd7b62e89

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