Skip to main content

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
  • Secure by Default: Built-in security best practices and sanitization
  • 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 (modern approach)
uv sync

# Or traditional approach
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:

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


Built with 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.1.tar.gz (129.7 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.1-py3-none-any.whl (127.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reroute-0.2.1.tar.gz
  • Upload date:
  • Size: 129.7 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.1.tar.gz
Algorithm Hash digest
SHA256 838fd9471e9e438099701499843c5f5010f8532be499fdccef00870de4ea8965
MD5 0e1907281a6a3cd3f14fe5dc8a1c1819
BLAKE2b-256 b10d0d77b3a0cb5b715d87ee9acfc4646cde5422464e2e3e1cd23257640e6acc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reroute-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 127.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97af1cd46ba657460f1ff72f2488037ad2e629eb9ab4823fd634f64f3e6500b6
MD5 3af418e64763c719924f091ceec9c1a7
BLAKE2b-256 8ea9652b48da314f25d09ea6bd9fc20236a71b09d3af58912c0204607118f84e

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