Skip to main content

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

  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
  1. 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"}
  1. 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

fastapi_auto_router-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_auto_router-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

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

Hashes for fastapi_auto_router-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3fc0375c21a407b5667b567fb82fb85a8396f9cd2d227788217a5aa3f0560eb
MD5 6b60a9b09793adc71eecdc9a814f15c8
BLAKE2b-256 e054242e44ebf023eac3959d220a4dd9649255ecb06e6f2c204fdb95665ea949

See more details on using hashes here.

File details

Details for the file fastapi_auto_router-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_auto_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32ffc954e0b38e5d9f186aeb1e332d6834d4f8e764647ce5ff93b33cee885c88
MD5 5bebfe7aace02c149e48a33c741b0f93
BLAKE2b-256 a2d3bfc1429df7f90c37ede51fff17841b8b5184b1fb93e80fb6659d0ff6fc4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page