HTTP/2 implementation with hyper-h2 on Python 3 asyncio.
Project description
aioh2
HTTP/2 implementation with hyper-h2 on Python 3 asyncio.
Free software: BSD license
Documentation: https://aioh2.readthedocs.org.
Features
Asynchronous HTTP/2 client and server
Managed flow control
More to come
Example
# Server request handler
async def on_connected(proto):
while True:
# Receive request
stream_id, headers = await proto.recv_request()
# Send response headers
await proto.send_headers(stream_id, {':status': '200'})
# Send some response
await proto.send_data(stream_id, b'hello, ')
# Read all request body
resp = await proto.read_stream(stream_id, -1)
# Send more response
await proto.send_data(stream_id, resp)
# Send trailers
await proto.send_headers(stream_id, {'len': str(len(resp))},
end_stream=True)
# Start server on random port, with maximum concurrent requests of 3
server = await aioh2.start_server(
lambda p: asyncio.get_event_loop().create_task(on_connected(p)),
port=0, concurrency=3)
port = server.sockets[0].getsockname()[1]
# Open client connection
client = await aioh2.open_connection('0.0.0.0', port)
# Start request with headers
stream_id = await client.start_request(
{':method': 'GET', ':path': '/index.html'})
# Send request body
await client.send_data(stream_id, b'world', end_stream=True)
# Receive response
headers = await client.recv_response(stream_id)
print(headers)
# Read all response body
resp = await client.read_stream(stream_id, -1)
print(resp)
# Read response trailers
trailers = await client.recv_trailers(stream_id)
print(trailers)
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2016-1-22)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aioh2-0.1.0.tar.gz
(18.6 kB
view hashes)
Built Distribution
Close
Hashes for aioh2-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c682a32af6d89a45f435a08b5761239eb1d6e1a97f6f03d1804ab7e46e4940b9 |
|
MD5 | 2f0dd0867b0c2445c0a36ed37f116440 |
|
BLAKE2b-256 | f3b9b2b563329aa63229af31b9d987e11e57b40dbaa74081a93425fb83fe8ca1 |