Skip to content

REROUTE

File-based routing for Python backends

PyPI version Python 3.8+ License


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.

    Learn more

  • Class-based Handlers


    HTTP methods as class methods: get(), post(), put(), delete(). Clean, intuitive, and Pythonic approach to API development.

    Learn more

  • Powerful Decorators


    Built-in rate limiting, caching, validation, and authentication. Extend functionality with custom decorators easily.

    Learn more

  • Multi-framework Support


    Works with FastAPI and Flask. Django coming soon. Switch frameworks without rewriting your route logic.

    Adapters

  • Security Headers


    OWASP-compliant security headers out of the box. CSP, HSTS, X-Frame-Options, and more - configured automatically.

    Security

  • CLI Scaffolding


    Generate projects, routes, and models with CLI commands. reroute init and reroute create for rapid development.

    CLI


Quick Start

Requirements

  • Python 3.8+
  • FastAPI or Flask

Installation

pip install reroute[fastapi]
uv pip install reroute[fastapi]

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

python main.py

Visit:


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.

    Quick Start

  • User Guide


    Deep dives into routing, decorators, lifecycle hooks, and more.

    Guides

  • API Reference


    Complete API documentation for all REROUTE features.

    API Reference

  • Examples


    Real-world patterns: CRUD, authentication, caching, and more.

    Examples


Community & Support


License

REROUTE is released under the Apache License 2.0.