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.2.1.tar.gz (44.3 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.2.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_auto_router-0.2.1.tar.gz.

File metadata

  • Download URL: fastapi_auto_router-0.2.1.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for fastapi_auto_router-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b47257d67d7277686381760c96abebd4fe0f61efebbc10d357c61bf425a650c3
MD5 a0e7408ec08f04c43e1382ee7bac7b66
BLAKE2b-256 2fa1e06c0eac006373f04f25c2876a976235f52a11f5492f1fca673d7bdce008

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_auto_router-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa7b2287a557a77ef374a48994288beec2f24ea1c92d7d1fcc7e07a813af0129
MD5 b3a880ac9e33f7529b795c3f4602736f
BLAKE2b-256 49e966d87296a623ac591d97166e3f96a7c6db16df23c167537e22a6727e8cdd

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