Skip to main content

File-based routing for Python backend frameworks (FastAPI, Flask)

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
  • Multi-framework Support: Works with FastAPI and Flask (Django coming soon)
  • 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

# With FastAPI
pip install reroute[fastapi]

# With Flask
pip install reroute[flask]

# Or using uv (faster)
uv pip install reroute[fastapi]

Quick Start

# Create a new project
reroute init myapi --framework fastapi

# Navigate to project
cd myapi

# Install dependencies
uv sync  # or: pip install -r requirements.txt

# Run the server
python main.py

Visit http://localhost:7376/docs for interactive API documentation.

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

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.2.4.tar.gz (145.9 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.2.4-py3-none-any.whl (143.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for reroute-0.2.4.tar.gz
Algorithm Hash digest
SHA256 e62f3a50c0831c0be3909fe726ee447577df6c86981f06196dc687a488250829
MD5 4f2ef3cfb8b56bc3c3deb814c73e2e01
BLAKE2b-256 ff81f39dc3ea132bc37202b1d614e0ce517e9006af991c2412431d1b9b048f00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reroute-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 143.8 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.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d2606cbb8dcce9b162d1012e9db7240cebde201007bbab06d996543bce13eaa3
MD5 94c60acf99340547572127311de898c2
BLAKE2b-256 78b3e132db7cfce0ee94232c0c7903285c5b80b8e5f6888658d9ad5def1c5def

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