fastapi-routechain
Combine multiple APIRoute subclasses for FastAPI — with automatic conflict detection.
Installation
pip install fastapi-routechain
The problem
FastAPI's APIRouter accepts only a single route_class. If you want to use
multiple third-party route classes together (e.g. DishkaRoute for DI and
XmlRoute for XML support), you'd have to manually create a combined class.
Usage
ChainedAPIRouter — drop-in replacement for APIRouter
from fastapi_routechain import ChainedAPIRouter
from dishka.integrations.fastapi import DishkaRoute
from fastapi_xml import XmlRoute
router = ChainedAPIRouter(
route_classes=[DishkaRoute, XmlRoute], # priority = list order (MRO)
)
@router.get("/hello")
def hello():
return {"hello": "world"}
combine_routes — just the factory
from fastapi import APIRouter
from fastapi_routechain import combine_routes
MyRoute = combine_routes(DishkaRoute, XmlRoute)
router = APIRouter(route_class=MyRoute)
Priority and MRO
The order of classes in route_classes is the priority order — it directly maps
to Python's MRO (Method Resolution Order). The first class wins on conflicts.
# DishkaRoute.__init__ takes priority over XmlRoute.__init__
combine_routes(DishkaRoute, XmlRoute)
Conflict detection
fastapi-routechain warns you when combining classes that will silently lose
functionality — e.g. two classes that both override get_route_handler without
calling super().
# emits RouteConflictWarning
combine_routes(XmlRoute, SomeOtherHandlerRoute)
# raises RouteConflictError instead
combine_routes(XmlRoute, SomeOtherHandlerRoute, strict=True)
You can also check conflicts manually:
from fastapi_routechain import check_conflicts
issues = check_conflicts(RouteA, RouteB, RouteC)
for issue in issues:
print(issue)
API
| Symbol | Description |
|---|---|
ChainedAPIRouter |
APIRouter subclass accepting route_classes list |
combine_routes(*classes, strict=False) |
Returns a combined APIRoute subclass |
check_conflicts(*classes) |
Returns list of conflict description strings |
RouteConflictWarning |
Warning class emitted on soft conflicts |
RouteConflictError |
Exception raised in strict mode |
Metadata
Release files for fastapi-routechain 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_routechain-0.1.1.tar.gz | 32.8 kB | Without provenance | Details for fastapi_routechain-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_routechain-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for fastapi_routechain-0.1.1-py3-none-any.whl |
Total release size: 51.6 kB
Release files / fastapi_routechain-0.1.1.tar.gz
| Download URL | fastapi_routechain-0.1.1.tar.gz |
|---|---|
| Size | 32.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edcf6859e5044e695b80264f4a668165f7cd3126ec5f4264c4afcdc561beb67c
|
|
BLAKE2b-256 checksum How to use checksums |
23b3846c3039445eec23e352dfae0495deaa77476f623e3452d1c7dac12bf45b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / fastapi_routechain-0.1.1-py3-none-any.whl
| Download URL | fastapi_routechain-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eed6c68b66d53b2f4e71f967f5b1c234613e7568ccaafec6f071a2c3bbe89062
|
|
BLAKE2b-256 checksum How to use checksums |
f276e84851438e95c57563da958aec09511198ab757e681844e8a66e0fc5f4b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for fastapi-routechain 0.1.1
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.