Skip to main content

File-based routing for Python backend frameworks (FastAPI)

Project description

REROUTE Logo

REROUTE

File-based routing for Python backends

Inspired by Next.js, powered by FastAPI/Flask

PyPI version Python 3.8+ License


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
Your browser does not support the video tag.

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

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 Fully Supported Swagger UI, Scalar UI
Django Coming Soon -

License

Apache License 2.0

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Support


Built by developers, for developers.

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

reroute-0.3.0.tar.gz (192.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reroute-0.3.0-py3-none-any.whl (182.5 kB view details)

Uploaded Python 3

File details

Details for the file reroute-0.3.0.tar.gz.

File metadata

  • Download URL: reroute-0.3.0.tar.gz
  • Upload date:
  • Size: 192.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for reroute-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9a92e47186b5f6d2dbef51255c08941ba5a4dac7ef0377cc31951b59dc71329b
MD5 9addbed2ecfd0670085da5456561f8d0
BLAKE2b-256 3796d804e4d86d5836a02d3b684d6ebfdae134a52d48e9d99327c1fac4e4e44a

See more details on using hashes here.

File details

Details for the file reroute-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: reroute-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 182.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for reroute-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff8d8c100ccc396eb39de3a41b4eba84a966672b8d480b9aa763623579b5b625
MD5 d2c1bae533b985ce2d6e0b221a04095b
BLAKE2b-256 92361437aa15f257eb053fba7a15b038a2a6515fd18a33a4774532348c9c1e5c

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