Skip to main content

fastapi-router-variants

Latest Version MIT License Build Status Codecov semantic-release

Declare a route once and get path variants, API versioning and per-version OpenAPI documentation for FastAPI — for free.

fastapi-router-variants wraps APIRouter with a RouterWrapper that expands a single route declaration into every variant it should serve — multiple paths, multiple version prefixes (/v1/..., /v2/...), multiple mount prefixes, with deprecation handled automatically — then builds a separate OpenAPI schema per version and mounts Swagger UI / ReDoc / openapi.json for each of them.

Install

pip install fastapi-router-variants
# or
uv add fastapi-router-variants

Usage

from fastapi import FastAPI

from fastapi_router_variants import RouterDefaults, RouterWrapper


class ApiDefaults(RouterDefaults):
    prefix = "/api"           # mount every route under /api
    version = True            # force versioning on every route
    version_range = (1, 3)    # generate v1, v2, v3
    version_default = 3       # the version served on unversioned doc URLs


RouterWrapper.defaults = ApiDefaults()

router = RouterWrapper()


@router.get("/users/{user_id}")
def get_user(user_id: int) -> dict[str, int]:
    return {"id": user_id}


app = FastAPI()
app.include_router(router.base)

The single get declaration above registers GET /api/v1/users/{user_id}, GET /api/v2/users/{user_id} and GET /api/v3/users/{user_id}.

Path variants and flavors, versioning helpers, routing specs, per-version OpenAPI documents, custom categories and HTTP-error auto-documentation are all covered in the documentation.

Documentation

Full documentation is available at toilal.github.io/fastapi-router-variants. A preview of the in-progress develop branch is published at toilal.github.io/fastapi-router-variants/dev.

Requirements

  • Python ≥ 3.12
  • FastAPI ≥ 0.115

License

MIT © Rémi Alvergnat

CHANGELOG

v0.2.4 (2026-10-15)

Bug Fixes

  • deployment: Document the flavor deployment precedence (4b5a61f)

  • deployment: Keep each route flavor's own deployment (26eca97)

v0.2.3 (2026-10-07)

Bug Fixes

  • openapi: Document effective include routes from FastAPI 0.137 (98eb2e6)

  • openapi: Rebuild included routes from their effective context (964c508)

v0.2.2 (2026-07-25)

Bug Fixes

  • openapi: Clarify WebSocket route rebinding (26360ed)

  • openapi: Document preserved dependency overrides (ce4e7f5)

  • openapi: Isolate flattened routes between apps (62b7161)

  • openapi: Preserve overrides when flattening routers (13b8175)

  • openapi: Remove project-specific changelog entry (36d8fc8)

  • openapi: Remove project-specific implementation notes (e2150fc)

v0.2.1 (2026-07-20)

Bug Fixes

  • Flatten lazily-mounted routers to avoid FastAPI >=0.139 memory regression (#15, 21db307)

v0.2.0 (2026-07-05)

Features

v0.1.0 (2026-07-05)

  • Initial Release

Changelog entries are generated automatically by python-semantic-release from Conventional Commits on release.

Metadata

Release files for fastapi-router-variants 0.2.4

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

Source distribution (sdist)

Source distribution for fastapi-router-variants 0.2.4
File Size Uploaded Provenance Actions
fastapi_router_variants-0.2.4.tar.gz 159.5 kB Without provenance Details for fastapi_router_variants-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-router-variants 0.2.4
File Interpreter ABI Platform Actions
fastapi_router_variants-0.2.4-py3-none-any.whl Python 3 none any Details for fastapi_router_variants-0.2.4-py3-none-any.whl

Total release size: 186.1 kB

Release files / fastapi_router_variants-0.2.4.tar.gz

Download URL fastapi_router_variants-0.2.4.tar.gz
Size 159.5 kB
Tags Source
SHA-256 checksum
How to use checksums
08636975f9aac3a5a1b643f5b07c45bf8e23ca4d0bcdd8bdefc82fce8bdc54a8
BLAKE2b-256 checksum
How to use checksums
ae61c1980f8b5cddeb15916db03528e6bc97b8e186d1f121d01011d8aaf169b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fastapi_router_variants-0.2.4-py3-none-any.whl

Download URL fastapi_router_variants-0.2.4-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8bc7c398ebd161794fdbd6197744617c2a46ff83d10fb55f6cbbc4766f387eb
BLAKE2b-256 checksum
How to use checksums
a9696e2f20dbc6091d9bbaf635250d730288ffb82cee356e25ba0b8a67b3f0fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fastapi-router-variants 0.2.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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