# FastAPI Auto Router
Automatic router configuration for FastAPI based on filesystem structure.
## Installation
```bash
pip install fastapi-auto-router
```
## Usage
1. 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
```
2. In your router files, create FastAPI routers:
routers/user_management/users.py
```python
from fastapi import APIRouter
router = APIRouter()
@router.get("")
async def list_users():
return {"message": "List users"}
```
3. In your main FastAPI application, use AutoRouter:
```python
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
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-auto-router",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "automatic, configuration, fastapi, router",
"author": null,
"author_email": "Tony Outlier <Outlier@Chainer.Tech>",
"download_url": "https://files.pythonhosted.org/packages/44/d5/8b496023c0ba549b62f1722ad3e71a36125bf9ff5a3f1400fdf085ccfdff/fastapi_auto_router-0.1.1.tar.gz",
"platform": null,
"description": "# FastAPI Auto Router\n\nAutomatic router configuration for FastAPI based on filesystem structure.\n\n## Installation\n\n```bash\npip install fastapi-auto-router\n```\n\n## Usage\n\n1. Create your router files in a directory structure that matches your desired API paths:\n\n```\nyour_project/\n\u2514\u2500\u2500 routers/\n \u2514\u2500\u2500 user_management\n \u251c\u2500\u2500 users.py\n \u2514\u2500\u2500 {user_id}/\n \u2514\u2500\u2500 profile.py\n```\n\n2. In your router files, create FastAPI routers:\n\nrouters/user_management/users.py\n\n```python\nfrom fastapi import APIRouter\n\nrouter = APIRouter()\n\n\n@router.get(\"\")\nasync def list_users():\n return {\"message\": \"List users\"}\n```\n\n3. In your main FastAPI application, use AutoRouter:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_auto_router import AutoRouter\n\napp = FastAPI()\n# Initialize and load routers\nauto_router = AutoRouter(\n app=app,\n routers_dir=\"routers\", # Path to your routers directory\n api_prefix=\"/api/v1\" # Optional: prefix for all routes\n)\nauto_router.load_routers()\n```\n\nThis will create the following routes:\n\n- `/api/v1/user-management/users`\n- `/api/v1/user-management/{user_id}/profile`\n\n## Features\n\n- Automatic route configuration based on filesystem structure\n- Converts underscores to hyphens in route paths\n- Supports path parameters using {parameter_name} folders\n- Customizable API prefix\n- Works with any FastAPI application\n\n## License\n\nMIT License\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Automatic router configuration for FastAPI based on filesystem structure",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://github.com/forchain/fastapi-auto-router#readme",
"Homepage": "https://github.com/forchain/fastapi-auto-router",
"Issues": "https://github.com/forchain/fastapi-auto-router/issues",
"Repository": "https://github.com/forchain/fastapi-auto-router.git"
},
"split_keywords": [
"automatic",
" configuration",
" fastapi",
" router"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bb9e7b7c51162f5e12d8152cb24710f5e9d7100103fe91fee606565bf1308814",
"md5": "79978f536dcb787fad65334e0b290814",
"sha256": "d593f21050c14dd0355aa99efabb9be6317ffce964952952a80424178bc67cba"
},
"downloads": -1,
"filename": "fastapi_auto_router-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "79978f536dcb787fad65334e0b290814",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4192,
"upload_time": "2024-12-20T08:00:49",
"upload_time_iso_8601": "2024-12-20T08:00:49.631468Z",
"url": "https://files.pythonhosted.org/packages/bb/9e/7b7c51162f5e12d8152cb24710f5e9d7100103fe91fee606565bf1308814/fastapi_auto_router-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "44d58b496023c0ba549b62f1722ad3e71a36125bf9ff5a3f1400fdf085ccfdff",
"md5": "48c3fbc8c22923e245de2de65fd3ba6e",
"sha256": "c07168dadd5769e29c055d6a24bf6f14d0775747da6e38fd2293d1217252a98e"
},
"downloads": -1,
"filename": "fastapi_auto_router-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "48c3fbc8c22923e245de2de65fd3ba6e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6494,
"upload_time": "2024-12-20T08:00:50",
"upload_time_iso_8601": "2024-12-20T08:00:50.798074Z",
"url": "https://files.pythonhosted.org/packages/44/d5/8b496023c0ba549b62f1722ad3e71a36125bf9ff5a3f1400fdf085ccfdff/fastapi_auto_router-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 08:00:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "forchain",
"github_project": "fastapi-auto-router#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "fastapi",
"specs": [
[
">=",
"0.68.0"
]
]
},
{
"name": "uvicorn",
"specs": [
[
">=",
"0.15.0"
]
]
}
],
"lcname": "fastapi-auto-router"
}