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/ots/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.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distributions

pyots-8.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyots-8.2.1-cp310-cp310-macosx_10_9_x86_64.whl (329.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyots-8.2.1-cp310-cp310-macosx_10_9_universal2.whl (360.8 kB view details)

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

pyots-8.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyots-8.2.1-cp39-cp39-macosx_10_9_x86_64.whl (329.3 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyots-8.2.1-cp39-cp39-macosx_10_9_universal2.whl (360.8 kB view details)

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

pyots-8.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyots-8.2.1-cp38-cp38-macosx_10_9_x86_64.whl (329.3 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyots-8.2.1-cp38-cp38-macosx_10_9_universal2.whl (360.8 kB view details)

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

pyots-8.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.0 kB view details)

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

pyots-8.2.1-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.1.tar.gz.

File metadata

  • Download URL: pyots-8.2.1.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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1.tar.gz
Algorithm Hash digest
SHA256 f5c752b2f1a67855acb20b4e14c572150e3ac4d3cc367c2d2b25fcb5002b3f42
MD5 3591d4bc7238d0cecdeedee7eb24a3c7
BLAKE2b-256 8608863ad14cfaf1f39bdd06992f1b623d562475f158b5e3919981ca56e015a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e079114203cfe5b5dfc8818e0faf8f3184732bb092f175fcda5f4f0949e3c097
MD5 bd2f4ab6d2e65a9c699af6d2035d8cbc
BLAKE2b-256 54396f69af0eae5d2444ae474c48a479f59534a1aeec9940fd17b6a082935db3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp310-cp310-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.3 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a7d950cfd511946c7084bada6a571b5edd7515aadb7e41034a859fbc57870684
MD5 fa5e73be439f88371aa854e0e000d65b
BLAKE2b-256 ed52e1df0fc9fecb192c3bfd7ac214e7c588649378290468439e2fc00e5d7aa7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp310-cp310-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.8 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 71082dac68e2e15bb3570da3af2f21c13be0cde82a09326e43d97e88c6dff2b3
MD5 d8e1086d894806be07949c0c49df4a03
BLAKE2b-256 3c90f63f58625801c4c362b53e7b53e659663d8881c32fa500f5cc3c4951495b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67abe244cab4b6d439fb7f0af0fde8783650bfd4bea8ef0b9c18c0c7345418ad
MD5 b4d718743398a1ecfc343943064bd65e
BLAKE2b-256 662a580f4c1c32074f646f6de40d435e5986bd37474537cd4d5f1d8f6e5036d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.3 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 90f5a2a178902a2309a22af6753237adb676f23b58857cec6afd1141466fa0ac
MD5 6e66e69dfba9677fc971496855a7cecc
BLAKE2b-256 a9d4b4cfe00130cf57558430ef8129cd9d84313cc2cdc3ff20dd020fa8b259ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp39-cp39-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.8 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c280a94540bf12028f43f5c3ec69428436dab2a0d83c7fe536e04550c36a2f40
MD5 2d5c0a7f64a5af02e12dd831751bf72b
BLAKE2b-256 0a2717fc39035d8300dceed9a2eb2c9a9e1a6764d487703e853d6bbd50a8c34f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f9fa3d2d47581378d8fbc69f70107c9da22c6b59558292c00cf1687efeb6977
MD5 495c141f0cb9ecd6f199cbc9d7d1440f
BLAKE2b-256 163731148098b596af67a4782df1f297d1577341ed24a08d5c45b1717ed16531

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 329.3 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c7e8f32973038c892a519e8f93fdb49be7c6515459229ce161aaaf523f6c5319
MD5 b1a50204a989255d293428bafe9fa731
BLAKE2b-256 cd98897639ea7e302570262433d6d96f91b979e656b62b6fce5f0975a1e2ca44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-cp38-cp38-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 360.8 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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1b36f1d2d0ceab79d14123a2f236c76a3629c9c0b301fc2d8b0ba776a3ab11e2
MD5 5f0a9e3fecc3229476dc2b81882a0a81
BLAKE2b-256 4806812643027d484c4db89214f37a66d36a1bcb56395e7b2c045619c4ae4c57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5dc7b426ca14751bc15e0646ff813515b5efb0f50ece35d161f0fdad032aa25e
MD5 c0052a1f1b76b3c17db6fa1ed7334d3c
BLAKE2b-256 b088441c5f5eb9fa2c52d93096b4e86b9fe6604e13a2374dc82dc1f107bd631c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.2.1-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.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyots-8.2.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 089667341009fd944a5ec394be4c74ea9fb471b5b33614b345e625fd0e135197
MD5 f4fee8fb7a88dc6e6896616474875c3c
BLAKE2b-256 cd4b93cc82d2ad49cb5d713e2eed0a1d5bfe2f08e262a4bc813a7bb94ea94a88

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