SanF
A IIIF Image API 3.0 server implementation built with FastAPI, supporting up to Level 2 compliance. It can be used as a standalone server or embedded as a package within an existing FastAPI application.
Features
GET /iiif/{identifier}/info.jsonGET /iiif/{identifier}/{region}/{size}/{rotation}/{quality}.{format}- 303 redirect from
GET /iiif/{identifier}toinfo.json - Level 2 parameters:
region:full,square,x,y,w,h,pct:x,y,w,hsize:max,w,,,h,pct:n,w,h,!w,hrotation:0,90,180,270(and arbitrary non-negative angles)quality:defaultformat:jpg,png
- CORS enabled (when using
create_app, default*)
Installation
pip install sanf
Development Setup
python3.12 -m venv .venv
source .venv/bin/activate
pip install -e .
Running as a Standalone Server
Source images are loaded from ./images by default.
uvicorn sanf.main:create_app --factory --reload
The root directory for the local file connector can be changed via the IIIF_SOURCE_ROOT environment variable.
IIIF_SOURCE_ROOT=/path/to/images uvicorn sanf.main:create_app --factory --reload
Using as a Package
Public API
| Symbol | Purpose |
|---|---|
IIIFServerSettings |
Settings dataclass |
create_app(settings) |
Creates a standalone FastAPI application |
create_iiif_router(settings) |
Creates an APIRouter for embedding into an existing application |
ImageSourceConnector |
Protocol definition for connectors |
LocalFileConnector |
Connector for local filesystem images |
ConnectorError / ImageNotFoundError |
Connector exceptions |
IIIFServerSettings
from sanf import IIIFServerSettings, LocalFileConnector
from pathlib import Path
settings = IIIFServerSettings(
connector=LocalFileConnector(root=Path("./images")),
cors_origins=["https://example.com"], # default: ["*"]
jpeg_quality=85, # default: 85
max_width=4096, # default: None (no limit)
max_height=4096, # default: None (no limit)
)
create_app — Standalone Application
Returns a complete FastAPI instance including CORS middleware.
from sanf import create_app, IIIFServerSettings, LocalFileConnector
from pathlib import Path
settings = IIIFServerSettings(connector=LocalFileConnector(root=Path("./images")))
app = create_app(settings)
create_iiif_router — Embedding into an Existing Application
Returns an APIRouter without CORS. CORS should be managed by the calling application.
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sanf import create_iiif_router, IIIFServerSettings, LocalFileConnector
from pathlib import Path
settings = IIIFServerSettings(connector=LocalFileConnector(root=Path("./images")))
app = FastAPI()
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["GET"])
app.include_router(create_iiif_router(settings), prefix="/iiif")
Custom Connectors
Any storage backend can be connected by implementing a class that conforms to the ImageSourceConnector protocol.
class MyS3Connector:
def fetch_image_bytes(self, identifier: str) -> bytes:
# Return image bytes from S3 or any other backend
...
- Raise
ImageNotFoundErrorwhen the identifier does not exist - Raise
ConnectorErrorfor backend failures - The
identifieris received as a URL-decoded string
Metadata
Release files for sanf 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sanf-1.1.0.tar.gz | 9.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sanf-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / sanf-1.1.0.tar.gz
| Download URL | sanf-1.1.0.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83e495bfeffc15cfefba514c8fa0f756fe69c52e5fe944e5caec79e191a7b3b1
|
|
BLAKE2b-256 checksum How to use checksums |
d7f51bde2f703cb8ced4b5e76800b10bd13161a176bfedd481d6d443f4d59701
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / sanf-1.1.0-py3-none-any.whl
| Download URL | sanf-1.1.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
928bf18d1b76a430e886d356672cc4729d6fe281225ee625969e6d31757f74ea
|
|
BLAKE2b-256 checksum How to use checksums |
581a0dc6a2213b92809ee8867352269865bb60ce47a2d359cc9b3525f06b6baa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|