pylsqpack

License Version Python versions Tests

pylsqpack is a wrapper around the ls-qpack library. It provides Python Decoder and Encoder objects to read or write HTTP/3 headers compressed with QPACK.

class pylsqpack.Decoder(max_table_capacity: int, blocked_streams: int)

QPACK decoder.

Parameters:
  • max_table_capacity – the maximum size in bytes of the dynamic table

  • blocked_streams – the maximum number of streams that could be blocked

feed_encoder(data: bytes) List[int]

Feed data from the encoder stream.

If processing the data unblocked any streams, their IDs are returned, and resume_header() must be called for each stream ID.

If the data cannot be processed, EncoderStreamError is raised.

Parameters:

data – the encoder stream data

feed_header(stream_id: int, data: bytes) Tuple[bytes, List[Tuple[bytes, bytes]]]

Decode a header block and return control data and headers.

If the stream is blocked, StreamBlocked is raised.

If the data cannot be processed, DecompressionFailed is raised.

Parameters:
  • stream_id – the ID of the stream

  • data – the header block data

resume_header(stream_id: int) Tuple[bytes, List[Tuple[bytes, bytes]]]

Continue decoding a header block and return control data and headers.

This method should be called only when feed_encoder() indicates that a stream has become unblocked

Parameters:

stream_id – the ID of the stream

class pylsqpack.Encoder

QPACK encoder.

apply_settings(max_table_capacity: int, blocked_streams: int) bytes

Apply the settings received from the encoder.

Parameters:
  • max_table_capacity – the maximum size in bytes of the dynamic table

  • blocked_streams – the maximum number of streams that could be blocked

encode(stream_id: int, headers: List[Tuple[bytes, bytes]]) Tuple[bytes, bytes]

Encode a list of headers.

A tuple is returned containing two bytestrings: the encoder stream data and the encoded header block.

Parameters:
  • stream_id – the stream ID

  • headers – a list of header tuples

feed_decoder(data: bytes) None

Feed data from the decoder stream.

If the data cannot be processed, DecoderStreamError is raised.

Parameters:

data – the decoder stream data