Automatic router configuration for FastAPI based on filesystem structure
Project description
FastAPI Auto Router
Automatic router configuration for FastAPI based on filesystem structure.
Installation
pip install fastapi-auto-router
Usage
- Create your router files in a directory structure that matches your desired API paths:
your_project/
└── routers/
└── user_management
├── users.py
└── {user_id}/
└── profile.py
- In your router files, create FastAPI routers:
routers/user_management/users.py
from fastapi import APIRouter
router = APIRouter()
@router.get("")
async def list_users():
return {"message": "List users"}
- In your main FastAPI application, use AutoRouter:
from fastapi import FastAPI
from fastapi_auto_router import AutoRouter
app = FastAPI()
# Initialize and load routers
auto_router = AutoRouter(
app=app,
routers_dir="routers", # Path to your routers directory
api_prefix="/api/v1" # Optional: prefix for all routes
)
auto_router.load_routers()
This will create the following routes:
/api/v1/user-management/users/api/v1/user-management/{user_id}/profile
Features
- Automatic route configuration based on filesystem structure
- Converts underscores to hyphens in route paths
- Supports path parameters using {parameter_name} folders
- Customizable API prefix
- Works with any FastAPI application
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_auto_router-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_auto_router-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3fc0375c21a407b5667b567fb82fb85a8396f9cd2d227788217a5aa3f0560eb
|
|
| MD5 |
6b60a9b09793adc71eecdc9a814f15c8
|
|
| BLAKE2b-256 |
e054242e44ebf023eac3959d220a4dd9649255ecb06e6f2c204fdb95665ea949
|
File details
Details for the file fastapi_auto_router-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_auto_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ffc954e0b38e5d9f186aeb1e332d6834d4f8e764647ce5ff93b33cee885c88
|
|
| MD5 |
5bebfe7aace02c149e48a33c741b0f93
|
|
| BLAKE2b-256 |
a2d3bfc1429df7f90c37ede51fff17841b8b5184b1fb93e80fb6659d0ff6fc4e
|