Welcome to REROUTE¶
Modern file-based routing for Python backends
Here are the introductory sections and the tutorials to learn REROUTE.
You could consider this a book, a course, the official and recommended way to learn 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.
Why REROUTE?¶
-
File-based Routing
Organize routes by folders and files, just like Next.js.
No more manual route registration!
-
Class-based Handlers
HTTP methods as class methods:
get(),post(),put(),delete()Clean, intuitive, and Pythonic
-
Powerful Decorators
Built-in rate limiting, caching, validation, and more
Extend with custom decorators easily
-
Multi-framework Support
Works with FastAPI (Flask & Django coming soon)
Switch frameworks without rewriting routes
Quick Example¶
Get started in 2 minutes using CLI commands:
1. Install & Initialize¶
2. Generate a Route¶
This creates app/routes/user/page.py:
from reroute import RouteBase
from reroute.decorators import cache, rate_limit
class UserRoutes(RouteBase):
tag = "User"
@cache(duration=60)
def get(self):
return {"users": ["Alice", "Bob"]}
@rate_limit("5/min")
def post(self):
return {"message": "User created"}
3. Run Your API¶
That's it! Your routes are now available at /user with automatic OpenAPI documentation at /docs.
Features¶
File-based Routing¶
Organize your API by filesystem structure. Each folder becomes a route segment:
app/routes/
├── user/
│ └── page.py → /user
└── product/
├── page.py → /product
└── [id]/
└── page.py → /product/:id
Decorators¶
Built-in decorators for common API patterns:
@rate_limit("5/min")- Rate limiting per IP/user@cache(duration=60)- Response caching with LRU eviction@requires("admin", check_func=...)- Role-based access control@validate(schema={...})- Request validation@timeout(5)- Request timeout handling@log_requests()- Automatic request logging
Lifecycle Hooks¶
Control request/response flow with lifecycle methods:
class MyRoute(RouteBase):
def before_request(self):
# Authentication, validation
pass
def after_request(self, response):
# Add headers, transform response
return response
def on_error(self, error):
# Custom error handling
return {"error": str(error)}
Custom Configuration¶
Fine-tune REROUTE's behavior:
from reroute import Config
class MyConfig(Config):
PORT = 8000
API_BASE_PATH = "/api/v1"
ENABLE_CORS = True
CORS_ALLOW_ORIGINS = ["https://example.com"]
VERBOSE_LOGGING = True
What's Next?¶
-
Get up and running in 2 minutes
-
Deep dives into routing, decorators, and more
-
Complete API documentation
-
Real-world patterns and recipes
Community & Support¶
- GitHub: github.com/cbsajan/reroute
- PyPI: pypi.org/project/reroute
- Issues: Report bugs or request features
- Contribute: Contributing Guide
License¶
REROUTE is released under the Apache License 2.0.