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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.9 macOS 10.14+ x86-64

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

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.8 macOS 10.14+ x86-64

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

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

pyots-8.1.4-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.4-cp36-cp36m-manylinux2010_x86_64.whl (3.8 MB view details)

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

pyots-8.1.4-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.4.tar.gz.

File metadata

  • Download URL: pyots-8.1.4.tar.gz
  • Upload date:
  • Size: 17.4 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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4.tar.gz
Algorithm Hash digest
SHA256 6f0dd7779d85255f6a784416e5f9d97375cbc0bae3d64d2fdd12446deca2d90a
MD5 f7f46f09ed72f46704c70a860226d716
BLAKE2b-256 a7ae443b0d9334919277c42794036945e0204852749f0d8516ef6d153fe0713a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 daaaee22bb9fa74079b58327d5ea017363526580f5dff055f72bc7b089e6f09f
MD5 c0899985ed91bfdf8b4003e989c5250f
BLAKE2b-256 df1fea63dabbf34453a53fff1c084169d0ab121543f7aa17175833953ef97723

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.7 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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 6edabd1201d021e2e81d746dfcabe9d792ff62b1cee995be3586afe0fa2b33c5
MD5 4f3e43fe67eb3c6a824fe133b6092b27
BLAKE2b-256 e75f601a0a3a892ec660e124f5c25c0b9a6ab087878fec8899a9b73f3c073f8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f2de8c848381ecc5df13fcc7b068d684d02fd22915b37e1daeea17900cb18084
MD5 e2dd25ab04dc1247ade56a918d08c53c
BLAKE2b-256 1f037fc079a42b80beb1561efd2fa739c40054dd50d44e9416ca0c93e61db1f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 390.7 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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 742919501b94de784692a7419ad74755ac23eea0293bdc57e83a82aab66c6bc5
MD5 6aafd3daba240ff8f3f939a7e70d211c
BLAKE2b-256 5aa8c6cf27bdd286c51730a969a89ded65813910bd44ccdd182373d9db3af0df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b371bf7aaf01270fedef2f79bc0fd265659c6455f36f472fc6ec3319b2155236
MD5 fa445ce62b549f749d6d59b8418408ce
BLAKE2b-256 7dcedb779e330524ba586c3c0d54e7ad2f626c9ace2e4c9c24920b995fa6ae26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0bfbe636faa8c08c906ad8d9364ef7dfd6faf1729caa6d1894470f226a1f4c93
MD5 c577e0dbaefcc668ff8973110533db20
BLAKE2b-256 58a2dfffadf734b459ad18f9e4fe72f388dd7baf507001bc4911928852f5a25e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 b781b2f3eb6b26b01f198d0a56c206bade17906f1681e03fff8237f4a0e1ceea
MD5 0b2cf2e2e55f3c5b04f2b2374d8327a0
BLAKE2b-256 1227c2123c857c2a03698d2c44d0f5747bd4026112153cc38eb901ba49727afc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.4-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.59.0 CPython/3.9.2

File hashes

Hashes for pyots-8.1.4-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 523f93f6bc6bfb14b30f2b7970181297298333980f7c12a6a61f5217964334ba
MD5 7907fb7fbdbac92ee986e5ab647d7eef
BLAKE2b-256 08a42a08ad74afd31429763b4da60628e6fe38ff6739f37daa0416afd9b273d7

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