Module

_priority

HTTP Priority Signals (RFC 9218).

Parses thePriority header (u=N, i) from HTTP/2 requests and provides a simple priority-based scheduler for DATA frame writes.

RFC 9218 defines:

  • u=N(urgency): 0-7, default 3. Lower is more urgent.
  • i(incremental): boolean. If present, response can be interleaved.

This module provides:

  1. Parsing of Priority header values
  2. A per-connection priority scheduler for ordering stream writes

Classes

StreamPriority 2
Parsed priority for a single HTTP/2 stream.

Parsed priority for a single HTTP/2 stream.

Attributes

Name Type Description
urgency int

0 (highest) to 7 (lowest). Default: 3.

incremental bool

If True, response can be interleaved with others.

PriorityScheduler 8
Priority-based scheduler for HTTP/2 stream writes. Maintains a per-stream priority and provides or…

Priority-based scheduler for HTTP/2 stream writes.

Maintains a per-stream priority and provides ordering for which stream should get bandwidth next. Higher urgency (lower number) streams are served first. Among same-urgency streams, incremental streams can interleave while non-incremental streams are sequential.

All operations are O(log n) via a min-heap. Thread-safe: a lock protects all mutable state for correctness under free-threading.

Methods

has_pending 0 bool
True if any streams are waiting to send.
property
def has_pending(self) -> bool
Returns
bool
stream_count 0 int
Number of tracked streams.
property
def stream_count(self) -> int
Returns
int
set_priority 2
Set or update the priority for a stream.
def set_priority(self, stream_id: int, priority: StreamPriority) -> None
Parameters
Name Type Description
stream_id

The HTTP/2 stream identifier.

priority

The parsed priority for this stream.

get_priority 1 StreamPriority
Get the priority for a stream (default: urgency=3, not incremental).
def get_priority(self, stream_id: int) -> StreamPriority
Parameters
Name Type Description
stream_id
Returns
StreamPriority
schedule 1
Mark a stream as ready to send data.
def schedule(self, stream_id: int) -> None
Parameters
Name Type Description
stream_id

The stream that has data to write.

next_stream 0 int | None
Get the next stream that should write data.
def next_stream(self) -> int | None
Returns
int | None Stream ID with highest priority (lowest urgency), or None if no streams are pending.
remove_stream 1
Remove a stream from the scheduler.
def remove_stream(self, stream_id: int) -> None
Parameters
Name Type Description
stream_id

The stream to remove.

Internal Methods 1
__init__ 0
def __init__(self) -> None

Functions

parse_priority 1 StreamPriority
Parse an RFC 9218 Priority header value.
def parse_priority(value: bytes | str) -> StreamPriority
Parameters
Name Type Description
value bytes | str

The Priority header value (e.g.,u=1, i).

Returns
StreamPriority