Extra sources for IIIF server, not only images
Project description
OAREPO IIIF
This package adds support for input loaders for IIIF server
Rationale
We would like to add support for loading images from non-image source. For example, loading n-th image from a PDF file, converting data into graphs etc.
Invenio support for IIIF
Invenio has support for IIIF server via invenio-iiif package. Unfortunately there is no extensibility mechanism for loading images from non-image sources.
This package adds this support.
Usage
Create an opener and register it to entry point oarepo-iiif.openers
. The uuid
contains an identification of the image. It is up to you to parse and interpret it.
def pdf_opener(uuid, app=None, **kwargs): # kwargs currently empty but keep them for extensibility
return binary stream of image data or None if can not handle the uuid
If the opener loads data not from file buckets but from another location,
you have to register a function that checks access (and raises werkzeug exception
if the access is denied). The entry point for this function is oarepo-iiif.checks
.
def pdf_check(uuid, app=None, **kwargs): # kwargs might contain 'version', 'region', 'size', 'rotation', 'quality', 'image_format'
"""
check permissions and return
* True if the access is ok
* None if can not handle
* raise an exception if access denied
"""
return True
See rest test for an example of these functions.
Then power up the server and hit IIIF url:
curl https://127.0.0.1:5000/api/iiif/v2/<uuid>/<region>/<size>/<rotation>/<quality>.<format>
How it works (for library developers)
As extensibility mechanism is not available, this library overrides invneio-iiif uuid_to_image_opener
and api_decorator_callback
in the app_loaded
callback. Keep this in mind if you have libraries
that perform similar task.
@app_loaded.connect
def loaded(sender, app=None, **kwargs):
with app.app_context():
current_oarepo_iiif = app.extensions['oarepo-iiif']
iiif_ext = current_app.extensions['invenio-iiif'].iiif_ext
# replace opener
prev_opener = iiif_ext.uuid_to_image_opener
iiif_ext.uuid_to_image_opener_handler(
lambda *args, **akwargs: current_oarepo_iiif.open(*args, app=app, **akwargs) or prev_opener(*args, **akwargs)
)
# replace decorator handler
prev_decorator_handler = iiif_ext.api_decorator_callback
def decorator_handler(*args, **akwargs):
ret = current_oarepo_iiif.check(*args, app=app, **akwargs)
if ret is not None:
return ret
return prev_decorator_handler(*args, **akwargs)
iiif_ext.api_decorator_handler(decorator_handler)
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
Built Distribution
Hashes for oarepo_iiif-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 576774d9a5ea9ace087f128564a8093faba65e65fb09e306220a740656400191 |
|
MD5 | eebf7a02aeb21624e54be63c966f59e2 |
|
BLAKE2b-256 | 0ef2e33a13f19169b92e27b59031cee828241be04e5dcfa628d398cee9f9844e |