Skip to main content

Python library for working with IIIF Image and Presentation APIs

Project description

piffle

Python library for generating and parsing IIIF Image API URLs in an object-oriented, pythonic fashion.

Unit Test Status codecov Maintainability

Piffle is tested on Python 3.8—3.11.

Piffle was originally developed by Rebecca Sutton Koeser at Emory University as a part of Readux and forked as a separate project under emory-lits-labs. It was later transferred to Rebecca Sutton Koeser at the Center for Digital Humanities at Princeton.

Installation and example use:

pip install piffle

Example use for generating an IIIF image url:

>>> from piffle.image import IIIFImageClient
>>> myimg = IIIFImageClient('http://image.server/path/', 'myimgid')
>>> print myimg
http://image.server/path/myimgid/full/full/0/default.jpg
>>> print myimg.info()
http://image.server/path/myimgid/info.json"
>>> print myimg.size(width=120).format('png')
http://image.server/path/myimgid/full/120,/0/default.png

Example use for parsing an IIIF image url:

>>> from piffle.image import IIIFImageClient
>>> myimg = IIIFImageClient.init_from_url('http://www.example.org/image-service/abcd1234/full/full/0/default.jpg')
>>> print myimg
http://www.example.org/image-service/abcd1234/full/full/0/default.jpg
>>> print myimg.info()
http://www.example.org/image-service/abcd1234/info.json
>>> myimg.as_dict()['size']['full']
True
>>> myimg.as_dict()['size']['exact']
False
>>> myimg.as_dict()['rotation']['degrees']
0.0

Example use for reading a IIIF manifest:

>>> from piffle.image import IIIFImageClient
>>> from piffle.presentation import IIIFPresentation
>>>  manifest = IIIFPresentation.from_url('https://iiif.bodleian.ox.ac.uk/iiif/manifest/60834383-7146-41ab-bfe1-48ee97bc04be.json')
>>> manifest.label
'Bodleian Library MS. Bodl. 264'
>>> manifest.id
'https://iiif.bodleian.ox.ac.uk/iiif/manifest/60834383-7146-41ab-bfe1-48ee97bc04be.json'
>>> manifest.type
'sc:Manifest'
>>> for canvas in manifest.sequences[0].canvases[:5]:
...     image_id = canvas.images[0].resource.id
...     iiif_img = IIIFImageClient(*image_id.rsplit('/', 1))
...     print(str(iiif_img.size(height=250)))
...
https://iiif.bodleian.ox.ac.uk/iiif/image/90701d49-5e0c-4fb5-9c7d-45af96565468/full/,250/0/default.jpg
https://iiif.bodleian.ox.ac.uk/iiif/image/e878cc78-acd3-43ca-ba6e-90a392f15891/full/,250/0/default.jpg
https://iiif.bodleian.ox.ac.uk/iiif/image/0f1ed064-a972-4215-b884-d8d658acefc5/full/,250/0/default.jpg
https://iiif.bodleian.ox.ac.uk/iiif/image/6fe52b9a-5bb7-4b5b-bbcd-ad0489fcad2a/full/,250/0/default.jpg
https://iiif.bodleian.ox.ac.uk/iiif/image/483ff8ec-347d-4070-8442-dbc15bc7b4de/full/,250/0/default.jpg

Development and Testing

This project uses git-flow branching conventions.

Install locally for development (the use of a python virtualenv is recommended):

pip install -e .

Install test dependencies:

pip install -e ".[dev]"

Run unit tests: py.test or python setup.py test

Install pre-commit hooks

Anyone who wants to contribute to this codebase should install the configured pre-commit hooks:

pre-commit install

This will configure a pre-commit hooks to automatically lint and format python code with ruff and black.

Pre-commit hooks and formatting conventions were added at version 0.5, so git blame may not reflect the true author of a given change. To make git blame more accurate, ignore formatting revisions:

git blame <FILE> --ignore-revs-file .git-blame-ignore-revs

Or configure your git to always ignore styling revision commits:

git config blame.ignoreRevsFile .git-blame-ignore-revs

Publishing python packages

A new python packages is automatically built and published to PyPI using a GitHub Actions workflow when a new release is created on GitHub.

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

piffle-0.5.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

piffle-0.5.0-py2.py3-none-any.whl (15.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file piffle-0.5.0.tar.gz.

File metadata

  • Download URL: piffle-0.5.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for piffle-0.5.0.tar.gz
Algorithm Hash digest
SHA256 09bcc3a5ea0388a0169490cf774dc30b04dbcc5d7d2bcca792b32c39b3d56b5c
MD5 6072faa7029ea1ee43fe95ed568735d2
BLAKE2b-256 418b3d3ca75ae350da1ea86ab0cb6fed598a9e1864a50f320b6284d29daefaa5

See more details on using hashes here.

File details

Details for the file piffle-0.5.0-py2.py3-none-any.whl.

File metadata

  • Download URL: piffle-0.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for piffle-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 48b6f2d8d4b5a6a2d246f637014cb5e77248e8cfa9e61281e3a067c67be92860
MD5 2cbc4e2919973f6d2ab320f934f5572d
BLAKE2b-256 c9496a6aca092b8d9b19ca007eca59abdf39eb2067663632ddd6130fca2e0af1

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