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.8, 3.9, 3.10 or 3.11 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 python -m pip install -U 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 python -m 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.

If you wish to run tests comparing results from ots-python against pyots, be sure to python -m pip install opentype-sanitizer first, otherwise that set of tests will be skipped.

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-9.1.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distributions

pyots-9.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyots-9.1.0-cp311-cp311-macosx_11_0_arm64.whl (324.0 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pyots-9.1.0-cp311-cp311-macosx_10_9_x86_64.whl (351.5 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyots-9.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyots-9.1.0-cp310-cp310-macosx_11_0_arm64.whl (324.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pyots-9.1.0-cp310-cp310-macosx_10_9_x86_64.whl (351.5 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyots-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyots-9.1.0-cp39-cp39-macosx_11_0_arm64.whl (324.0 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pyots-9.1.0-cp39-cp39-macosx_10_9_x86_64.whl (351.5 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyots-9.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyots-9.1.0-cp38-cp38-macosx_11_0_arm64.whl (324.0 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pyots-9.1.0-cp38-cp38-macosx_10_9_x86_64.whl (351.5 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyots-9.1.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for pyots-9.1.0.tar.gz
Algorithm Hash digest
SHA256 914c30c02cec9dfd89bfc0adac2eb965792e6851b69bbcf5c3559cc511be7d0b
MD5 3650d2cd4bc60aeba523026a8fee32b7
BLAKE2b-256 a791124f0621b64aa4bc0cfb4287af80735288cee3ecd36ce612a8db7c2cc2fc

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 686594950502635c2f52083419e45995980d21afdb80a9707fb453d1bd613333
MD5 ef403072cfa7a096fee6dcbe6eb87132
BLAKE2b-256 90e71435a307a409ab4e2e01f418f053975e948bbdb760bbfebd9a36764dfc44

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a0c0ce63f72d3fb8df267e62f746469f5e8c8d9b0014ba8a9b7ae00ab77a527
MD5 f479866c4696192b84ea39cc1187dbaf
BLAKE2b-256 e78a554b8253ce4de8aea6546488083f39273c8ac30667a42dab17182848398b

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 98629875a10c60693d995cdca4a502210fb14da9d344153e6ac46e41b3046e59
MD5 ba10de902f655b47f7dec7fe7339a5a2
BLAKE2b-256 9c1f07f99a335068916a2fb2feeef72dbc31529adeafff96628248e99b64ec5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15872ab6f9c4f47c92e8494b51d4e0a5d47b19f9254fa20139f98ef59dbb4950
MD5 5326447166f75bb3207ab23ab53946e5
BLAKE2b-256 c8fc445334bed15dc440c888502d832fa56ede2c1ed3eb32c8f517e06d65a909

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91dfd85a0051d0ad142aa894250c1bcc9eaa4e5ac5d70de99376687c54c1c009
MD5 226813f8da4b6c576e08b37ae1cc8b32
BLAKE2b-256 5aa54ff505dd17e5ec1459f609bb662ae9156512561f8fb1fb8611a011e8d56f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8bd80c2a43fa55fff1c8943fee47eb675a30bf6f4065a3db25cdcb2b54d41b7a
MD5 677bc5a99394c58d1b32bcb01fa07753
BLAKE2b-256 c40135c62aff3ada1894bcadc342a9aedfaf22aaab3036ca1ac03c3d431bcf68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 931c41382f4b1673444055e971c5a76848c4a17207b4ae223fe7c3602a63d227
MD5 dba0fa3301506de11a45945f01fe6776
BLAKE2b-256 8923028ee2bc20b568b616ac54fd6ba2bbd3da977ade26a054e50ce98ce4dfce

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a271ea13e59c5c078ed3279625717da7e15648be1b12193d460eec9d7c1889f7
MD5 b333db3c7d12c3728be92e6318bdd69d
BLAKE2b-256 41dd1ac05fb337c9b82e86a5ef4003ac4ea485d27cc322d06d10f32c17e13132

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 02d3b17901600a58e61f45044f3cee548fafd6a3e8fcc3821d65ab351ab85bb1
MD5 f67297c4947ed5bcfd7409574ea8e0d4
BLAKE2b-256 fe9cf12441d8ad7e46afafc2f930d9f14b06b2eda1a733d7c03acaf35278d6d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d03ebd93b68f982ec420c576558b3c08629029de3b52f6a0fc971a32af3fd17
MD5 c2bdbc719ddb1ac2d63175de21eb2b65
BLAKE2b-256 330b282cfad5225f4d72c40ff199f5f95fb15bb8a1123a5ec86ab54cacbbd872

See more details on using hashes here.

File details

Details for the file pyots-9.1.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyots-9.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 948b0168685aee0890ac5e2105b24ff06c98ad7ac99106f68588b630db2c8c77
MD5 a1a1cecb4dda8523177ca2689047e39c
BLAKE2b-256 9ca4c4aca5c16d040027f5cb060ab6340afe269f091a4fcefed285d499449e21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-9.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d9bdefaed5ffaedc62ce9dd105497ecca25e33737d5065b4c52b20f8e856738a
MD5 8770de56ce3dd1390ff16e56de3b5b97
BLAKE2b-256 c9c981e49266b68047718d79b3a289dba25b1e04ba365eabcd759afd6b3e40f8

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