FastAPI File-Based Router 🚀
Motivation
Sveltekit ruined me 🤓! I made this package because:
- File-based routing is the bees knees.
- I like to watch the world burn.
- It's just easier, bro.
This Python module dynamically loads FastAPI routes from a specified directory structure. It is designed to streamline the integration of API routes into a FastAPI app, making it easy to manage large applications with many endpoints.
HOW TO USE
You can import routes and API Routers as usual, but whenever you want, if you structure your endpoints like below, it will loop over the directory and put all the routes correctly.
Example
📁 project_root/
├ 📁 routes/ # This folder is set as the directory in the load_routes function
│ ├ 📄 route.py # Translates to /api (base route of the directory)
│ │
│ ├ 📁 users/
│ │ ├ 📄 route.py # /api/users
│ │ ├ 📄 [user_id].py # /api/users/{user_id}
│ │ └ 📄 profile.py # /api/users/profile
│ │
│ ├ 📁 products/
│ │ ├ 📄 route.py # /api/products
│ │ └ 📁 [product_id]/
│ │ ├ 📄 route.py # /api/products/{product_id}
│ │ └ 📄 reviews.py # /api/products/{product_id}/reviews
│ │
│ └ 📁 settings/
│ ├ 📄 route.py # /api/settings
│ └ 📁 notifications/
│ ├ 📄 route.py # /api/settings/notifications
│ └ 📄 email.py # /api/settings/notifications/email
├ 📁 templates/
│ └ 📄 home.html # Not relevant to FastAPI routes
└ 📄 main.py # Where you set up your FastAPI app and call load_routes
Installation
Clone this repository or copy the script into your project directory:
pip install fastapi-file-router
Usage
from fastapi import FastAPI
from fastapi_file_router import load_routes
app = FastAPI()
load_routes(server, "routes", verbose=True)
# Optional
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
)
Logging
Enable verbose logging to get detailed output during the route loading process, which can be helpful for debugging:
load_routes(app, Path("./routes"), verbose=True)
Contributing
Contributions are welcome! Please fork the repository and open a pull request with your features or fixes.
License
Don't be a bozo.
Metadata
Release files for fastapi-file-router 0.1.17
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_router-0.1.17.tar.gz | 6.4 kB | Without provenance | Details for fastapi_file_router-0.1.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_file_router-0.1.17-py3-none-any.whl | Python 3 | none | any | Details for fastapi_file_router-0.1.17-py3-none-any.whl |
Total release size: 10.9 kB
Release files / fastapi_file_router-0.1.17.tar.gz
| Download URL | fastapi_file_router-0.1.17.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3a6f973762b1fbb392943aacd767caaa83d036e6000e55ca360d0ffbe0e9605
|
|
BLAKE2b-256 checksum How to use checksums |
84daa52b220d21f4e4da0dcd1af3fe71c46446f4631014e8423a2c8119d766a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.4 CPython/3.10.12 Linux/5.15.0-130-generic
|
Release files / fastapi_file_router-0.1.17-py3-none-any.whl
| Download URL | fastapi_file_router-0.1.17-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc605b526613ec0dc48bacdba304883e0873dfb1d11e75b72a9153dd5b09950d
|
|
BLAKE2b-256 checksum How to use checksums |
681a7757f27c57365a5240e9fcc63fd0821ac40480752824fc690330c245522c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.4 CPython/3.10.12 Linux/5.15.0-130-generic
|
Security for fastapi-file-router 0.1.17
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.