fastapi-file-routing
Nuxt/Nitro-style file-based routing for FastAPI. The layout of a routes/
directory becomes your URL structure; each file exposes plain get, post,
... functions.
uv add fastapi-file-routing # or: pip install fastapi-file-routing
Usage
# main.py
from fastapi import FastAPI
from fastapi_file_routing import add_file_routes
app = FastAPI()
add_file_routes(app, "routes")
routes/
├── index.py → /
├── users/
│ ├── index.py → /users
│ ├── me.py → /users/me
│ ├── {id}.py → /users/{id}
│ └── {path...}.py → /users/{path:path} (catch-all)
└── _utils.py → ignored ("_" prefix = private helper)
Each route file exposes module-level functions named after HTTP methods
(get, post, put, patch, delete, head, options), sync or async:
# routes/users/{id}.py
async def get(id: int):
return {"user": id}
def delete(id: int):
return {"deleted": id}
These are ordinary FastAPI endpoint functions: typing, Depends,
response models and OpenAPI docs work as usual. Static routes are
registered before dynamic ones (/users/me wins over /users/{id}),
and uvicorn main:app --reload picks up route file changes out of the box.
Middleware, auth and the rest
The library does one thing: map files to routes. Cross-cutting concerns use FastAPI's own mechanisms:
- global middleware:
app.add_middleware(...) - per-route logic:
Depends(...)in the handler signature - per-tree config:
add_file_routes(app, "routes", prefix="/api", tags=["v1"], dependencies=[...])(keyword arguments are forwarded toinclude_router)
Errors at startup
add_file_routes raises before the app serves a single request when:
- the directory does not exist (
FileNotFoundError) - a route file defines no HTTP handler (
ValueError) - two files map to the same method and path, for example
users.pyandusers/index.py(ValueError)
Development
uv sync
uv run pytest
uv run ruff check . && uv run ruff format --check . && uv run ty check
See CONTRIBUTING.md.
License
MIT
Metadata
Release files for fastapi-file-routing 0.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 | Provenance | Actions |
|---|---|---|---|---|
| fastapi_file_routing-0.1.0.tar.gz | 4.6 kB | Without provenance | Details for fastapi_file_routing-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_file_routing-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_file_routing-0.1.0-py3-none-any.whl |
Total release size: 10.3 kB
Release files / fastapi_file_routing-0.1.0.tar.gz
| Download URL | fastapi_file_routing-0.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
082efe3d813a3ce6dd37a8d1d770569b87de7f07bcdd5cbb8d2917c30a4c260d
|
|
BLAKE2b-256 checksum How to use checksums |
c3eab86c63badbb9f5714bfd7fa9097c6ac9dce56785cc0f90e55da52275ba10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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_file_routing-0.1.0-py3-none-any.whl
| Download URL | fastapi_file_routing-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae4ce16e6cc8e9519ae77cd52832e194c073a580fc0158919e1bf429e4f04d95
|
|
BLAKE2b-256 checksum How to use checksums |
cb4c7224c93fda3f4355975541825a993c09e9e222d3b6426ffe6c4e1bd37cec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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-file-routing 0.1.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.
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.