Quick Setup

🚀 Installation & Setup

RustAPI is published as a pre-compiled wheel package on PyPI (`pyrustapi`) with zero Rust toolchain required for end users.

Installing via Pip

pip install pyrustapi pydantic

Building from Source (Optional / Development)

git clone https://github.com/rajboopathiking/rustapi.git
cd rustapi
pip install maturin
maturin develop --release
Your First API

💻 Writing Your First Application

Create a file named main.py:

import rustapi
from pydantic import BaseModel

# Initialize the RustAPI Engine (Tokio runtime + Hyper HTTP server)
app = rustapi.Engine()

class Item(BaseModel):
    name: str
    price: float
    is_offer: bool = None

@app.get("/")
def read_root():
    return {"Hello": "World from RustAPI"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

@app.post("/items")
def create_item(item: Item):
    return {"item_name": item.name, "item_price": item.price}

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

Run the application:

python main.py

Open http://127.0.0.1:8000/docs (Swagger UI) or http://127.0.0.1:8000/redoc (ReDoc) in your browser!

Ergonomics

📥 Path, Query, Header & Body Extraction

Automatic Path & Query Coercion

RustAPI parses URL path and query parameters natively in Rust, yielding structured 422 Unprocessable Entity responses if type constraints fail.

@app.get("/search")
def search(query: str, page: int = 1, limit: int = 20):
    return {"query": query, "page": page, "limit": limit}
Developer Experience

🔄 Hot Auto-Reload Mode

Enable auto-reload during development to restart the server on file changes:

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