Skip to main content

High-performance Python web framework powered by Rust โ€” 2x faster than Robyn

Project description

Pyre ๐Ÿ”ฅ

High-performance Python web framework powered by Rust.

Built on Per-Interpreter GIL (PEP 684) and a Rust async core, Pyre runs Python handlers across all CPU cores in a single process.

  • 429k req/s on Linux (8C/16T), 2.7x faster than Robyn at equal scale (16 workers each), 1/3 the memory.
  • 300s sustained 400k QPS, 120 million requests, zero errors, zero memory leaks.

What's new in v1.4.0

  • M:N scheduling โ€” io_workers (Tokio I/O threads) and workers (Python sub-interpreters) configured independently
  • SO_REUSEPORT multi-accept โ€” N independent accept loops with kernel-level load balancing on Linux
  • LTO + TCP_QUICKACK + mimalloc โ€” compile-time whole-program optimization, reduced first-byte latency, high-concurrency allocator
  • Headers OnceLock + serde_json/pythonize โ€” lazy header conversion, Rust-side JSON serialization
  • Full benchmark: benchmarks/benchmark-14-linux.en.md

What others can't do, Pyre has built-in

  • SharedState โ€” cross-worker memory sharing without Redis (nanosecond latency)
  • AI-native โ€” MCP server, MsgPack RPC, SSE streaming
  • Observable โ€” GIL watchdog, backpressure (503), request timeout (504)
from pyreframework import Pyre

app = Pyre()

@app.get("/")
def index(req):
    return {"hello": "world"}

@app.get("/io")
async def io_heavy(req):
    import asyncio
    await asyncio.sleep(0.1)
    return "done"

app.run()

Why Pyre?

The problem

AI applications in Python need high throughput and low memory. An AI agent backend handles thousands of concurrent LLM calls, RAG queries, and tool invocations โ€” all I/O-heavy, all in Python. A quantitative trading gateway processes hundreds of real-time data feeds simultaneously. These workloads demand the performance of C++ with the ecosystem of Python.

But Python has the GIL (Global Interpreter Lock). One lock, one core, no parallelism. Every framework before Pyre works around this with compromises.

What others do (and why it's not enough)

FastAPI chose async on a single core. Elegant for I/O, but one CPU-heavy request (JSON parsing, Pydantic validation, numpy computation) blocks the entire event loop. Scale via Gunicorn means duplicating the full Python runtime per process. At 15k req/s, you hit the ceiling.

Robyn replaced the Python event loop with Rust (Tokio). Better I/O, but Python handlers still run on one GIL. Scaling means 22+ OS processes (--fast), eating 447 MB. The Rust layer is fast; the Python layer is the bottleneck.

Multi-threading doesn't help. Python threads share one GIL โ€” they take turns, not run in parallel. Adding threads adds context-switch overhead without adding throughput. threading in Python is concurrency theater, not parallelism.

Free-threaded Python (no-GIL, PEP 703) removes the lock but makes every Python object operation slower (atomic reference counting). The ecosystem isn't ready โ€” most C extensions assume the GIL exists. It trades one problem for another.

What Pyre does differently

Pyre multiplies the GIL. Using Per-Interpreter GIL (PEP 684), each worker gets its own independent Python interpreter with its own GIL inside a single process. True multi-core parallelism, zero memory duplication, zero IPC overhead.

FastAPI:  1 process ร— 1 GIL ร— async tricks     = fast I/O, slow CPU, 15k QPS
Robyn:    16 processes ร— 16 GILs ร— 16ร— memory  = brute force, 156k QPS, 583 MB
Pyre:     1 process ร— 16 GILs ร— shared memory   = elegant, 429k QPS, 189 MB

This matters for AI:

  • LLM gateway โ€” thousands of concurrent await calls, each taking 2-5 seconds. Pyre's async pool handles 133k concurrent I/O operations.
  • Agent orchestration โ€” multiple agents computing simultaneously. Each sub-interpreter runs at full CPU speed without blocking others.
  • Memory efficiency โ€” deploy 3x more instances on the same hardware. Pyre 189 MB for 16 workers vs Robyn 583 MB. On a 512 MB container, Pyre runs 16 parallel workers; Robyn fits 12 at best.
  • State sharing โ€” cross-worker app.state with nanosecond latency. No Redis, no serialization, no network hop. Session management, caching, and coordination built into the framework.

Performance

Benchmarked on Linux (AMD Ryzen 7 7840HS, 8C/16T), Python 3.12, wrk -t4 -c100 -d10s.

Full report: benchmarks/benchmark-14-linux.md

Throughput (requests/sec)

Route Pyre P50 P99
GET / (plain text) 429,000 185ฮผs 579ฮผs
GET /json 405,000 196ฮผs 599ฮผs
GET /user/42 (path param) 395,000 201ฮผs 641ฮผs
POST /echo (JSON parse) 372,000 214ฮผs 785ฮผs
GET /compute (CPU-bound) 379,000 211ฮผs 772ฮผs

Pyre vs Robyn (fair comparison)

Both frameworks given 16 workers on the same hardware. Robyn: --processes 16 --workers 2.

Route Pyre (1 proc, 16 sub-interp) Robyn (16 proc ร— 2 workers) Ratio
GET / 429k req/s 156k req/s 2.7x
GET /json 405k req/s 155k req/s 2.6x
GET /user/42 395k req/s 144k req/s 2.7x
POST /echo 372k req/s 144k req/s 2.6x
GET /compute 379k req/s 145k req/s 2.6x

Resource efficiency

Resource Pyre Robyn (16 proc)
Memory 189 MB 583 MB
Processes 1 16
QPS per MB 2,268 req/s/MB 268 req/s/MB
Cross-worker state Built-in (DashMap, nanosecond) Needs Redis

Pyre achieves 2.7x the throughput with 1/3 the memory. Per-MB efficiency is 8.5x better.

Stability (5-minute sustained load)

Sustained 300s stress test, wrk -t4 -c100.

Metric Linux (v1.4.0) macOS (v1.2.0)
Sustained QPS 400,683 req/s 214,641 req/s
Total requests 120,209,758 (120M) 64,410,189 (64M)
Non-2xx responses 0 0
Socket errors 0 0
Memory growth 169 โ†’ 196 MB (+27 MB) 1712 โ†’ 752 KB
Max latency 9.02ms 39.98ms

120 million requests, zero errors, zero memory leaks.

Stress test (c=1024)

Metric Result
QPS 356,328 req/s
P50 / P99 1.40ms / 3.15ms
Errors 0

Graceful degradation under extreme concurrency โ€” still 356k QPS with zero errors.

Pyre vs Robyn: feature comparison

Capability Pyre Robyn
Architecture 1 process, N sub-interpreters N OS processes
SharedState (cross-worker) Built-in (DashMap, nanosecond) Not supported (needs Redis)
MCP Server (AI tool protocol) Built-in Supported (experimental)
MsgPack RPC Built-in + magic client Not supported
SSE Streaming Built-in (PyreStream) Supported
GIL Watchdog Built-in (contention + hold time) Not supported
Backpressure (503 overload) Built-in (bounded channels) Not supported
Request Timeout (504) Built-in (30s zombie reaper) Not supported
Hybrid Dispatch (gil=True) Auto-routes to main interpreter Not supported
TestClient Built-in Not built-in
WebSocket Supported Supported
CORS Supported Supported
Static Files Supported (async, no GIL) Supported
Middleware before/after hooks Supported
Hot Reload Supported Supported

Who is Pyre for?

AI Agent servers โ€” Build MCP-compatible tool servers, LLM gateways, and multi-agent orchestration backends. Handle thousands of concurrent LLM streaming responses with SSE. SharedState coordinates agents without Redis.

Quantitative trading โ€” Process real-time market data feeds with sub-millisecond P50 latency. Sub-interpreter parallelism runs strategy computations across all cores without GIL contention. WebSocket support for live order book streaming.

High-throughput microservices โ€” Internal service mesh nodes that need maximum req/s with minimum memory. MsgPack RPC for binary-efficient inter-service communication. Backpressure (503) protects downstream systems under load spikes.

Edge/IoT gateways โ€” Run on memory-constrained devices (512 MB containers, Raspberry Pi). 67 MB for 10 parallel workers vs 447 MB for the alternatives.

How Pyre works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Pyre Architecture                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Python handlers (def / async def / gil=True)           โ”‚
โ”‚      โ†“                                                   โ”‚
โ”‚  Rust core (Tokio + Hyper)                              โ”‚
โ”‚  โ”œโ”€โ”€ Sync worker pool โ”€โ”€โ†’ N sub-interpreters (OWN_GIL)  โ”‚
โ”‚  โ”œโ”€โ”€ Async worker pool โ”€โ”€โ†’ N asyncio event loops        โ”‚
โ”‚  โ”œโ”€โ”€ Hybrid dispatch โ”€โ”€โ†’ main interpreter (numpy/C ext) โ”‚
โ”‚  โ”œโ”€โ”€ SharedState โ”€โ”€โ†’ DashMap (nanosecond, cross-worker) โ”‚
โ”‚  โ””โ”€โ”€ Backpressure โ”€โ”€โ†’ bounded channels (503 on overload)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Feature Comparison

Routing & Request/Response

Feature Pyre FastAPI Robyn
Decorator routing โœ… โœ… โœ…
Path params /hello/{name} โœ… โœ… โœ…
Query params โœ… โœ… โœ…
JSON parsing โœ… โœ… โœ…
Pydantic validation โœ… model= โœ… native โœ…
File upload (multipart) โœ… โœ… โœ…
Cookie read/write โœ… โœ… โœ…
Redirect โœ… โœ… โœ…
Custom status/headers โœ… โœ… โœ…
Static files โœ… โœ… โœ…

Protocols

Feature Pyre FastAPI Robyn
HTTP/1.1 โœ… โœ… โœ…
HTTP/2 โœ… โœ… (Hypercorn) โœ…
WebSocket (text+binary) โœ… โœ… โœ…
SSE streaming โœ… โœ… โœ…

Middleware & Security

Feature Pyre FastAPI Robyn
before/after hooks โœ… โœ… middleware โœ…
CORS โœ… built-in โœ… โœ…
Body size limit โœ… 10MB โœ… โœ…
Backpressure (503) โœ… โŒ โŒ
Path traversal protection โœ… โœ… โŒ
Worker panic protection โœ… catch_unwind N/A N/A

AI & Microservices

Feature Pyre FastAPI Robyn
MCP Server (AI tools) โœ… native โŒ (third-party) โœ…
MsgPack RPC โœ… โŒ โŒ
Content negotiation โœ… JSON/MsgPack JSON only JSON only
Magic RPC Client โœ… โŒ โŒ
SharedState (no Redis) โœ… nanosecond โŒ needs Redis โŒ needs Redis

Concurrency (Pyre unique)

Feature Pyre FastAPI Robyn
Sub-interpreter parallelism โœ… Per-GIL โŒ โŒ
Hybrid GIL dispatch โœ… โŒ โŒ
Auto sync/async dual pool โœ… zero-loss โŒ โŒ
Multi-process โ€” (not needed) โœ… Gunicorn โœ… --fast

Observability (Pyre unique)

Feature Pyre FastAPI Robyn
GIL Watchdog โœ… โŒ โŒ
Memory RSS monitoring โœ… โŒ โŒ
Request counters โœ… โŒ โŒ
Structured logging โœ… โœ… โœ…

Developer Experience

Feature Pyre FastAPI Robyn Notes
Type stubs (.pyi) โœ… โœ… native โœ…
TestClient โœ… โœ… โŒ
Env var config โœ… โœ… โœ…
Hot reload โœ… reload=True โœ… --reload โœ…
OpenAPI docs โ€” โœ… โœ… Pyre uses MCP for AI discovery; type hints serve as docs
Dependency injection โ€” โœ… Depends() โœ… Pyre uses before_request hooks for the same purpose

C Extension Compatibility

Python C extensions (PyO3/Rust, C/C++) use global state that isn't compatible with sub-interpreters (PEP 684). This is a CPython ecosystem limitation, not a Pyre limitation.

Library Sub-interp gil=True Why
pydantic โŒ โœ… pydantic-core is PyO3/Rust, global static state
numpy โŒ โœ… C extension hardcodes "load once per process"
pandas โŒ โœ… Depends on numpy
scipy โŒ โœ… Depends on numpy
orjson โŒ โœ… PyO3/Rust module
sqlalchemy โŒ โœ… C extensions (greenlet, cython)
pillow โŒ โœ… C extension with global state
httpx โœ… โœ… Pure Python
requests โœ… โœ… Pure Python
json, hashlib, math โœ… โœ… stdlib, multi-interp safe
asyncio, threading โœ… โœ… stdlib, per-interpreter loops
dataclasses, typing โœ… โœ… Pure Python
re, datetime, os โœ… โœ… stdlib

Rule of thumb: if pip show <package> shows a .so/.pyd file, it likely needs gil=True. Pure Python packages always work in sub-interpreters.

The fix is simple: add gil=True to routes that need C extensions.

# Fast route โ€” sub-interpreter, 429k req/s, no C extensions needed
@app.get("/fast")
def fast(req):
    return {"hello": "world"}

# Heavy route โ€” GIL main interpreter, full C extension support
@app.post("/analyze", model=AnalysisRequest, gil=True)
def analyze(req, data):
    import numpy as np
    import pandas as pd
    return {"mean": float(np.mean(data.values))}

Pyre auto-detects which routes need GIL and dispatches accordingly. Fast routes stay at 429k req/s; GIL routes get full ecosystem access. Both run concurrently in the same server.

When will this be fixed? When PyO3 and numpy add PEP 684 multi-phase init support. Tracking: PyO3#3451, numpy#24003. When they do, these libraries will run at full speed in sub-interpreters โ€” no gil=True needed.

Why no OpenAPI? Pyre targets high-performance APIs and AI agents, not browser-based API explorers. For AI tool discovery, MCP is a more modern protocol. For human developers, Pydantic models + type stubs provide the same contract guarantees.

Why no dependency injection? before_request hooks solve the same problem (auth, DB connections, shared logic) with less magic and better debuggability. DI adds framework coupling without performance benefit.

Install

# From source (requires Rust toolchain + Python 3.12+)
git clone https://github.com/moomoo-tech/pyre.git
cd pyre
python -m venv .venv && source .venv/bin/activate
pip install maturin
maturin develop --release

Demos

Three production-grade example applications. Each demonstrates a different real-world use case with multiple Pyre features working together.

# Install dependencies first
pip install pydantic numpy msgpack httpx

# AI Agent Server โ€” MCP tools, SSE streaming, session memory
python examples/ai_agent_server.py

# Trading Data API โ€” numpy analytics, WebSocket, Pydantic, RPC
python examples/trading_api.py

# Full-stack REST API โ€” CRUD, cookie auth, file upload
python examples/fullstack_api.py

AI Agent Server (examples/ai_agent_server.py)

Build MCP-compatible AI tool servers with streaming token output.

python examples/ai_agent_server.py

# Chat (simulated LLM)
curl -X POST http://127.0.0.1:8000/chat \
  -H 'Content-Type: application/json' \
  -d '{"prompt": "What is Python?", "session_id": "user1"}'

# SSE streaming (token-by-token, like ChatGPT)
curl -N http://127.0.0.1:8000/stream?prompt=hello

# MCP tool discovery (for Claude Desktop)
curl -X POST http://127.0.0.1:8000/mcp \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

# Session memory
curl http://127.0.0.1:8000/memory/user1

Features used: MCP Server, SSE (PyreStream), async handlers, SharedState, Pydantic, CORS

Trading Data API (examples/trading_api.py)

Real-time market data with numpy analytics and WebSocket streaming.

python examples/trading_api.py

# Market quote
curl http://127.0.0.1:8000/market/AAPL

# Submit order (Pydantic validated)
curl -X POST http://127.0.0.1:8000/order \
  -H 'Content-Type: application/json' \
  -d '{"ticker": "AAPL", "side": "buy", "quantity": 100, "price": 150.5}'

# Portfolio analytics (numpy)
curl http://127.0.0.1:8000/analytics/portfolio

# RPC call from another service
python -c "
from pyreframework import PyreRPCClient
with PyreRPCClient('http://127.0.0.1:8000') as c:
    print(c.get_signals(tickers=['AAPL', 'TSLA']))
"

Features used: numpy (gil=True), Pydantic, WebSocket, SharedState, MsgPack RPC, CORS

Full-stack REST API (examples/fullstack_api.py)

Complete CRUD application with authentication and file uploads.

python examples/fullstack_api.py

# Register + login
curl -X POST http://127.0.0.1:8000/auth/register \
  -H 'Content-Type: application/json' \
  -d '{"username": "alice", "email": "alice@example.com", "password": "secret123"}'

curl -c cookies.txt -X POST http://127.0.0.1:8000/auth/login \
  -H 'Content-Type: application/json' \
  -d '{"username": "alice", "password": "secret123"}'

# Create item (authenticated)
curl -b cookies.txt -X POST http://127.0.0.1:8000/items \
  -H 'Content-Type: application/json' \
  -d '{"name": "Widget", "price": 9.99, "tags": ["new"]}'

# List items (with pagination)
curl http://127.0.0.1:8000/items?page=1&per_page=10

Features used: Pydantic, Cookie auth, File upload, Redirect, SharedState as DB, CORS, structured logging

Quick Start

Basic API

from pyreframework import Pyre, PyreResponse

app = Pyre()

@app.get("/")
def index(req):
    return {"message": "Hello from Pyre!"}

@app.get("/user/{name}")
def greet(req):
    return {"name": req.params["name"]}

@app.get("/search")
def search(req):
    return {"q": req.query_params.get("q", "")}

@app.post("/data")
def receive(req):
    return req.json()

app.run()  # http://127.0.0.1:8000

Async Handlers

def and async def coexist at full speed โ€” auto-detected, auto-routed.

@app.get("/fast")
def fast(req):              # โ†’ sync pool (429k req/s)
    return "instant"

@app.get("/io")
async def io_heavy(req):    # โ†’ async pool (133k req/s)
    result = await fetch_from_database()
    return {"data": result}

Pydantic Validation

from pydantic import BaseModel, Field

class Order(BaseModel):
    ticker: str = Field(max_length=5)
    amount: int = Field(gt=0)
    price: float

@app.post("/order", model=Order)
def place_order(req, order: Order):
    return {"total": order.amount * order.price}
# Invalid โ†’ 422 with validation errors

CORS

app.enable_cors()  # Allow all origins
app.enable_cors(allow_origins=["https://example.com"], allow_credentials=True)

Cookies

from pyreframework.cookies import get_cookie, set_cookie, delete_cookie

@app.get("/login")
def login(req):
    return set_cookie(PyreResponse(body="ok"), "session", "abc", httponly=True)

@app.get("/me")
def me(req):
    return {"session": get_cookie(req, "session")}

File Upload

from pyreframework.uploads import parse_multipart

@app.post("/upload")
def upload(req):
    f = parse_multipart(req)["file"]
    return {"filename": f.filename, "size": f.size}

Redirect

from pyreframework import redirect

@app.get("/old")
def old(req):
    return redirect("/new")

WebSocket

@app.websocket("/ws")
def echo(ws):
    while True:
        msg = ws.recv()
        if msg is None: break
        ws.send(f"echo: {msg}")

SSE Streaming

from pyreframework import PyreStream
import threading

@app.get("/stream", gil=True)
def stream(req):
    s = PyreStream()
    def gen():
        for token in ["Hello", " ", "World"]:
            s.send_event(token)
        s.close()
    threading.Thread(target=gen).start()
    return s

MCP Server (AI Agent)

@app.mcp.tool(description="Add two numbers")
def add(a: int, b: int) -> int:
    return a + b
# Claude Desktop โ†’ http://localhost:8000/mcp

RPC (MsgPack)

@app.rpc("/rpc/compute")
def compute(data):
    return {"result": data["a"] + data["b"]}

# Client:
from pyreframework import PyreRPCClient
with PyreRPCClient("http://server:8000") as c:
    c.compute(a=3, b=5)  # โ†’ {"result": 8}

Shared State

app.state["key"] = "value"     # Write (any worker)
val = app.state["key"]         # Read (nanosecond, no Redis)

numpy / C Extensions

@app.get("/compute", gil=True)
def compute(req):
    import numpy as np
    return {"mean": float(np.mean(np.random.randn(10000)))}

Configuration

PYRE_HOST=0.0.0.0 PYRE_PORT=9000 PYRE_WORKERS=16 PYRE_LOG=1 python app.py

Monitoring

PYRE_METRICS=1 python app.py   # Enable GIL watchdog

Testing

from pyreframework.testing import TestClient

client = TestClient(app)
resp = client.get("/")
assert resp.status_code == 200
assert resp.json()["hello"] == "world"

Architecture

Python handlers (def / async def / gil=True)
    โ†“
Pyre (Rust core, 12 modules)
โ”œโ”€โ”€ Tokio runtime (HTTP/1+2, WebSocket, SSE)
โ”œโ”€โ”€ Sub-interpreter pool (N independent GILs)
โ”‚   โ”œโ”€โ”€ Sync workers (def โ†’ 429k req/s)
โ”‚   โ””โ”€โ”€ Async workers (async def โ†’ 133k req/s)
โ”œโ”€โ”€ Hybrid GIL dispatch (gil=True โ†’ numpy/C extensions)
โ”œโ”€โ”€ SharedState (DashMap, cross-worker, nanosecond)
โ”œโ”€โ”€ GIL Watchdog (contention + hold time + queue depth)
โ””โ”€โ”€ Backpressure (bounded channels, 503 on overload)

Sub-interpreter Safe Ecosystem

Pyre's sub-interpreters deliver 429k req/s, but C extensions (Pydantic, NumPy, Pandas) can't run in them. Instead of fighting the ecosystem, Pyre offers a Golden Path: modern, pure-Python alternatives that are not just safe โ€” they're faster.

Category Traditional (needs gil=True) Golden Path (sub-interp safe)
Validation Pydantic V2 msgspec / mashumaro
Data Pandas + NumPy Polars
HTTP Client requests httpx
JSON orjson stdlib json / msgspec
Database psycopg2 psycopg v3 (pure Python)

The rule: pure Python = sub-interp safe. C extensions = use gil=True.

Not just safe โ€” faster

Same endpoints, same logic. Pyre with sub-interp safe libs vs FastAPI with the traditional Pydantic stack:

Test FastAPI + Pydantic Pyre + Golden Path Speedup Latency reduction
Health Check 9,031 req/s 214,714 req/s 23.8x 11.1ms โ†’ 0.38ms
JSON Echo 7,602 req/s 209,012 req/s 27.5x 13.2ms โ†’ 0.40ms
CPU-bound (10k moving avg) 263 req/s 599 req/s 2.3x 374ms โ†’ 165ms
Validation 7,345 req/s 208,439 req/s 28.4x 13.8ms โ†’ 0.41ms

The traditional stack is single-threaded โ€” the GIL serializes every request. Pyre runs 10 sub-interpreters in parallel, each with its own GIL. The Golden Path libraries are pure Python, so they load cleanly in every interpreter. The result: 24-28x throughput, 29-34x lower latency.

Run the benchmark yourself: bash benchmarks/run_comparison.sh

"Pyre doesn't force you to change, but it rewards you when you do."

Full ecosystem guide: docs/subinterp-safe-ecosystem.md

Limitations

Pyre's sub-interpreter architecture delivers extreme performance but comes with specific constraints. All are caused by CPython ecosystem limitations, not Pyre design choices, and all have clear workarounds.

C extensions in sub-interpreters

What: Libraries built with PyO3 (Rust) or C/C++ extensions cannot be imported inside sub-interpreters. This includes pydantic, numpy, pandas, orjson, and most compiled packages.

Why: CPython's PEP 684 requires extensions to declare multi-interpreter support via Py_MOD_PER_INTERPRETER_GIL_SUPPORTED. Most libraries haven't done this yet. PyO3 uses global static state that conflicts with multiple interpreters.

Workaround: Add gil=True to routes that need these libraries. They run on the main interpreter with full ecosystem access while other routes run at 429k req/s on sub-interpreters.

@app.get("/fast")                    # Sub-interpreter: 429k req/s
def fast(req): return "hello"

@app.post("/analyze", gil=True)      # Main interpreter: numpy works
def analyze(req):
    import numpy as np
    return {"result": float(np.mean([1,2,3]))}

When fixed: When PyO3 (#3451) and numpy (#24003) add PEP 684 support.

Python 3.12+ required

What: Pyre requires Python 3.12 or later.

Why: Per-Interpreter GIL (PEP 684) was introduced in Python 3.12. This is the core technology that enables Pyre's parallelism.

Workaround: None. Python 3.12+ is required. Consider using pyenv to manage multiple Python versions.

Build from source

What: Pyre must be compiled from source using Rust and Maturin. No pre-built wheels on PyPI yet.

Why: The project is pre-release. PyPI binary wheels for multiple platforms require CI/CD infrastructure.

Workaround: Install Rust (curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh) and build with maturin develop --release.

No OpenAPI auto-documentation

What: Pyre doesn't generate Swagger/OpenAPI documentation from route definitions.

Why: Pyre targets high-performance backends and AI agents, not browser-based API explorers. For AI tool discovery, Pyre provides native MCP (Model Context Protocol) support, which is purpose-built for AI applications. For human developers, Pydantic models and type stubs provide compile-time contract guarantees.

Single-process only

What: Pyre runs as a single OS process. No multi-process mode like Gunicorn or Robyn --fast.

Why: This is by design. Sub-interpreters provide multi-core parallelism within one process, with 6.7x less memory than multi-process alternatives. SharedState works without Redis. Adding multi-process would destroy these advantages.

Requirements

  • Python 3.12+ (PEP 684 sub-interpreters)
  • Rust toolchain (build from source)
  • macOS or Linux

License

Apache License 2.0 โ€” see LICENSE for details.

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

pyreframework-1.4.2.tar.gz (737.7 kB view details)

Uploaded Source

Built Distributions

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

pyreframework-1.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyreframework-1.4.2-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file pyreframework-1.4.2.tar.gz.

File metadata

  • Download URL: pyreframework-1.4.2.tar.gz
  • Upload date:
  • Size: 737.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pyreframework-1.4.2.tar.gz
Algorithm Hash digest
SHA256 6a515dd2d76eb4246f02e5abd440cfb79a7d50b3f8706158b6cc0689f36936e0
MD5 dff3f9b76c53246d4d0da98ea656f408
BLAKE2b-256 d5a2fce49bfbe186176fd5f103071ca17c885ee06aac79688757acc3eed936be

See more details on using hashes here.

File details

Details for the file pyreframework-1.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyreframework-1.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef4ca10fc7128aededf34530b43f6f2bd43dfe7542ff80213b83666d455adc82
MD5 b752fed177407c627e391385d4f7ed5c
BLAKE2b-256 69569f0b446b141809fd10a872ec69e1dfba37cd9aa011e2231633eef0068e22

See more details on using hashes here.

File details

Details for the file pyreframework-1.4.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyreframework-1.4.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61eb1c4c81a42a614e35533e222c899e7f5630eef5ea6d0061fda98d10566394
MD5 4d97e8a79f18767504033aa386d30ac7
BLAKE2b-256 e7d65a63be1b49fc57f3a7f218eda469ff0c6b6b764cb1d81da415276d047abd

See more details on using hashes here.

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