Knafeh
A high-performance QUIC-based RPC framework written in Rust with first-class Python bindings.
Knafeh provides two transport backends — raw QUIC (quinn) for maximum throughput and HTTP/3 (tokio-quiche) for gRPC compatibility — with pluggable codecs, middleware, server-streaming, and connection pooling.
Features
- Dual transport — Raw QUIC (~13K rpc/s) or HTTP/3 (~4K rpc/s), selectable per use case
- Pluggable codecs — Protobuf (default), JSON, or implement the
Codectrait - Unary & server-streaming RPCs — with length-prefixed framing for HTTP/3 streams
- Middleware —
Interceptortrait for auth, logging, tracing, rate limiting - Connection pooling — QUIC-native multiplexing with automatic reconnection
- Retries —
RetryPolicywith exponential backoff, jitter, status-code awareness - Python bindings — Native async (pyo3-async-runtimes) + sync API, anyio structured concurrency
- gRPC-compatible status codes — 17 standard codes with proper error propagation
Quick Start
Prerequisites
- Rust 1.94+
- Python >= 3.13 (for Python bindings)
- maturin (for building Python wheels)
Generate TLS Certificates
QUIC requires TLS. For development, generate a self-signed cert:
Tests generate certs automatically via rcgen — no manual setup needed.
Rust — HTTP/3 Server + Client
use Server;
use JsonCodec;
use TlsConfig;
let server = builder
.bind_str?
.tls
.codec
.add_service
.build?;
server.serve.await?;
use Client;
use JsonCodec;
let client = builder
.endpoint
.codec
.build
.await?;
let response = client.call.await?;
Rust — Raw QUIC (maximum performance)
use ;
// Server
let server = bind?;
server.serve.await?;
// Client
let client = connect_insecure.await?;
let response = client.call.await?;
Python — Async Client
= await
# Batch concurrent calls with structured cancellation (anyio TaskGroup)
= await
Python — Sync Client (scripts, notebooks)
=
Python — Server
=
=
return
await
Building & Testing
# Rust crate (Python bindings are opt-in via the python feature)
# Python
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
# Performance benchmarks (release mode)
TLS certificates are generated at runtime via rcgen — no manual cert setup needed for tests.
Releasing
Releases are published by the GitHub Actions release workflow when a semver tag like v1.0.0 is pushed. Before tagging, update the matching versions in Cargo.toml and pyproject.toml. For an existing tag, run the workflow manually and provide the tag value.
Required repository secrets:
CARGO_REGISTRY_TOKENfor crates.ioPYPI_TOKENfor PyPI
The workflow publishes the Rust crate and Linux x86_64 PyPI wheels for Python 3.13 and 3.14.
Performance
Benchmarked on localhost, release mode, 10K sequential requests:
| Transport | Throughput | p50 Latency |
|---|---|---|
| Raw QUIC (quinn) | 12,680 rpc/s | 76 us |
| HTTP/3 (tokio-quiche) | 4,300 rpc/s | 230 us |
Parallel (32 in-flight): Raw QUIC reaches 104K rpc/s, HTTP/3 reaches 15K rpc/s.
See docs/E2E_TESTING_REPORT_v1.0.0.md for full benchmark results including codec comparisons, Python client/server benchmarks, and external framework comparisons.
License
Apache-2.0