Rupy

High-Performance Web Framework for Python

Powered by Rust and Axum, Rupy delivers blazing-fast performance with the simplicity and elegance of Python. Build modern web applications with ease.

Why Choose Rupy?

Combining the performance of Rust with the simplicity of Python

Lightning Fast

Built on Rust and Axum, Rupy delivers exceptional performance that rivals the fastest web frameworks available.

Simple API

Intuitive Python API that feels natural. Write clean, readable code with decorators and type hints.

All HTTP Methods

Full support for GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS with convenient decorators.

Dynamic Routes

Define dynamic path parameters with ease using angle brackets. Perfect for RESTful APIs.

Middleware Support

Powerful middleware system for authentication, CORS, logging, rate limiting, and more.

OpenTelemetry

Built-in observability with OpenTelemetry for metrics, tracing, and structured logging.

Installation

Get started with Rupy in minutes

Add as Dependency

Add Rupy to your pyproject.toml:

[project]
dependencies = [
    "rupy @ git+https://github.com/manoelhc/rupy.git"
]

Then install:

pip install .

Build from Source

For development or customization:

1. Install maturin:

pip install maturin

2. Build and install:

maturin develop

Or for production:

maturin build --release
pip install target/wheels/rupy-*.whl

Quick Start

Build your first Rupy application in seconds

app.py

from rupy import Rupy, Request, Response

app = Rupy()

@app.route("/", methods=["GET"])
def index(request: Request) -> Response:
    return Response("Hello, World!")

@app.route("/user/<username>", methods=["GET"])
def get_user(request: Request, username: str) -> Response:
    return Response(f"User: {username}")

@app.route("/echo", methods=["POST"])
def echo(request: Request) -> Response:
    return Response(f"Echo: {request.body}")

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8000)

Run your application:

python app.py

Test with curl:

curl http://127.0.0.1:8000/
curl http://127.0.0.1:8000/user/alice
curl -X POST -d '{"name": "test"}' http://127.0.0.1:8000/echo

Documentation

Everything you need to build powerful web applications

HTTP Methods

Rupy provides convenient decorators for all HTTP methods:

@app.get("/items")
def list_items(request: Request) -> Response:
    return Response("List of items")

@app.post("/items")
def create_item(request: Request) -> Response:
    return Response(f"Created: {request.body}")

@app.put("/items/<item_id>")
def update_item(request: Request, item_id: str) -> Response:
    return Response(f"Updated item {item_id}")

@app.patch("/items/<item_id>")
def patch_item(request: Request, item_id: str) -> Response:
    return Response(f"Patched item {item_id}")

@app.delete("/items/<item_id>")
def delete_item(request: Request, item_id: str) -> Response:
    return Response(f"Deleted item {item_id}")

Dynamic Routes

Define dynamic path parameters using angle brackets:

@app.route("/user/<username>", methods=["GET"])
def user_profile(request: Request, username: str) -> Response:
    return Response(f"User Profile: {username}")

@app.route("/blog/<author>/<post_id>", methods=["GET"])
def blog_post(request: Request, author: str, post_id: str) -> Response:
    return Response(f"Blog post {post_id} by {author}")

@app.route("/products/<category>/<product_id>", methods=["GET"])
def product_details(request: Request, category: str, product_id: str) -> Response:
    return Response(f"Product {product_id} in category {category}")

Middleware

Basic Middleware

Middlewares execute before route handlers and can inspect, modify, or block requests:

@app.middleware
def logging_middleware(request: Request):
    print(f"Processing {request.method} {request.path}")
    return request  # Continue to next middleware/handler

@app.middleware
def auth_middleware(request: Request):
    if request.path.startswith("/admin"):
        return Response("Unauthorized", status=401)
    return request

CORS Middleware

Handle cross-origin requests with CORS middleware:

@app.middleware
def cors_middleware(request: Request):
    # Handle preflight OPTIONS requests
    if request.method == "OPTIONS":
        return Response("", status=204)
    return request

JWT Authentication

Protect routes with JWT authentication:

@app.middleware
def jwt_auth_middleware(request: Request):
    # Skip auth for public routes
    if request.path in ["/", "/login", "/public"]:
        return request
    
    # Check for protected routes
    if request.path.startswith("/protected"):
        # Validate JWT token from headers
        return Response(
            '{"error": "Unauthorized"}',
            status=401
        )
    return request

OpenTelemetry Support

Enable Telemetry

Programmatically enable OpenTelemetry:

app = Rupy()

# Enable telemetry with optional configuration
app.enable_telemetry(
    endpoint="http://localhost:4317",  # OTLP gRPC endpoint
    service_name="my-service"           # Service name for traces
)

# Check telemetry status
is_enabled = app.is_telemetry_enabled()

# Disable telemetry
app.disable_telemetry()

Environment Variables

Configure telemetry using environment variables:

export OTEL_ENABLED=true
export OTEL_SERVICE_NAME=my-service
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
export RUST_LOG=info

python app.py

Collected Metrics

Automatic Metrics:
  • http.server.requests - Total HTTP requests counter
  • http.server.duration - Request duration histogram
Tracing Attributes:
  • http.method - HTTP method (GET, POST, etc.)
  • http.route - Matched route pattern
  • http.scheme - Protocol scheme (http/https)

Examples

Learn from real-world examples

1

Basic App

Simple GET and POST routes demonstrating the basics of Rupy.

examples/basic_app.py
2

REST API

Complete RESTful API with all HTTP methods (GET, POST, PUT, PATCH, DELETE).

examples/rest_api.py
3

Dynamic Routes

Demonstrates dynamic path parameters with multiple examples.

examples/dynamic_routes.py
4

All HTTP Methods

Comprehensive example showing all supported HTTP methods.

examples/all_methods.py
5

Telemetry

OpenTelemetry integration for metrics, tracing, and logging.

examples/telemetry_example.py
6

CORS Middleware

Cross-Origin Resource Sharing (CORS) middleware example.

examples/cors_middleware.py
7

JWT Authentication

JWT-based authentication middleware with protected routes.

examples/jwt_middleware.py
8

Method Decorators

Using convenient method-specific decorators (@app.get, @app.post, etc.).

examples/method_decorators.py
9

Combined Middlewares

Multiple middlewares working together: logging, rate limiting, and auth.

examples/combined_middlewares.py

Built for Performance

Powered by Rust and Axum for unmatched speed

🚀

Lightning Fast

Rust-powered backend delivers exceptional performance

âš¡

Low Latency

Handle thousands of requests with minimal overhead

💪

Production Ready

Battle-tested Axum framework under the hood

Benchmark Example

wrk -t12 -c400 -d30s http://127.0.0.1:8000/

Designed to outperform traditional Python frameworks like FastAPI and Flask