File-based routing for Python backend frameworks (FastAPI, Flask)
Project description
REROUTE
File-based routing for Python backends - Inspired by Next.js, powered by FastAPI/Flask
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
- Parameter Injection: FastAPI-style parameter extraction (Query, Path, Header, Body, etc.)
- Pydantic Models: Generate data validation models with CLI
- Framework Adapters: Works with FastAPI (Flask, Django support coming)
- Interactive CLI: Next.js-style project scaffolding with beautiful prompts
- Code Generation: Quickly generate routes, CRUD operations, models, and tests
- Environment Config: .env file support with auto-loading
- Powerful Decorators: Rate limiting, caching, validation, and more
- API Versioning: Built-in support for base path prefixes (e.g.,
/api/v1)
Installation
pip install reroute
Quick Start
# Create a new project
reroute init myapi
# Navigate to project
cd myapi
# Install dependencies
pip install -r requirements.txt
# Run the server
python main.py
Visit http://localhost:7376/docs for interactive API documentation.
Documentation
📚 Complete Documentation - Full guides, API reference, and examples
Quick links:
- Getting Started - Installation and first route
- CLI Commands - Complete CLI reference
- API Reference - RouteBase, parameters, decorators, config
- Examples - CRUD, authentication, rate limiting, caching
- Contributing - How to contribute to REROUTE
How It Works
REROUTE uses your folder structure to create API routes. Each folder becomes a URL path, and each page.py file defines the route handlers.
app/routes/hello/page.py → /hello
app/routes/users/page.py → /users
app/routes/posts/page.py → /posts
API Versioning with Base Path:
Instead of creating nested folders, use API_BASE_PATH in config:
# config.py
API_BASE_PATH = "/api/v1"
Now your routes are automatically prefixed:
app/routes/users/page.py → /api/v1/users
app/routes/posts/page.py → /api/v1/posts
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.
Configuration
Every project has a config.py file to customize server settings, routing behavior, and more.
API Versioning
Use API_BASE_PATH to prefix all routes (e.g., /api/v1).
Framework Support
- FastAPI - Fully supported with OpenAPI docs
- Flask - Coming soon
License
Apache License 2.0
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Support
- Documentation: https://cbsajan.github.io/reroute-docs
- Issues: GitHub Issues
- PyPI: pypi.org/project/reroute
Built with by developers, for developers.
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.1.1.tar.gz.
File metadata
- Download URL: reroute-0.1.1.tar.gz
- Upload date:
- Size: 46.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94dd83d947c76b1bc090418adc2e2b2cd465bc19887be59a3b8e861ddf85c21a
|
|
| MD5 |
8340deffb7713f8f75ef98c26a26c0db
|
|
| BLAKE2b-256 |
c545804e24c332d67f724e21af82f412c1654ee222b1047173d791a4cab4a12d
|
File details
Details for the file reroute-0.1.1-py3-none-any.whl.
File metadata
- Download URL: reroute-0.1.1-py3-none-any.whl
- Upload date:
- Size: 53.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceef43a94a7f10190b9537a93058af3b578ab588ee9357369f9313df9c2c53c3
|
|
| MD5 |
d0afbc9cd851f4ff6129c9b164d58e17
|
|
| BLAKE2b-256 |
e45733dfbc65593718eca2e46c39520e437ae956e70b6cc4abbb2f460d633d42
|