{"id":2199,"library":"priority","title":"HTTP/2 Priority Tree","description":"Priority is a pure-Python implementation of the HTTP/2 priority logic, as described in RFC 7540 Section 5.3 (Stream Priority). It allows clients to express preferences for how servers allocate resources across concurrent HTTP/2 requests by managing a priority tree. The library uses a variant of the implementation from the H2O project. The current version, 2.0.0, was released in June 2021, indicating a stable project in maintenance mode, part of the broader python-hyper ecosystem for HTTP/2 related libraries.","status":"maintenance","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/python-hyper/priority/","tags":["http/2","priority","networking","hyper"],"install":[{"cmd":"pip install priority","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"PriorityTree","correct":"from priority import PriorityTree"}],"quickstart":{"code":"import priority\n\np = priority.PriorityTree()\np.insert_stream(stream_id=1)\np.insert_stream(stream_id=3)\np.insert_stream(stream_id=5, depends_on=1)\np.insert_stream(stream_id=7, weight=32)\np.insert_stream(stream_id=9, depends_on=7, weight=8)\np.insert_stream(stream_id=11, depends_on=7, exclusive=True)\n\n# Simulate sending data by iterating the tree\nprint(\"Initial serving order:\")\nfor _ in range(10):\n    next_stream_id = p.next_stream_to_send()\n    if next_stream_id is None:\n        print(\"  No more active streams.\")\n        break\n    print(f\"  Sending data for stream: {next_stream_id}\")\n    # Simulate blocking a stream after it's been served once\n    if next_stream_id == 7:\n        p.block(7)\n        print(\"  Stream 7 blocked for demonstration.\")\n    \n# Unblock a stream to see it re-enter the queue\np.unblock(7)\nprint(\"\\nStream 7 unblocked. Continuing serving order:\")\nfor _ in range(5):\n    next_stream_id = p.next_stream_to_send()\n    if next_stream_id is None:\n        print(\"  No more active streams.\")\n        break\n    print(f\"  Sending data for stream: {next_stream_id}\")","lang":"python","description":"Initialize a `PriorityTree`, insert streams with various dependencies and weights, then iterate using `next_stream_to_send()` to determine the optimal sending order. Demonstrates how to block and unblock streams to change their active status within the tree."},"warnings":[{"fix":"Be aware of server-side HTTP/2 implementations and network configurations. Do not assume strict adherence to client-side priority signals. Verify actual behavior through testing with tools like HTTP/2 prioritization test pages.","message":"HTTP/2 stream prioritization is a suggestion to the server, not a strict command. Servers and intermediate network elements (like proxies or CDNs) may not fully respect client-side priority requests due to their own implementation details, buffering, or policy, potentially leading to resource allocation that doesn't match client expectations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `block()`, `unblock()`, and `reprioritize()` methods are called correctly to reflect the actual state and desired priority of HTTP/2 streams in response to application logic and network conditions.","message":"The `PriorityTree`'s effectiveness relies on accurate and timely updates of stream states. Failing to call methods like `block(stream_id)` when a stream is unable to send data, or `unblock(stream_id)` when it becomes active again, can lead to suboptimal or stalled resource allocation.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}