Skip to main content

HTTP/2 implementation with hyper-h2 on Python 3 asyncio.

Project description

aioh2

https://img.shields.io/pypi/v/aioh2.svg https://img.shields.io/travis/decentfox/aioh2.svg Documentation Status

HTTP/2 implementation with hyper-h2 on Python 3 asyncio.

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)

Uploaded Source

Built Distribution

aioh2-0.1.0-py2.py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page