Skip to main content

A blazingly fast Rust-based FastAPI alternative

Project description

Blazely

A high-performance web framework combining Rust's speed with Python's simplicity.

Performance: 2.7x faster than FastAPI in single-threaded scenarios, with ultra-low latency (0.5ms vs 1.4ms).

Features

  • ๐Ÿš€ Rust-Powered: Hyper HTTP server + Tokio async runtime
  • โšก Fast JSON: Native Rust serde_json serialization (3-5x faster than Python)
  • ๐Ÿ”“ Free-Threading Ready: PyO3 0.23 with gil_used = false
  • ๐ŸŽฏ Multi-Threading: True concurrent request handling
  • ๐Ÿ Python-Friendly: FastAPI-like decorator syntax
  • ๐Ÿ“ฆ Easy Install: Single pip install with pre-built wheels (planned)

Quick Start

Prerequisites

  • Python 3.13+ (or 3.8+, but 3.13 recommended)
  • Rust toolchain (install here)

Installation

# Clone the repository
git clone https://github.com/cakirtaha/blazely.git
cd blazely

# Install dependencies and build
pip install maturin
maturin develop --release

# Or use uv (recommended)
uv pip install maturin
uv run maturin develop --release

Hello World

from blazely import Blazely

app = Blazely()

@app.get("/")
def hello(request=None):
    return {"message": "Hello, Blazely!"}

if __name__ == "__main__":
    app.run()  # Server starts on http://127.0.0.1:8000

Architecture

Two-Layer Design

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Python Layer               โ”‚  FastAPI-like API
โ”‚   - Decorators (@app.get)    โ”‚  Easy to use
โ”‚   - Type hints & Pydantic    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚ PyO3 0.23 Bridge
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Rust Layer                 โ”‚  Performance
โ”‚   - Hyper HTTP/1.1 server    โ”‚  Low latency
โ”‚   - Tokio multi-threading    โ”‚  High throughput
โ”‚   - serde_json               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Request Flow

  1. HTTP Request โ†’ Hyper receives (Rust, no GIL)
  2. Route Matching โ†’ matchit finds handler (Rust, no GIL)
  3. Python Handler โ†’ Acquire GIL, call your function
  4. JSON Response โ†’ serde_json serializes (Rust)
  5. HTTP Response โ†’ Hyper sends, release GIL

Key Insight: GIL is held only during your Python handler execution (~1ms)

Performance

Benchmark Results

Test: 150 requests to GET / endpoint (simple JSON response)

Metric Blazely FastAPI Improvement
Single-threaded 1,935 req/s 714 req/s 2.71x faster
Multi-threaded (10) 2,890 req/s 2,665 req/s 1.08x faster
Latency (avg) 0.50ms 1.38ms 2.76x lower

Why So Fast?

  1. Rust serde_json - All JSON in compiled code (not Python)
  2. Hyper - Low-level HTTP server (minimal overhead)
  3. Minimal GIL - Python only during handler execution
  4. Multi-threading - Tokio handles concurrency efficiently

API Reference

Creating an Application

from blazely import Blazely

app = Blazely(title="My API", version="1.0.0")

Route Decorators

@app.get("/path")           # GET request
@app.post("/path")          # POST request
@app.put("/path")           # PUT request
@app.delete("/path")        # DELETE request
@app.patch("/path")         # PATCH request

Path Parameters

@app.get("/users/{user_id}")
def get_user(request=None, user_id: int = 0):
    # Extract from request if needed
    if request and "path_params" in request:
        user_id = int(request["path_params"]["user_id"])
    return {"user_id": user_id}

Query Parameters

@app.get("/search")
def search(request=None, q: str = "", limit: int = 10):
    # Extract from request if needed
    if request and "query_params" in request:
        q = request["query_params"].get("q", q)
        limit = int(request["query_params"].get("limit", limit))
    return {"query": q, "limit": limit}

Request Body (Pydantic)

from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float

@app.post("/items")
def create_item(request=None, item: Item = None):
    # Request body is parsed and validated
    if request and "body" in request:
        item = Item(**request["body"])
    return {"item": item.model_dump()}

Const Routes (Ultra-Fast)

@app.get("/health", const=True)
def health(request=None):
    return {"status": "ok"}

Response is cached in Rust and served without calling Python. Expected: 100k+ req/s.

Project Structure

blazely/
โ”œโ”€โ”€ python/blazely/      # Python API layer
โ”‚   โ”œโ”€โ”€ app.py          # Main Blazely class with decorators
โ”‚   โ”œโ”€โ”€ response.py     # Response types
โ”‚   โ”œโ”€โ”€ params.py       # Parameter extractors
โ”‚   โ””โ”€โ”€ _internal.py    # Imports Rust extension module
โ”‚
โ”œโ”€โ”€ src/                # Rust performance engine
โ”‚   โ”œโ”€โ”€ lib.rs         # PyO3 module entry point
โ”‚   โ”œโ”€โ”€ server.rs      # Hyper HTTP server + Tokio runtime
โ”‚   โ”œโ”€โ”€ router.rs      # Route matching with matchit
โ”‚   โ”œโ”€โ”€ handler.rs     # Python handler bridge (GIL management)
โ”‚   โ”œโ”€โ”€ request.rs     # HTTP request โ†’ Python dict
โ”‚   โ”œโ”€โ”€ response.rs    # Python dict โ†’ HTTP response (serde_json)
โ”‚   โ””โ”€โ”€ runtime.rs     # Tokio runtime creation
โ”‚
โ”œโ”€โ”€ examples/
โ”‚   โ””โ”€โ”€ hello_world.py  # Simple example application
โ”‚
โ”œโ”€โ”€ Cargo.toml          # Rust dependencies
โ””โ”€โ”€ pyproject.toml      # Python package config (Maturin)

Technology Stack

Rust (Performance Layer)

  • PyO3 0.23 - Python/Rust bindings with free-threading support
  • Hyper 1.0 - Low-level HTTP server
  • Tokio - Multi-threaded async runtime
  • serde_json - Fast JSON serialization
  • matchit - Fast path routing
  • pythonize - Python โ†” serde conversion

Python (API Layer)

  • Pydantic - Data validation
  • typing-extensions - Type hints

Development

Building

# Development build (faster compilation)
maturin develop

# Release build (optimized, slower compilation)
maturin develop --release

# With uv (recommended)
uv run maturin develop --release

Running Tests

# Python tests
pytest tests/python/

# Rust tests
cargo test

Running Examples

python examples/hello_world.py
# Visit http://127.0.0.1:8000

Current Status

โœ… Working

  • HTTP server (Hyper + Tokio)
  • Route decorators (@app.get, @app.post, etc.)
  • Path and query parameters
  • Request body with Pydantic
  • JSON responses (serde_json)
  • Const route caching
  • Multi-threading support
  • Free-threading compatible (Python 3.13t ready)

โš ๏ธ Limitations

  1. Handlers must accept request parameter - Even if unused: def handler(request=None)
  2. Async handlers not fully supported - Use sync handlers for now
  3. Parameter extraction manual - Need to extract from request dict
  4. No middleware - Coming in future versions
  5. No OpenAPI generation - Coming in future versions

๐ŸŽฏ Roadmap

  • Automatic parameter injection (remove manual extraction)
  • Full async handler support
  • Middleware system
  • OpenAPI schema generation
  • Request/Response classes (instead of dicts)
  • WebSocket support
  • Static file serving

Troubleshooting

Build fails

# Update Rust
rustup update

# Clean and rebuild
cargo clean
maturin develop --release

Import error: blazely._internal

# Rebuild the extension
maturin develop

Server not responding

Make sure handlers accept the request parameter:

# โŒ Wrong
@app.get("/")
def handler():
    return {}

# โœ… Correct
@app.get("/")
def handler(request=None):
    return {}

Contributing

Contributions welcome! Key areas:

  1. Performance - Optimize hot paths
  2. Features - Middleware, OpenAPI, async support
  3. Testing - More integration tests
  4. Documentation - Examples and guides

License

MIT License - see LICENSE file

Acknowledgments

  • Built with PyO3 - Amazing Rust/Python interop
  • Inspired by FastAPI - Great API design
  • Powered by Hyper - Rust's HTTP foundation

Blazely = Rust's speed + Python's simplicity ๐Ÿš€

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

blazely-0.1.0.tar.gz (64.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

blazely-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (574.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

blazely-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (574.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

blazely-0.1.0-cp39-abi3-win_amd64.whl (540.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

blazely-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (602.1 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

blazely-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (575.4 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

blazely-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (542.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file blazely-0.1.0.tar.gz.

File metadata

  • Download URL: blazely-0.1.0.tar.gz
  • Upload date:
  • Size: 64.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for blazely-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7de0c3c71a0fbf5be6a169175cd83814759ca781a334feeaf5b2edff59d3e504
MD5 c88a24d012d10eff0312ebb4477bef48
BLAKE2b-256 6333928e3d06c434a4bd4ac089d737fb9e4d99c6590f379378352009b1681921

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0.tar.gz:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 28a22f4631fe1ab843502ac3d43f72b724cc882577cff7bf72aa382a28eb446b
MD5 fde18f005567e362a15c6d35ee623281
BLAKE2b-256 b61410b2d8936bd27191b2042cc7452f9d94089765145ad2641b6ac4ee4deb9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f13a158f51cb173fd2e1ccdf0240b1a680de0c6f536f43af6bbb7b317904abb4
MD5 c4129df82011acb8513376878f2fc708
BLAKE2b-256 b3ae37cee203a806177f88985760432254565c89ea1d6837c4ea5bd15a286298

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: blazely-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 540.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for blazely-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4e111cc6458f94f25efff1b479142b9dbd13a3279b033f1ced995d1022aa4a09
MD5 0cf0e8582abadb02732d00249d2e3525
BLAKE2b-256 c811da551da44b1c2328c4c12bed1012b2280aed922bb8a64b07c594f2c7df5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-cp39-abi3-win_amd64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blazely-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b33498626a059e2a88a4ee00a607aedf2c2970a1438bcef5d4a8d1b85f2ffd43
MD5 271d8d6e4c551fd9a1cba7ff49677284
BLAKE2b-256 df23e3adb8a0b83488bba4de32d638f3c1677001b4f683a699e334bed8aa4285

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 779e6ce7a34337005c7547e001baa98b73ffb50193a067374f4814c44fbf7834
MD5 2c51379959d57dd898405c26c43f621a
BLAKE2b-256 19880129293d055d3d9d9334c9b9ee3a8058743327140ba5704fbdcb93589ee9

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blazely-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for blazely-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ff458cf2fd8d160830a8217b4fba80a4845614a57e00db38e80718803f3d3ec
MD5 8d076902ad9337e181db734a74bb64a1
BLAKE2b-256 52736e8208f457be99be64c4dfc3eaf376c54b690612afdaaa16c4a87271e994

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: ci.yml on cakirtaha/blazely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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