hyperframe is a pure-Python library providing the HTTP/2 framing code used in the hyper project. It allows for creating, serializing, and parsing HTTP/2 frames from a binary stream. The current version is 6.1.0, and it is actively maintained as part of the python-hyper organization.
Install & Compatibility
Where this runs
tested against v6.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.925 runs
installs and imports cleanly · install 0.0s · import 0.015s · 17.9MB
glibcpy 3.10–3.925 runs
installs and imports cleanly · install 1.5s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
The primary classes for frames are within the 'hyperframe.frame' submodule.
from hyperframe.frame import Frame
Specific frame types like DataFrame are directly importable from 'hyperframe.frame'.
from hyperframe.frame import DataFrame
Custom exceptions are located in the 'hyperframe.exceptions' submodule.
from hyperframe.exceptions import HyperframeError
This example demonstrates creating a `DataFrame`, adding data and flags, serializing it, and then parsing the header and body of a frame from raw bytes. It showcases the basic workflow for working with HTTP/2 frames. Note the use of `memoryview` for efficient binary data handling during parsing.
from hyperframe.frame import DataFrame, Frame
# Create a DATA frame
f = DataFrame(stream_id=5)
f.data = b'some binary data'
f.flags.add('END_STREAM')
f.flags.add('PADDED')
f.padding_length = 30
# Serialize the frame
data = f.serialize()
print(f"Serialized frame: {data.hex()}")
# Parse a frame header from binary data
header_bytes = data[:9] # HTTP/2 frame headers are 9 bytes
parsed_frame_header, length = Frame.parse_frame_header(memoryview(header_bytes))
print(f"Parsed frame type: {type(parsed_frame_header).__name__}, Stream ID: {parsed_frame_header.stream_id}, Length to read: {length}")
# Parse the frame body
body_bytes = data[9:9 + length]
parsed_frame_header.parse_body(memoryview(body_bytes))
print(f"Parsed frame flags: {parsed_frame_header.flags}, Data: {parsed_frame_header.data}")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.