Skip to main content

A tool creating JSON manifests compliant with IIIF presentation API 3.0

Project description

pyIIIFpres

Build Status

This is a Python module built for easing the construction of JSON manifests compliant with IIIF API 3.0 in a production environment, similarly to iiif-prezi for earlier versions of the protocol.

NOTE: This is NOT a reference implementation. Pull requests and issues are welcome!

Installation

The library uses only standard libraries and can be installed using pip:

pip install git+https://github.com/giacomomarchioro/pyIIIFpres

Basic usage

The module maps the API structure to Python classes. The user set_ objects that can have only one value (e.g. id) and add_ objects that can have multiple entities (e.g. labels). As an example, we will execute the Simple Manifest - Book recipe from the IIIF cookbook. More examples from the cookbook in the examples folder of this repository.

from IIIFpres import iiifpapi3
iiifpapi3.BASE_URL = "https://iiif.io/api/cookbook/recipe/0009-book-1"
manifest = iiifpapi3.Manifest()
manifest.set_id(extendbase_url="manifest.json")
manifest.add_label("en","Simple Manifest - Book")
manifest.add_behavior("paged")

#        label       width height id                                                                            service  
data = (("Blank page",3204,4613,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f18","/full/max/0/default.jpg"),
        ("Frontispiece",3186,4612,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f19","/full/max/0/default.jpg"),
        ("Title page",3204,4613,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f20","/full/max/0/default.jpg"),
        ("Blank page",3174,4578,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f21","/full/max/0/default.jpg"),
        ("Bookplate",3198,4632,"https://iiif.io/api/image/3.0/example/reference/59d09e6773341f28ea166e9f3c1e674f-gallica_ark_12148_bpt6k1526005v_f22","/full/max/0/default.jpg"),)

for idx,d in enumerate(data):
    idx+=1 
    canvas = manifest.add_canvas_to_items()
    canvas.set_id(extendbase_url="canvas/p%s"%idx) # in this case we use the base url
    canvas.set_height(d[2])
    canvas.set_width(d[1])
    canvas.add_label("en",d[0])
    annopage = canvas.add_annotationpage_to_items()
    annopage.set_id(extendbase_url="page/p%s/1" %idx)
    annotation = annopage.add_annotation_to_items(target=canvas.id)
    annotation.set_id(extendbase_url="annotation/p%s-image"%str(idx).zfill(4))
    annotation.set_motivation("painting")
    annotation.body.set_id("".join(d[3:]))
    annotation.body.set_type("Image")
    annotation.body.set_format("image/jpeg")
    annotation.body.set_width(d[1])
    annotation.body.set_height(d[2])
    s = annotation.body.add_service()
    s.set_id(d[3])
    s.set_type("ImageService3")
    s.set_profile("level1")

manifest.json_save("manifest.json")

Debug the manifest

When you are populating a new IIIF type from scratch some helpful function can be used for spotting errors.

.inspect() method returns a JSON representation of the object where the recommended and required fields are shown:

from IIIFpres import iiifpapi3
manifest = iiifpapi3.Manifest()
manifest.inspect()

.show_errors_in_browser() method open a new browser tab highlighting the required and recommended fields.

manifest.show_errors_in_browser()

Reading the manifest (experimental)

A json file compliant with presentation API3 can be read as follow:

from IIIFpres.utilities import read_API3_json
mymanifest = read_API3_json('manifest.json')

This map Canvas, Annotation and the major IIIF types to iiifpapi3 classes, loading the rests as dicts.

See the project wiki for information regarding getting image sizes automatically, improve the writing performance and more.

Acknowledgements

I would like to thanks Martim Passos for reporting issues, and IIIF community and coordinators.

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

pyIIIFpres-0.1.1.tar.gz (141.4 kB view details)

Uploaded Source

Built Distribution

pyIIIFpres-0.1.1-py3-none-any.whl (143.1 kB view details)

Uploaded Python 3

File details

Details for the file pyIIIFpres-0.1.1.tar.gz.

File metadata

  • Download URL: pyIIIFpres-0.1.1.tar.gz
  • Upload date:
  • Size: 141.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pyIIIFpres-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2cc3e46f1df8410d72ea95db712fcbe8ff42e58e1ef0f4a9d0766fece14bd13d
MD5 5e4f2238e094a249423ad1809f426375
BLAKE2b-256 29635ad15fd40a82f8789e85a0bb2f59b08218c6986eeb67304d22b317845148

See more details on using hashes here.

File details

Details for the file pyIIIFpres-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyIIIFpres-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 143.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for pyIIIFpres-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4bc157abe205019af4b88296b6a9504b317a7d8216b2eed09d7b266d36bcfaa9
MD5 17c6d418a2b2256a2cfd07dc62f7e4b8
BLAKE2b-256 434270502122a2febf043dd3693360c683dd432afff5d577e6b32ee2fe26f3d4

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