Skip to main content
https://raw.github.com/Lukasa/hyper/development/docs/source/images/hyper.png https://travis-ci.org/python-hyper/hyper-h2.png?branch=master

This repository contains a pure-Python implementation of a HTTP/2 protocol stack. It’s written from the ground up to be embeddable in whatever program you choose to use, ensuring that you can speak HTTP/2 regardless of your programming paradigm.

You use it like this:

import h2.connection

conn = h2.connection.H2Connection()
conn.send_headers(stream_id=stream_id, headers=headers)
conn.send_data(stream_id, data)
socket.sendall(conn.data_to_send())
events = conn.receive_data(socket_data)

This repository does not provide a parsing layer, a network layer, or any rules about concurrency. Instead, it’s a purely in-memory solution, defined in terms of data actions and HTTP/2 frames. This is one building block of a full Python HTTP implementation.

To install it, just run:

pip install h2

Documentation

Documentation is available at http://python-hyper.org/h2/.

Contributing

hyper-h2 welcomes contributions from anyone! Unlike many other projects we are happy to accept cosmetic contributions and small contributions, in addition to large feature requests and changes.

Before you contribute (either by opening an issue or filing a pull request), please read the contribution guidelines.

License

hyper-h2 is made available under the MIT License. For more details, see the LICENSE file in the repository.

Authors

hyper-h2 is maintained by Cory Benfield, with contributions from others. For more details about the contributors, please see CONTRIBUTORS.rst.

Release History

2.1.0 (2016-02-02)

API Changes (Backward-Compatible)

  • Added new field to DataReceived: flow_controlled_length. This is the length of the frame including padded data, allowing users to correctly track changes to the flow control window.

  • Defined new UnsupportedFrameError, thrown when frames that are known to hyperframe but not supported by hyper-h2 are received. For backward-compatibility reasons, this is a ProtocolError and a KeyError.

Bugfixes

  • Hyper-h2 now correctly accounts for padding when maintaining flow control windows.

  • Resolved a bug where hyper-h2 would mistakenly apply SETTINGS_INITIAL_WINDOW_SIZE to the connection flow control window in addition to the stream-level flow control windows.

  • Invalid Content-Length headers now throw ProtocolError exceptions and correctly tear the connection down, instead of leaving the connection in an indeterminate state.

  • Invalid header blocks now throw ProtocolError, rather than a grab bag of possible other exceptions.

2.0.0 (2016-01-25)

API Changes (Breaking)

  • Attempts to open streams with invalid stream IDs, either by the remote peer or by the user, are now rejected as a ProtocolError. Previously these were allowed, and would cause remote peers to error.

  • Receiving frames that have invalid padding now causes the connection to be terminated with a ProtocolError being raised. Previously these passed undetected.

  • Settings values set by both the user and the remote peer are now validated when they’re set. If they’re invalid, a new InvalidSettingsValueError is raised and, if set by the remote peer, a connection error is signaled. Previously, it was possible to set invalid values. These would either be caught when building frames, or would be allowed to stand.

  • Settings changes no longer require user action to be acknowledged: hyper-h2 acknowledges them automatically. This moves the location where some exceptions may be thrown, and also causes the acknowledge_settings method to be removed from the public API.

  • Removed a number of methods on the H2Connection object from the public, semantically versioned API, by renaming them to have leading underscores. Specifically, removed:

    • get_stream_by_id

    • get_or_create_stream

    • begin_new_stream

    • receive_frame

    • acknowledge_settings

  • Added full support for receiving CONTINUATION frames, including policing logic about when and how they are received. Previously, receiving CONTINUATION frames was not supported and would throw exceptions.

  • All public API functions on H2Connection except for receive_data no longer return lists of events, because these lists were always empty. Events are now only raised by receive_data.

  • Calls to increment_flow_control_window with out of range values now raise ValueError exceptions. Previously they would be allowed, or would cause errors when serializing frames.

API Changes (Backward-Compatible)

  • Added PriorityUpdated event for signaling priority changes.

  • Added get_next_available_stream_id function.

  • Receiving DATA frames on streams not in the OPEN or HALF_CLOSED_LOCAL states now causes a stream reset, rather than a connection reset. The error is now also classified as a StreamClosedError, rather than a more generic ProtocolError.

  • Receiving HEADERS or PUSH_PROMISE frames in the HALF_CLOSED_REMOTE state now causes a stream reset, rather than a connection reset.

  • Receiving frames that violate the max frame size now causes connection errors with error code FRAME_SIZE_ERROR, not a generic PROTOCOL_ERROR. This condition now also raises a FrameTooLargeError, a new subclass of ProtocolError.

  • Made NoSuchStreamError a subclass of ProtocolError.

  • The StreamReset event is now also fired whenever a protocol error from the remote peer forces a stream to close early. This is only fired once.

  • The StreamReset event now carries a flag, remote_reset, that is set to True in all cases where StreamReset would previously have fired (e.g. when the remote peer sent a RST_STREAM), and is set to False when it fires because the remote peer made a protocol error.

  • Hyper-h2 now rejects attempts by peers to increment a flow control window by zero bytes.

  • Hyper-h2 now rejects peers sending header blocks that are ill-formed for a number of reasons as set out in RFC 7540 Section 8.1.2.

  • Attempting to send non-PRIORITY frames on closed streams now raises StreamClosedError.

  • Remote peers attempting to increase the flow control window beyond 2**31 - 1, either by window increment or by settings frame, are now rejected as ProtocolError.

  • Local attempts to increase the flow control window beyond 2**31 - 1 by window increment are now rejected as ProtocolError.

  • The bytes that represent individual settings are now available in h2.settings, instead of needing users to import them from hyperframe.

Bugfixes

  • RFC 7540 requires that a separate minimum stream ID be used for inbound and outbound streams. Hyper-h2 now obeys this requirement.

  • Hyper-h2 now does a better job of reporting the last stream ID it has partially handled when terminating connections.

  • Fixed an error in the arguments of StreamIDTooLowError.

  • Prevent ValueError leaking from Hyperframe.

  • Prevent struct.error and InvalidFrameError leaking from Hyperframe.

1.1.1 (2015-11-17)

Bugfixes

  • Forcibly lowercase all header names to improve compatibility with implementations that demand lower-case header names.

1.1.0 (2015-10-28)

API Changes (Backward-Compatible)

  • Added a new ConnectionTerminated event, which fires when GOAWAY frames are received.

  • Added a subclass of NoSuchStreamError, called StreamClosedError, that fires when actions are taken on a stream that is closed and has had its state flushed from the system.

  • Added StreamIDTooLowError, raised when the user or the remote peer attempts to create a stream with an ID lower than one previously used in the dialog. Inherits from ValueError for backward-compatibility reasons.

Bugfixes

  • Do not throw ProtocolError when attempting to send multiple GOAWAY frames on one connection.

  • We no longer forcefully change the decoder table size when settings changes are ACKed, instead waiting for remote acknowledgement of the change.

  • Improve the performance of checking whether a stream is open.

  • We now attempt to lazily garbage collect closed streams, to avoid having the state hang around indefinitely, leaking memory.

  • Avoid further per-stream allocations, leading to substantial performance improvements when many short-lived streams are used.

1.0.0 (2015-10-15)

  • First production release!

Release files for h2 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h2 2.1.0
File Size Uploaded
h2-2.1.0.tar.gz 49.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h2 2.1.0
File Interpreter ABI Platform
h2-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 88.0 kB

Release files / h2-2.1.0.tar.gz

Download URL h2-2.1.0.tar.gz
Size 49.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e575a46f66d2b782bdf443d02b04a4c2037c0735854c3ea380319695e80a927c
BLAKE2b-256 checksum
How to use checksums
b72e00e099b386eaecf0016ec960a12506fd7799f8b7cd356cc06938f21d47f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / h2-2.1.0-py2.py3-none-any.whl

Download URL h2-2.1.0-py2.py3-none-any.whl
Size 38.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9e5baa7a58c1a9cd1232ae35c2cb59048ddbf758df0f5af9c2d4277f4dd2a8b1
BLAKE2b-256 checksum
How to use checksums
4b9b2cfc0f33360c029c7259775a4685811eea50e6dc82787e8f0e0e2cef1d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

4.4.1

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.6.2

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.4

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.4

2 release files

2.4.3

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.7

2 release files

2.2.6

2 release files

2.2.5

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page