Skip to main content

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.json
  • GET /iiif/{identifier}/{region}/{size}/{rotation}/{quality}.{format}
  • 303 redirect from GET /iiif/{identifier} to info.json
  • Level 2 parameters:
    • region: full, square, x,y,w,h, pct:x,y,w,h
    • size: max, w,, ,h, pct:n, w,h, !w,h
    • rotation: 0, 90, 180, 270 (and arbitrary non-negative angles)
    • quality: default
    • format: 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 ImageNotFoundError when the identifier does not exist
  • Raise ConnectorError for backend failures
  • The identifier is received as a URL-decoded string

Metadata

Release files for sanf 1.2.0

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

Source distribution (sdist)

Source distribution for sanf 1.2.0
File Size Uploaded Provenance Actions
sanf-1.2.0.tar.gz 11.9 kB With provenance Details for sanf-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sanf 1.2.0
File Interpreter ABI Platform Actions
sanf-1.2.0-py3-none-any.whl Python 3 none any Details for sanf-1.2.0-py3-none-any.whl

Total release size: 21.0 kB

Release files / sanf-1.2.0.tar.gz

Download URL sanf-1.2.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3060b7aa404f14075a14ecc4389a68ecada0c6fdfa55e01b3fed8a680880ef5d
BLAKE2b-256 checksum
How to use checksums
d50f0ba8f9ecd96d98612ef3e9ea04d272525f407893ccfd3d99318ba559d623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / sanf-1.2.0-py3-none-any.whl

Download URL sanf-1.2.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1785cf42f3f1528d9729965e8989c26f6a2e83ad91955dc3c00da99d7630eff
BLAKE2b-256 checksum
How to use checksums
2c456b74e4d185b8c90ffa03177c682ed8740f72b2eef40e812fed2620ac002d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for sanf 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sanf-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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