Metadata-Version: 2.4
Name: reroute
Version: 0.4.0
Summary: File-based routing for Python backend frameworks (FastAPI)
Home-page: https://github.com/cbsajan/reroute
Author: C B Sajan
Author-email: C B Sajan <cloud.ckhathri@gmail.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/cbsajan/reroute
Project-URL: Repository, https://github.com/cbsajan/reroute
Project-URL: Documentation, https://cbsajan.github.io/reroute-docs
Keywords: fastapi,routing,file-based,web-framework,async
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Framework :: FastAPI
Classifier: Framework :: AsyncIO
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0.0
Requires-Dist: InquirerPy>=0.3.0
Requires-Dist: cookiecutter>=2.1.0
Requires-Dist: packaging>=21.0
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
Requires-Dist: uvicorn[standard]>=0.20.0; extra == "fastapi"
Provides-Extra: flask
Requires-Dist: flask>=2.0.0; extra == "flask"
Provides-Extra: security
Requires-Dist: argon2-cffi>=23.0.0; extra == "security"
Requires-Dist: pyjwt>=2.8.0; extra == "security"
Requires-Dist: email-validator>=2.0.0; extra == "security"
Requires-Dist: bleach>=6.0.0; extra == "security"
Provides-Extra: openapi
Requires-Dist: pyyaml>=6.0; extra == "openapi"
Requires-Dist: jsonschema>=4.0; extra == "openapi"
Provides-Extra: websocket
Requires-Dist: websockets>=11.0; extra == "websocket"
Requires-Dist: python-socketio>=5.0; extra == "websocket"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: sqlalchemy>=2.0.0; extra == "dev"
Requires-Dist: bandit>=1.7.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

<div align="center">
  <img src="https://raw.githubusercontent.com/cbsajan/reroute/main/assets/logo-light.svg" alt="REROUTE Logo" width="200">
  <h1>REROUTE</h1>
  <p><em>File-based routing for Python backends</em></p>
  <p><strong>Inspired by Next.js, powered by FastAPI/Flask</strong></p>

  [![PyPI version](https://badge.fury.io/py/reroute.svg)](https://pypi.org/project/reroute/)
  [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/cbsajan/reroute/blob/main/LICENSE)

</div>

---

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

```bash
# 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

```bash
# 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

<div align="center">
  <video width="800" height="450" controls>
    <source src="assets/demo.mp4" type="video/mp4">
    Your browser does not support the video tag.
  </video>
  <p><em>Click to play demo video (643 KB)</em></p>
</div>

---

## Generate Routes with CLI

```bash
# 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](https://cbsajan.github.io/reroute)** - Full guides, API reference, and examples

### Build Documentation Locally

```bash
cd docs
pip install -r requirements.txt
mkdocs serve
```

Visit `http://127.0.0.1:8000` to view the documentation.

### Quick Links
- [Getting Started](https://cbsajan.github.io/reroute/latest/getting-started/quickstart/) - Installation and first route
- [CLI Commands](https://cbsajan.github.io/reroute/latest/cli/commands/) - Complete CLI reference
- [Decorators](https://cbsajan.github.io/reroute/latest/guides/decorators/) - Rate limiting, caching, validation
- [Security](https://cbsajan.github.io/reroute/latest/guides/security/) - Security headers and best practices
- [API Reference](https://cbsajan.github.io/reroute/latest/api/) - RouteBase, parameters, decorators, config
- [Examples](https://cbsajan.github.io/reroute/latest/examples/) - CRUD, authentication, rate limiting, caching

## 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:

```python
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 | Removed in v0.3.0 | - |
| Django | Coming Soon | - |

**Note:** As of v0.3.0, REROUTE focuses exclusively on FastAPI for better async support, automatic OpenAPI documentation, and active maintenance.

## License

Apache License 2.0

## Contributing

We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

## Support

- **Documentation**: [https://cbsajan.github.io/reroute](https://cbsajan.github.io/reroute)
- **Issues**: [GitHub Issues](https://github.com/cbsajan/reroute/issues)
- **PyPI**: [pypi.org/project/reroute](https://pypi.org/project/reroute)

---

<div align="center">
  Built by developers, for developers.
</div>
