Async http client/server framework (asyncio)
Project description
Async http client/server framework
Key Features
Supports both client and server side of HTTP protocol.
Supports both client and server Web-Sockets out-of-the-box without the Callback Hell.
Web-server has middlewares and pluggable routing.
Getting started
Client
To retrieve something from the web:
import aiohttp
import asyncio
import async_timeout
async def fetch(session, url):
async with async_timeout.timeout(10):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'http://python.org')
print(html)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Server
This is simple usage example:
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
async def wshandle(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
async for msg in ws:
if msg.type == web.MsgType.text:
await ws.send_str("Hello, {}".format(msg.data))
elif msg.type == web.MsgType.binary:
await ws.send_bytes(msg.data)
elif msg.type == web.MsgType.close:
break
return ws
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/echo', wshandle),
web.get('/{name}', handle)])
web.run_app(app)
Documentation
External links
Feel free to make a Pull Request for adding your link to these pages!
Communication channels
aio-libs google group: https://groups.google.com/forum/#!forum/aio-libs
Feel free to post your questions and ideas here.
gitter chat https://gitter.im/aio-libs/Lobby
We support Stack Overflow. Please add aiohttp tag to your question there.
Requirements
Python >= 3.5.3
Optionally you may install the cChardet and aiodns libraries (highly recommended for sake of speed).
License
aiohttp is offered under the Apache 2 license.
Keepsafe
The aiohttp community would like to thank Keepsafe (https://www.getkeepsafe.com) for it’s support in the early days of the project.
Source code
The latest developer version is available in a github repository: https://github.com/aio-libs/aiohttp
Benchmarks
If you are interested in by efficiency, AsyncIO community maintains a list of benchmarks on the official wiki: https://github.com/python/asyncio/wiki/Benchmarks
Changelog
3.1.3 (2018-04-12)
Fix cancellation broadcast during DNS resolve (#2910)
3.1.2 (2018-04-05)
3.1.1 (2018-03-27)
Support asynchronous iterators (and asynchronous generators as well) in both client and server API as request / response BODY payloads. (#2802)
3.1.0 (2018-03-21)
Welcome to aiohttp 3.1 release.
This is an incremental release, fully backward compatible with aiohttp 3.0.
But we have added several new features.
The most visible one is app.add_routes() (an alias for existing app.router.add_routes(). The addition is very important because all aiohttp docs now uses app.add_routes() call in code snippets. All your existing code still do register routes / resource without any warning but you’ve got the idea for a favorite way: noisy app.router.add_get() is replaced by app.add_routes().
The library does not make a preference between decorators:
routes = web.RouteTableDef() @routes.get('/') async def hello(request): return web.Response(text="Hello, world") app.add_routes(routes)
and route tables as a list:
async def hello(request): return web.Response(text="Hello, world") app.add_routes([web.get('/', hello)])
Both ways are equal, user may decide basing on own code taste.
Also we have a lot of minor features, bug fixes and documentation updates, see below.
Features
Relax JSON content-type checking in the ClientResponse.json() to allow “application/xxx+json” instead of strict “application/json”. (#2206)
Bump C HTTP parser to version 2.8 (#2730)
Accept a coroutine as an application factory in web.run_app and gunicorn worker. (#2739)
Implement application cleanup context (app.cleanup_ctx property). (#2747)
Make writer.write_headers a coroutine. (#2762)
Add tracking signals for getting request/response bodies. (#2767)
Deprecate ClientResponseError.code in favor of .status to keep similarity with response classes. (#2781)
Implement app.add_routes() method. (#2787)
Implement web.static() and RouteTableDef.static() API. (#2795)
Install a test event loop as default by asyncio.set_event_loop(). The change affects aiohttp test utils but backward compatibility is not broken for 99.99% of use cases. (#2804)
Refactor ClientResponse constructor: make logically required constructor arguments mandatory, drop _post_init() method. (#2820)
Use app.add_routes() in server docs everywhere (#2830)
Websockets refactoring, all websocket writer methods are converted into coroutines. (#2836)
Provide Content-Range header for Range requests (#2844)
Bugfixes
Fix websocket client return EofStream. (#2784)
Fix websocket demo. (#2789)
Property BaseRequest.http_range now returns a python-like slice when requesting the tail of the range. It’s now indicated by a negative value in range.start rather then in range.stop (#2805)
Close a connection if an unexpected exception occurs while sending a request (#2827)
Fix firing DNS tracing events. (#2841)
Improved Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file aiohttp-3.1.3.tar.gz
.
File metadata
- Download URL: aiohttp-3.1.3.tar.gz
- Upload date:
- Size: 756.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fcef0489e3335b200d31a9c1fb6ba80fdafe14cd82b971168c2f9fa1e4508ad |
|
MD5 | 973b1b845a5f91e90403e1978c898068 |
|
BLAKE2b-256 | d10170773afaf252a17a4fceb6a3ac815d2a490d67226832b05eaf0f49d6ac50 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 364.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a3cee4cd10de0ce6c37d7a35f437baa70ca87272a0ccd3d3e1a0383de2f189a |
|
MD5 | d4aa7f951aa06419922e3698ca91643c |
|
BLAKE2b-256 | 94043d80ada0a48cd7985a4a00ea273e6a0af6f221c764edeac442f11b1bf8f1 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-win32.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-win32.whl
- Upload date:
- Size: 352.2 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b61cec34628c5a2e047f93555d93c29f4e29169839b421f62206b9f317f7ae |
|
MD5 | cfb1fc1ac99ac5f6c3d4e1780a43477f |
|
BLAKE2b-256 | 96cb3d83e3dea4b937729645f8390d78d7b71c57a4d7afaf4939641453949435 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 661.2 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52fcb205ab8a43ddaf182c928f84e998a02213139b2b2636a26249569d9518bd |
|
MD5 | e1aee3099239b6efc4129fe8a55844b4 |
|
BLAKE2b-256 | 097f95e1f38eb778c76b1d5f008efc9f3d648dadd22275497a038ee0844dcd62 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 638.8 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c5de2bc5004c2c60e5f256978ad711c1fb4dca00890ac7884ed92c6aa520608 |
|
MD5 | 6614a7ebd8379e41c69a821309c47f59 |
|
BLAKE2b-256 | 90dd8fd2feaa123dccc547affa54d73f15eb464ef8bdebbe3ad21bdfbce7daaa |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 367.6 kB
- Tags: CPython 3.6m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b03578ad3f5ba6fa8b8614bd3628c4c33de92bd23af95ebd8f4de66bac35d3d8 |
|
MD5 | 40230d8b5fa6a3d7db32a5d39d721de5 |
|
BLAKE2b-256 | a4d7e7bce7efe8500f7ea3692fb1b73aa0a6f640b3729f950887aea0f2a4e723 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 375.2 kB
- Tags: CPython 3.6m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb5f0ef22896122fa5a84bf37202d3f6ee2404f12176608259bc408509f4883 |
|
MD5 | e99fd55dbb2b91c037894824b8916433 |
|
BLAKE2b-256 | 0823650cc311586ea40082d7e8e55d338abdebb4e927563ef1ed66dbbf87794d |
Provenance
File details
Details for the file aiohttp-3.1.3-cp36-cp36m-macosx_10_10_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp36-cp36m-macosx_10_10_x86_64.whl
- Upload date:
- Size: 377.2 kB
- Tags: CPython 3.6m, macOS 10.10+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | feb271ced50b689b2e4d969a5bfb0a1cfd0cc05dd11cdde4e42d93e009e0b900 |
|
MD5 | b67689fcbc4a24b183c67fecf6ad2a28 |
|
BLAKE2b-256 | 297cd34d416947409d07a890cced069964d06042964d578b65fc3321d5fe388b |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 362.4 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc50ec0dd5887844653ce5d2dd5dab93fd2e2af44d4be65d6d5306fb4039f2bf |
|
MD5 | fb20055d73201de8d6b0d36e1162ee05 |
|
BLAKE2b-256 | 5cd4457807f84af32135bd6c351ba14258a7b6fb7cbbaba9550965db16672fc4 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-win32.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-win32.whl
- Upload date:
- Size: 350.8 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33630a2dc90fee1e05bd1b57cde51d65b571c61494a1a91772c8bc0896acb5c8 |
|
MD5 | 1d76efe3800e2c72abf0458d058b0e37 |
|
BLAKE2b-256 | 0f33cf831fd0b731ee859b2b49ad6b78072b90c89f97601f96e7f6d79d17590d |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 647.2 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a55a2bf7433ddf753ed46cf5a733c787524a41b933799541075dd8db9ead1b |
|
MD5 | 764d48fa8c35dd10d88ea3e1644e4a0a |
|
BLAKE2b-256 | 1285863f2697ab633bd83587c99a306a14a2e87ce48e60d31c66d836672fe644 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 624.2 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25983293a073ae530bd4027fb82a9f16fcfe48335873582946d2dc3ed64337f0 |
|
MD5 | 6b1eeafd830b1200c4a784c02d4e1333 |
|
BLAKE2b-256 | 756efa14df8e2ba3135143ad2e7e4a7138d7b331e50009bd2600ddb2af30a5bb |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 366.8 kB
- Tags: CPython 3.5m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 390c1a2c7799519b3755a6e3f660842c3b1544e92a10ecd309ea97ce5c8c713d |
|
MD5 | e185001a9a7490f3fe227c08b9f8c97a |
|
BLAKE2b-256 | f4cf7a068026c7dfd7f963fce6cbcd923b54acb7e4d1adf0a15bf4178002b19d |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 372.8 kB
- Tags: CPython 3.5m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f883507d537a838d496755a14a41f2c34c7af5f39d7627e15d6b2a27578705b7 |
|
MD5 | 2ec00b344d254f1fd08c287b4f91af96 |
|
BLAKE2b-256 | 19e28cba3438caaab3060557550b54e77f42abbabf80b00623ac897dad506842 |
Provenance
File details
Details for the file aiohttp-3.1.3-cp35-cp35m-macosx_10_10_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.1.3-cp35-cp35m-macosx_10_10_x86_64.whl
- Upload date:
- Size: 374.6 kB
- Tags: CPython 3.5m, macOS 10.10+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f0172f7760597b636431b7651f020b8dba6a816b2d7e263afa54a4f2f4d0a6 |
|
MD5 | 867b282e8ce3e323a6dde66bd2d211f3 |
|
BLAKE2b-256 | 9b0976e671f271a886e16c6361f1bb41ec5a8033fd8fa7c87110d90a51e0af80 |