Skip to main content

Python wrapper for ot-sanitizer

Project description

pyots (PYthon OT Sanitizer)

Run Tests Build Python Wheels

PyPI PyPI

macOS ubuntu

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.7, 3.8, 3.9 or 3.10 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 .
  • while iterating changes, you will want to delete the temporary build and src/ots/build folders.

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 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 can modify fonts that are successfully sanitized, even when no changes are performed. Thus modified can sometimes be True when 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
from pathlib import Path

for filename in Path("src/tests/fonts/good").rglob("*"):
    result = pyots.sanitize(filename.absolute())
    if not result.sanitized:
        print('{}:\n{}'.format(filename, "\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.2.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distributions

pyots-8.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyots-8.2.0-cp310-cp310-macosx_10_9_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyots-8.2.0-cp310-cp310-macosx_10_9_universal2.whl (360.7 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-8.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyots-8.2.0-cp39-cp39-macosx_10_9_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyots-8.2.0-cp39-cp39-macosx_10_9_universal2.whl (360.7 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-8.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyots-8.2.0-cp38-cp38-macosx_10_9_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyots-8.2.0-cp38-cp38-macosx_10_9_universal2.whl (360.7 kB view details)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-8.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (723.9 kB view details)

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

pyots-8.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (329.2 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file pyots-8.2.0.tar.gz.

File metadata

  • Download URL: pyots-8.2.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0.tar.gz
Algorithm Hash digest
SHA256 137886295fa3d2ac70983077d74eb2cc81837c7ae360e407f574b444c15bb59a
MD5 33920d219d76459045b46c24e7620585
BLAKE2b-256 1a9c738a82183e7c75490e51891fce4de25843b3643a51431a2f909127179d9b

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-8.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b61275112f1b657048ac56b75f11d741ce3856b7991e36de8f43f615281071e4
MD5 4ae75c3663fc918002fb0d47167ef62a
BLAKE2b-256 5805e636e617548dd6fefd4a718a509a70e1405833ffa898779ce944646ad129

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyots-8.2.0-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.2 kB
  • Tags: CPython 3.10, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 434848fc79c95602b85df66eb40b74f2b90b67c1969a863b60c6ef62e292847a
MD5 a1452c6aa4d509d50ed5e6b700f877d0
BLAKE2b-256 20c2cde6034070a71a0b2891d928930d8c0b02f9aa2076ebc5ac4bb2957d7f10

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

  • Download URL: pyots-8.2.0-cp310-cp310-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.7 kB
  • Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4be6842851c6880a857e95d062a45c109adcc260e01c556ce12d1bb92d6225f1
MD5 7dd0c540e26f04fd600489cc93a5b7e1
BLAKE2b-256 0196e5c44068a8e4cbc587284b6ff1c5845743f3ce75a2009801a69457b4cdc6

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-8.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 968231461b80db621e253b52d819e9a7f1bd269cb90426c3a6d0d98edd05d82e
MD5 f3faabfe0c7d56bad706fb1ed2082b7b
BLAKE2b-256 c9746fd202ac7b2ff0d5fd7b545c514414316ef7062ba3bcd6627f6e3469e036

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyots-8.2.0-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.2 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 dcbc09f2c9e6d0473a5ffebcf7ed247d32075098710bbc7977c6ac3d1d17cd16
MD5 7e826aa672aa0eff144de1c1cd901b95
BLAKE2b-256 8f8a8e64781b8b021598ed27e3099e5f547f4bac904bf5fbb5795e294beb309e

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

  • Download URL: pyots-8.2.0-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.7 kB
  • Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d04fc31b4e255fa856ca78884cd081b8c476cac33b0300f5daafebbc85e67709
MD5 b6645114d63898705e8ff146b9a2e9b8
BLAKE2b-256 3f12d3ff8d6e12d363df8ea71ab4b4e6d307e4e689d7cf094f885283d2be3a1a

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-8.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 600257621a30c480b6ef1abc05f7859a416e68e9509aa61caa326edd86bd2fbb
MD5 b9b32a1f9a1581ec69b587c3aa368f33
BLAKE2b-256 72be33b232825f810b3ad8dbc4091fa36b8a0170d413c351b97acd7731f75916

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyots-8.2.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.2 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7f5671e2420abbd402cf3dfe83abcf80886b1b490988d2ff34f27f1acb51e6cd
MD5 47b117009e407c611e497f3b628e9627
BLAKE2b-256 4d01650d364f8b8b55c466c7db54d70c44791fa84dda294ba30663a1cf827623

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

  • Download URL: pyots-8.2.0-cp38-cp38-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.7 kB
  • Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e9913bbcbcabdd2dc77ecdaf1e6217cc6a428358f4d1796120cb8dca1475f510
MD5 eba6c863477a634aad235f5642c3de38
BLAKE2b-256 6bc7693221ab61b227c53651fe6f11444993a2dccad5d0c8833221008e96aa46

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-8.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a55c836271da91bc69c97c54f24c53d5a66a153fa47ef40f05872d9a1c2fb7c7
MD5 e5720f27e3b1b73df93f79cbdc556c0e
BLAKE2b-256 7f2ee6a4cc3636d6e85efa6787c27d35b21f1d36e0a6f98a5c081c7814a6373a

See more details on using hashes here.

File details

Details for the file pyots-8.2.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyots-8.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.2 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5fc5272289f14959456d4ec282371754c2ce78f2cb6002dd186666f38c9b707b
MD5 4e721ecdb6d045db2378a77d39ce4e13
BLAKE2b-256 f6f273d8eff1bb18b93f2c44db238e2ce8f05a10e4c3796d5dea15f757cdbfad

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