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, or 3.8 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 source older than 7.1.7 might not build correctly since it used a different build system. Also, versions newer than the one specified in this repo might require adjustments in order to build correctly.
  • 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.tar.gz (17.3 kB view details)

Uploaded Source

Built Distributions

pyots-8.1.3-cp39-cp39-manylinux2010_x86_64.whl (745.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.9 macOS 10.14+ x86-64

pyots-8.1.3-cp38-cp38-manylinux2010_x86_64.whl (745.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

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

Uploaded CPython 3.8 macOS 10.14+ x86-64

pyots-8.1.3-cp37-cp37m-manylinux2010_x86_64.whl (746.2 kB view details)

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

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

Uploaded CPython 3.7m macOS 10.14+ x86-64

pyots-8.1.3-cp36-cp36m-manylinux2010_x86_64.whl (745.4 kB view details)

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

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

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: pyots-8.1.3.tar.gz
  • Upload date:
  • Size: 17.3 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.tar.gz
Algorithm Hash digest
SHA256 6b5a068edd3a0980b2c06fda257dd2a37de45788ea8c1456f549a19792c1846e
MD5 cb7db2ebb7779fb38fb2518f23a39dc6
BLAKE2b-256 3d2e9346d5315afd273d016c3b63e69eff6a432bee15f93f43b36f4cf5d04fe2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 745.0 kB
  • 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-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5cda3139057edd438348fadfd5a92df1a9e0e081e133fb401929109584341286
MD5 088a5152696704f3f282dede7fef6816
BLAKE2b-256 99e1aeb4d0f60470eabfb037d0d42b092490d55b717ec8b53a4d4f73bf30c76b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 332.2 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-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 a7c04466f948c63d1a047fb8b93008f45b6f9d41d5d9376a594279baaf33624d
MD5 16a23332ba10f00ba9710661be7dbd72
BLAKE2b-256 2de0e082ce9b2bb361e8b47ec9778186393d9e2bd3e552a6ba3126e47d288044

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 745.3 kB
  • 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-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e00242ad35062b8ae1849c9ad81c130cda3b5dbb18b54960ff41e8e84fb47556
MD5 b33ac2631e8c394252b395de728c1df6
BLAKE2b-256 01dc674ff95c087110bd506d5250ec67ab12820d09ab8d2bcf34966ed1f8b0c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 332.2 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-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7bc4d44b8354d01260f1d4263e46581f21e4f1c610db5e0f9dced03b81ae6f85
MD5 a69e42761c2bf6befb09c038f2c078e9
BLAKE2b-256 d86ba91b531e3e39ec5e880e2d489ba44c4ccf7a7900093803743d7bf52da33f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 746.2 kB
  • 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-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5092c2bf09c98dbd3554c19c5bb7f740ffd2f52af6fd1874cc8256f21d8b01be
MD5 6b70c5dad1c06ab18dff29c1945e8923
BLAKE2b-256 00bd3ce8bd8c7d70ce3dad96ea7adb0479afb7ece82d1c24ee106427cc070775

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 332.3 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-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 bf1725f6e3780b7bccccefabe01317e23fa554ac1be02bccad2a37aa59087745
MD5 ed6620721b841fe7565546497822b852
BLAKE2b-256 f9193cd7f52cfdcb0516be7e35d39751a3fa52f6d30d5ca642e3b4b78de5d6f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 745.4 kB
  • 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-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2e8c2af354801192a46e54abc794450c6157943f3b5dc93e30c076bc561f5e54
MD5 96b6b2eb3697e2b75a739954dcca565f
BLAKE2b-256 3c050cfe91e92fa334a5a6cbf88c21989d31a2a33c61f683e50e4fe9d5a6a3a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-8.1.3-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 332.2 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-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 05f131293ff24cfd120a8aad1172a89d7df0dac8b35db4325c610a2e46c194db
MD5 9bd11fc22371cc7d43c5b488c6441177
BLAKE2b-256 babab7e7430bafb42d7e81c0241d1179ab7eb41b63a853c5f1cf7d7f8a2031cf

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