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

Uploaded Source

Built Distributions

pyots-0.2.0-cp38-cp38-manylinux2010_x86_64.whl (477.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

pyots-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl (318.6 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

pyots-0.2.0-cp37-cp37m-manylinux2010_x86_64.whl (478.1 kB view details)

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

pyots-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl (318.6 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

pyots-0.2.0-cp36-cp36m-manylinux2010_x86_64.whl (477.3 kB view details)

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

pyots-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl (318.6 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: pyots-0.2.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fd53d61a3ea4bfa6e1c341c13912695d91b065a826e747c1d0f5a33da1618ee9
MD5 47c2515da55c08cfdfab8823c49949c2
BLAKE2b-256 5e55caf3f1ec942db3acb01b39a8ca4d98cc837e0a7c14e0df9923b7dcfac98d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 477.4 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f9f10aa882b04ec9b4a27ca37fd5fad6c080d9510a3a550d19264f07ce60b1d8
MD5 b72d15f681bcc1f7e5549ed83cf50f7c
BLAKE2b-256 32ec4b092f993a2f80724fb2fa87ceea3b36546c8f287c2af21c390eb3638aaa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 318.6 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 fe9f96ccf166576af45164adc26a1abdf13e451cedbfa6f8d8fb5f0f4b0a242f
MD5 a0b4e99c94e29cabef15671ee6d0777f
BLAKE2b-256 c7a02230b8ab28c249a9cb50c902e635f20310b81f2511f9f612cdd4fa3fa792

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 478.1 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5191f338da3a568567afbf8c163f157efa10d7614cef96f9c2862179201c30c7
MD5 d583ec599317b48669ac252213c12d56
BLAKE2b-256 4a34070ce74306fdfaac2c157855f26c5f9ac7b43fcf7095d8c26a878ae16a74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 318.6 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f426bdf77cd8be53eccbd44b792a89ed32c365a32ed76f4e42453adb9205a264
MD5 88e35095bfc0aaeaa32e177db0e993e5
BLAKE2b-256 0918a761834b99e9ca75b8fc61ad42e9e0149c11efd89ff6d1311e14fab261c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 477.3 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9f5eec6ec5b5775654d41a13510e196855e2b9b3a3b4feb5b7e40b6c81ab52af
MD5 a6575492f0cd1b406aa522ce86ee447e
BLAKE2b-256 54dcf465571337d777ff599de6a5a81cda33cbe095786ca4f4144119b76a25df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyots-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 318.6 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for pyots-0.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 77a2084a80459fddb71498731d4ac6e682ab3a09fcd1c901efa88bb6ec3dbf57
MD5 4536bff111c37391c6c64907dfe70104
BLAKE2b-256 8241ccca3dc54864d208f475302f8cdbcb955e6256cc25179b1c0db1bc3cfabd

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