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.1.tar.gz (64.8 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.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (578.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

blazely-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (579.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

blazely-0.1.1-cp39-abi3-win_amd64.whl (548.3 kB view details)

Uploaded CPython 3.9+Windows x86-64

blazely-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (606.6 kB view details)

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

blazely-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (580.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

blazely-0.1.1-cp39-abi3-macosx_11_0_arm64.whl (546.1 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: blazely-0.1.1.tar.gz
  • Upload date:
  • Size: 64.8 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.1.tar.gz
Algorithm Hash digest
SHA256 f37b5c10b7363d1369a79d63129ce8ed66e50a07b8256c926d720505de216757
MD5 83548c6ab4322c5df5c6997e78af251e
BLAKE2b-256 71e489dea470fade60ff7fe529abfcf155fb924e503f5b3cef0a7cd2ef4e5d5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1.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.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 27a24d46d08fed22119be538b26180f2d65fbfdae86d4add07b7d723e68bbbcc
MD5 628da84b9bdb189e89bdeb6626e87e33
BLAKE2b-256 160fe407540ddc540d42e86ca167c9454acd13230fdc5aae859f9dcd2e6629f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a87f804cf8accf19f8c5a8d0662e414d2465858c54f9b52fa775c3acf7e62663
MD5 6a697d462a43ad63d7bb90bde35e37b2
BLAKE2b-256 138efe05e848205955816360df27438a0e2bc4cc4778548755fa0fa6ad9cdfeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: blazely-0.1.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 548.3 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.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b92275cd083fea578f5e320bc050357eae61b397bef985174845513039d41e39
MD5 55db78db13080ca17dd48222672428ce
BLAKE2b-256 f66bcac1bdda5e6550fdf2ad000b79c6aa6b267db25fba28177093730e030af3

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blazely-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a1bfbf00de28bbd9c5da41046cf9f73783c83e7d773ccce26b0368e2872e0fa
MD5 f4631688ddb2497f19e874b80346cd30
BLAKE2b-256 2afc5d9c66e096342b8ba8834127806999f7df3da4fc76a3850f8202f226e9e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for blazely-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f31808c2e424bdb62c3258b97d95b1eac58c4c068d30fa9da86bf0bda8636ecc
MD5 3c3798a3e2db1ac807c7ca0665a36a78
BLAKE2b-256 e1f9d259891021fec996ad1a492a1ce2211a72d5337b900e457acbb8ce89e54d

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for blazely-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7aaf5474c1672785258ec0f9103462ffe15aae2ff181edcd29ef9edd372d11f
MD5 7094229fcc4351a2a9d7ac1638259c31
BLAKE2b-256 6593a70111d13b5c26a74bf2abba3fe55007c58d2bd6b79c915521aaefb0f210

See more details on using hashes here.

Provenance

The following attestation bundles were made for blazely-0.1.1-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