Skip to main content

verselect

Header-based version routing for FastAPI.

verselect routes requests based on a date header (for example, X-API-VERSION: 2022-02-02). If a client sends a version that does not exist, the request falls back to the closest lower version. Unversioned routes are supported alongside versioned ones.

Русская версия: README.ru.md.

Highlights

  • Header-driven routing with a "closest lower version" fallback
  • Per-version OpenAPI schemas with a simple versions dashboard
  • Works with standard FastAPI routers and middleware

Install

pip install verselect

Quickstart

from contextvars import ContextVar
from datetime import date

from fastapi import APIRouter
from starlette.responses import Response

from verselect import HeaderRoutingFastAPI

api_version_var: ContextVar[date] = ContextVar("api_version")
router = APIRouter(prefix="/v1")
webhook_router = APIRouter(prefix="/v1")


@router.get("/users")
def users():
    return Response(f"Hello from {api_version_var.get()}", media_type="text/plain")


@webhook_router.post("/webhooks")
def webhooks():
    return {"saved": True}


app = HeaderRoutingFastAPI(
    api_version_header_name="X-API-VERSION",
    api_version_var=api_version_var,
)

app.add_header_versioned_routers(router, header_value="2022-01-10")
app.add_header_versioned_routers(router, header_value="2022-02-11")
app.add_unversioned_routers(webhook_router)

Send a request with a version header:

curl -H "X-API-VERSION: 2022-02-11" http://localhost:8000/v1/users

Version rules

  • Version format: ISO 8601 date (YYYY-MM-DD).
  • Exact matches win.
  • If there is no exact match, the closest lower version is selected.
  • If the requested version is older than the oldest available, a 404 is returned.

OpenAPI and docs

  • /openapi.json?version=YYYY-MM-DD returns the schema for a specific version.
  • /docs shows a dashboard of all available versions and links to their docs.

Development (uv)

uv sync --dev
uv run ruff check .
uv run ruff format --check .
uv run mypy .
uv run pytest

More examples live in tests/_resources.

Metadata

Release files for verselect 0.3.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 verselect 0.3.0
File Size Uploaded
verselect-0.3.0.tar.gz 71.9 kB Details

Built distribution (wheel)

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

Total release size: 74.9 kB

Release files / verselect-0.3.0.tar.gz

Download URL verselect-0.3.0.tar.gz
Size 71.9 kB
Tags Source
SHA-256 checksum
How to use checksums
299a787fd85e08a3e7232bc283c1ec6be2c0dc4e361406b1e0f7b220c9093453
BLAKE2b-256 checksum
How to use checksums
f0021965df608d00f8193be205d7ca37c2cc090d0c91b9e08dfab0b1560b1494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 3, 2026.

Transparency log

Release files / verselect-0.3.0-py3-none-any.whl

Download URL verselect-0.3.0-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfdf98c4fabf3ddf251dc791228610e170fa12686fa36c82de49ad1221c9096e
BLAKE2b-256 checksum
How to use checksums
b40c163c6621060d0d9df20878b44131a9013ab40000e3acb47478de20f6ad41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.1

2 release files

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