Skip to main content
https://travis-ci.org/mekarpeles/iiif2.svg

An implementation of the IIIF Image API 2.0 Specification

Installation

$ pip3 install iiif2

Usage

The iiif2 library includes an image processing component called IIIF, responsible for implementing the iiif image processing pipeline, and a Parse utility capable of extracting iiif parameters and their data from uris.

from iiif2 import IIIF
from iiif2.web import Parse

You can combine the IIIF and Parse objects to create iiif 2.0 image tiles using only:

  • a iiif image 2.0 uri and

  • a resolved image filepath

An image path may be provided in one of two ways. First, it can be manually specified as a string:

from iiif2 import IIIF, web

url = 'https://stacks.stanford.edu/image/iiif/'
      'ff139pd0160%252FK90113-43/full/full/0/default.jpg'

# a web server can return a rendered tile directly
# without ever saving tile to disk. Works on read-only fs:
tile = IIIF.render('images/file.jpg', *web.Parse(url))

# if we want, we can save tile (e.g. for caching)
tile.save('cache/%s' % web.urihash(url))

Example Web Service

An entire IIIF Web Service written in Flask in ~30 lines of code is provided in the examples/ folder.

import os.path
from flask import Flask, request, jsonify, send_file
from iiif2 import IIIF, web

PATH = os.path.dirname(os.path.realpath(__file__))
app = Flask(__name__)


@app.route('/<identifier>/info.json')
def info(identifier):
      return jsonify(web.info(request.url_root, identifier))


@app.route('/<identifier>/<region>/<size>/<rotation>/<quality>.<fmt>')
def iiif(**kwargs):
    params = web.Parse.params(**kwargs)
    path = resolve(params.get('identifier'))
    with IIIF.render(path, **params) as tile:
        return send_file(tile, mimetype=tile.mime)


def resolve(identifier):
    """Resolves a iiif identifier to the resource's path on disk.
    This method is specific to this server's architecture.
    """
    return os.path.join(PATH, 'images', '%s.jpg' % identifier)


if __name__ == "__main__":
    app.run(debug=True)

Release files for iiif2 0.0.32

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iiif2 0.0.32
File Size Uploaded
iiif2-0.0.32.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iiif2 0.0.32
File Interpreter ABI Platform
iiif2-0.0.32-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 16.4 kB

Release files / iiif2-0.0.32.tar.gz

Download URL iiif2-0.0.32.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
592d0b44b9e6da8ad7d3abd94a5853b20235b1c6b080fc5fd5d9e0cbe41bc075
BLAKE2b-256 checksum
How to use checksums
fed6acda542aef303068d2769c5f8d7d6aab3649c0700f62f111e7de707024d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / iiif2-0.0.32-py2.py3-none-any.whl

Download URL iiif2-0.0.32-py2.py3-none-any.whl
Size 9.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2ee36801319d01843541cd5276e3633e3758d5ca56e00c4649a7d2a37aabe2ea
BLAKE2b-256 checksum
How to use checksums
4a09bfc4214ab30e348851727ce61f91f66592f13e0cc2f9d8a45c829a754a83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.32 This release

2 release files

0.0.31

1 release file

0.0.3

2 release files

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page