h11r translates between bytes and HTTP events. It handles message framing,
connection state, and protocol errors without reading from or writing to the
network. Connect it to synchronous sockets, asyncio, Trio, or any other
transport that can move bytes.
The protocol core is an independent Rust crate exposed as a typed Python
package through PyO3. Its connection model is inspired by
h11, while request, response, and
trailer head parsing is built on
httparse.
h11ris currently alpha software. Its public API may change before the first stable release.
Performance
The chart compares protocol-layer throughput for h11r and h11 0.16.0
across five equivalent Python HTTP/1.1 workloads that reuse their connections.
Each workload uses public APIs and includes protocol state transitions. It does
not include socket, TLS, or asynchronous runtime overhead. Higher is faster.
The results were produced by the pyperf benchmark. The
raw pyperf result used to render the chart is included for
reproduction and inspection. The measurement environment is recorded in the
chart. Results will vary with hardware and Python version.
Quick Start
Add h11r to a uv-managed project:
uv add h11r
Or install it with pip:
pip install h11r
This server-side example parses one request and produces a complete response. The caller remains responsible for network I/O.
=
# Bytes received from any synchronous or asynchronous transport.
=
=
assert
assert == b
assert
# Write the returned bytes to the same transport.
=
+=
+=
A Protocol Component, Not an HTTP Client
h11r does not open sockets, choose a concurrency model, or handle TLS,
connection pooling, redirects, cookies, or routing. It maintains the protocol
state of one HTTP/1.1 connection while higher-level clients, servers, proxies,
and test tools decide how to schedule I/O.
It supports client and server roles, HTTP/1.0 peers, Content-Length and
chunked framing, keep-alive cycles, informational responses, trailers, and
protocol handoff after Upgrade. Input size and header count have independent
limits, and local API misuse is reported separately from remote protocol
errors.
Acknowledgements
h11r follows the Sans-I/O approach of keeping protocol state
separate from network I/O. Its connection lifecycle and event model are
inspired by h11. It is not a drop-in
replacement for h11; it is a Rust-powered Python implementation built in the
same tradition.
Low-level HTTP head parsing is provided by
httparse. h11r owns the full
message framing, connection state machine, resource boundaries, and Python
API.
Contributing
See CONTRIBUTING.md for development and release guidance.
License
MIT