REROUTE¶
REROUTE brings the simplicity and elegance of Next.js-style file-based routing to Python web frameworks. Build clean, maintainable APIs with zero configuration.
Features¶
-
File-based Routing
Organize routes by folders and files, just like Next.js. No manual route registration needed. Your folder structure becomes your API structure.
-
Class-based Handlers
HTTP methods as class methods:
get(),post(),put(),delete(). Clean, intuitive, and Pythonic approach to API development. -
Powerful Decorators
Built-in rate limiting, caching, validation, and authentication. Extend functionality with custom decorators easily.
-
Multi-framework Support
Works with FastAPI and Flask. Django coming soon. Switch frameworks without rewriting your route logic.
-
Security Headers
OWASP-compliant security headers out of the box. CSP, HSTS, X-Frame-Options, and more - configured automatically.
-
CLI Scaffolding
Generate projects, routes, and models with CLI commands.
reroute initandreroute createfor rapid development.
Quick Start¶
Requirements¶
- Python 3.8+
- FastAPI or Flask
Installation¶
Create a Project¶
$ reroute init my-app --framework fastapi
==================================================
REROUTE Project Initialization
==================================================
? Would you like to generate test cases? Yes
? Would you like to set up a database? No
==================================================
Project Configuration Review
==================================================
Project Name: my-app
Framework: FASTAPI
Host: 0.0.0.0
Port: 7376
Include Tests: Yes
==================================================
? Does this look correct? Yes
Creating project: my-app
[ OK ] Creating project structure
[ OK ] Creating config.py
[ OK ] Creating logger.py
[ OK ] Generating FASTAPI application
[ OK ] Creating example route
[ OK ] Creating root and health routes
[ OK ] Creating test cases
[ OK ] Creating .env.example
[ OK ] Creating requirements.txt
[ OK ] Creating pyproject.toml
==================================================
[SUCCESS] Project created successfully!
==================================================
Project: my-app
Framework: FASTAPI
Location: /path/to/my-app
Next Steps:
1. cd my-app
2. uv venv
3. uv sync
4. uv run main.py
Happy Coding!
API Docs: http://localhost:7376/docs
Generate a Route¶
$ reroute create route --path /users --name User --methods GET,POST
[ OK ] Creating route directory
[ OK ] Generating route file
==================================================
[SUCCESS] Route created successfully!
==================================================
Route: /users
File: app/routes/users/page.py
Methods: GET, POST
Tag: User
This creates app/routes/users/page.py:
from reroute import RouteBase
from reroute.decorators import cache, rate_limit
class UserRoutes(RouteBase):
"""User API endpoints."""
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}
Run the Application¶
Visit:
- API Documentation: http://localhost:8000/docs
- Users Endpoint: http://localhost:8000/users
How It Works¶
Your folder structure becomes your 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 inheriting from RouteBase with HTTP methods:
from reroute import RouteBase
class UserRoutes(RouteBase):
def get(self):
"""Handle GET requests."""
return {"users": [...]}
def post(self):
"""Handle POST requests."""
return {"message": "Created"}
def put(self, id: int):
"""Handle PUT requests."""
return {"message": f"Updated {id}"}
def delete(self, id: int):
"""Handle DELETE requests."""
return {"message": f"Deleted {id}"}
What's Next?¶
-
Quick Start
Get up and running in 5 minutes with the full tutorial.
-
User Guide
Deep dives into routing, decorators, lifecycle hooks, and more.
-
API Reference
Complete API documentation for all REROUTE features.
-
Examples
Real-world patterns: CRUD, authentication, caching, and more.
Community & Support¶
- GitHub: github.com/cbsajan/reroute
- PyPI: pypi.org/project/reroute
- Issues: Report bugs or request features
- Contributing: Contributing Guide
License¶
REROUTE is released under the Apache License 2.0.