Welcome to aioh2’s documentation!¶
Contents:
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
- Multiplexing streams of data with managed flow and priority control
- Optional tickless health check
- More to come
Non-features:
- Request/Response wrappers
- Web server, dispatcher, cookie, etc
- HTTP/2 upgrade
Example¶
A server saying hello:
# Server request handler
async def on_connected(proto):
while True:
# Receive a request from queue
stream_id, headers = await proto.recv_request()
# Send response headers
await proto.start_response(stream_id, {':status': '200'})
# Response body starts with "hello"
await proto.send_data(stream_id, b'hello, ')
# Read all request body as a name from client side
name = await proto.read_stream(stream_id, -1)
# Amend response body with the name
await proto.send_data(stream_id, name)
# Send trailers with the length of the name
await proto.send_trailers(stream_id, {'len': str(len(name))})
# 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]
And a client to try out:
# Open client connection
client = await aioh2.open_connection('0.0.0.0', port,
functional_timeout=0.1)
# Optionally wait for an ack of tickless ping - a.k.a. until functional
await asyncio.sleep(0.1) # simulate client being busy with something else
rtt = await client.wait_functional()
if rtt:
print('Round-trip time: %.1fms' % (rtt * 1000))
# Start request with headers
stream_id = await client.start_request(
{':method': 'GET', ':path': '/index.html'})
# Send my name "world" as whole request body
await client.send_data(stream_id, b'world', end_stream=True)
# Receive response headers
headers = await client.recv_response(stream_id)
print('Response headers:', headers)
# Read all response body
resp = await client.read_stream(stream_id, -1)
print('Response body:', resp)
# Read response trailers
trailers = await client.recv_trailers(stream_id)
print('Response trailers:', trailers)
Above example can be found at examples/core.py.
Credits¶
A big thanks to the great library hyper-h2 from Cory Benfield.
DecentFoX Studio is a software outsourcing company delivering high-quality web-based products and mobile apps for global customers with agile methodology, focusing on bleeding-edge technologies and fast-developing scalable architectures.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Installation¶
At the command line:
$ easy_install aioh2
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv aioh2
$ pip install aioh2
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/decentfox/aioh2/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
aioh2 could always use more documentation, whether as part of the official aioh2 docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/decentfox/aioh2/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up aioh2 for local development.
Fork the aioh2 repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/aioh2.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv aioh2 $ cd aioh2/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 aioh2 tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/decentfox/aioh2/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Fantix King <fantix.king@gmail.com>
Contributors¶
None yet. Why not be the first?