File-based routing for Python backend frameworks (FastAPI)
Project description
REROUTE brings the simplicity of file-based routing to Python backend development. Just create files in folders, and they automatically become API endpoints.
Features
- File-based Routing: Folder structure maps directly to URL paths
- Class-based Routes: Clean, organized route handlers with lifecycle hooks
- FastAPI Integration: Full async support with automatic OpenAPI documentation
- Parameter Injection: FastAPI-style parameter extraction (Query, Path, Header, Body, etc.)
- Pydantic Models: Generate data validation models with CLI
- Interactive CLI: Next.js-style project scaffolding with beautiful prompts
- Code Generation: Quickly generate routes, CRUD operations, models, and tests
- Powerful Decorators: Rate limiting, caching, validation, and more
- Security Headers: OWASP-compliant security headers out of the box (CSP, HSTS, X-Frame-Options)
- Environment Config: .env file support with auto-loading
- API Versioning: Built-in support for base path prefixes (e.g.,
/api/v1)
Installation
# Install uv (if you don't have it)
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
# Install REROUTE with FastAPI
uv pip install reroute[fastapi]
Quick Start
# Create a new project
reroute init myapi
# Navigate to project
cd myapi
# Create virtual environment and install dependencies
uv venv
uv sync
# Run the server
uv run main.py
Visit http://localhost:7376/docs for interactive API documentation.
📺 Demo Video
Watch REROUTE in action! Check out our demo video to see:
- Project initialization with CLI
- File-based routing in action
- Security utilities (password hashing, JWT, validation)
- Integration with FastAPI
Click to play demo video (643 KB)
Generate Routes with CLI
# Generate a new route
reroute create route --path /users --name User --methods GET,POST
# This creates app/routes/users/page.py with:
# - GET endpoint for listing users
# - POST endpoint for creating users
# - Rate limiting and caching decorators
Documentation
Complete Documentation - Full guides, API reference, and examples
Build Documentation Locally
cd docs
pip install -r requirements.txt
mkdocs serve
Visit http://127.0.0.1:8000 to view the documentation.
Quick Links
- Getting Started - Installation and first route
- CLI Commands - Complete CLI reference
- Decorators - Rate limiting, caching, validation
- Security - Security headers and best practices
- API Reference - RouteBase, parameters, decorators, config
- Examples - CRUD, authentication, rate limiting, caching
How It Works
REROUTE uses your folder structure to create API routes:
app/routes/
users/
page.py -> /users
[id]/
page.py -> /users/{id}
products/
page.py -> /products
categories/
page.py -> /products/categories
Each page.py contains a class with HTTP methods:
from reroute import RouteBase
from reroute.decorators import cache, rate_limit
class UserRoutes(RouteBase):
tag = "Users"
@cache(duration=60)
def get(self):
"""Get all users."""
return {"users": ["Alice", "Bob"]}
@rate_limit("10/min")
def post(self):
"""Create a new user."""
return {"message": "User created", "id": 1}
Key Concepts
File-based Routing
Your folder structure is your API structure. No manual route registration needed.
Class-based Routes
Each route is a Python class with methods for HTTP verbs (get, post, put, delete, etc.).
Lifecycle Hooks
Routes support before_request, after_request, and on_error hooks for common patterns.
Decorators
Built-in decorators for rate limiting, caching, validation, and authentication.
Configuration
Every project has a config.py file to customize server settings, routing behavior, and security headers.
API Versioning
Use API_BASE_PATH to prefix all routes (e.g., /api/v1).
Framework Support
| Framework | Status | OpenAPI Docs |
|---|---|---|
| FastAPI | Fully Supported | Swagger UI, ReDoc |
| Flask | Removed in v0.3.0 | - |
| Django | Coming Soon | - |
Note: As of v0.3.0, REROUTE focuses exclusively on FastAPI for better async support, automatic OpenAPI documentation, and active maintenance.
License
Apache License 2.0
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Support
- Documentation: https://cbsajan.github.io/reroute
- Issues: GitHub Issues
- PyPI: pypi.org/project/reroute
Project details
Release history Release notifications | RSS feed
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 reroute-0.4.0.tar.gz.
File metadata
- Download URL: reroute-0.4.0.tar.gz
- Upload date:
- Size: 194.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0ceb98fdac110769988b7928f1a781ac35509031d0dfe9478585ceaf4d04319
|
|
| MD5 |
6b2e79314588f005cd6cc5fc3409770d
|
|
| BLAKE2b-256 |
9d2d9920b90e6cbafa273115225000f7f04854738442a398bdc666f9d374f1e2
|
File details
Details for the file reroute-0.4.0-py3-none-any.whl.
File metadata
- Download URL: reroute-0.4.0-py3-none-any.whl
- Upload date:
- Size: 182.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e03d54831884e2d6763c86efc14a729c393165e8608b9e922516f826c29589c8
|
|
| MD5 |
9addce3f6ee5de9ce783d81967f67f25
|
|
| BLAKE2b-256 |
778e90f9050384449d00ae79761adff9b34182f1db1cda7cfbe4f92aa4c12db0
|