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 and avoids Callback Hell.
Provides Web-server with middlewares and pluggable routing.
Getting started
Client
To get something from the web:
import aiohttp
import asyncio
async def fetch(session, url):
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
An example using a simple server:
# examples/server_simple.py
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.WSMsgType.text:
await ws.send_str("Hello, {}".format(msg.data))
elif msg.type == web.WSMsgType.binary:
await ws.send_bytes(msg.data)
elif msg.type == web.WSMsgType.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
Demos
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 its 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 efficiency, the AsyncIO community maintains a list of benchmarks on the official wiki: https://github.com/python/asyncio/wiki/Benchmarks
Changelog
3.5.4 (2019-01-12)
Bugfixes
Fix stream .read() / .readany() / .iter_any() which used to return a partial content only in case of compressed content #3525
3.5.3 (2019-01-10)
Bugfixes
Fix type stubs for aiohttp.web.run_app(access_log=True) and fix edge case of access_log=True and the event loop being in debug mode. #3504
Fix aiohttp.ClientTimeout type annotations to accept None for fields #3511
Send custom per-request cookies even if session jar is empty #3515
Restore Linux binary wheels publishing on PyPI
3.5.2 (2019-01-08)
Features
Bugfixes
Preserve MultipartWriter parts headers on write.
Refactor the way how Payload.headers are handled. Payload instances now always have headers and Content-Type defined.
Fix Payload Content-Disposition header reset after initial creation. #3035
Log suppressed exceptions in GunicornWebWorker. #3464
Remove wildcard imports. #3468
Use the same task for app initialization and web server handling in gunicorn workers. It allows to use Python3.7 context vars smoothly. #3471
Fix handling of chunked+gzipped response when first chunk does not give uncompressed data #3477
Replace collections.MutableMapping with collections.abc.MutableMapping to avoid a deprecation warning. #3480
Payload.size type annotation changed from Optional[float] to Optional[int]. #3484
Ignore done tasks when cancels pending activities on web.run_app finalization. #3497
Improved Documentation
Add documentation for aiohttp.web.HTTPException. #3490
Misc
3.5.1 (2018-12-24)
Fix a regression about ClientSession._requote_redirect_url modification in debug mode.
3.5.0 (2018-12-22)
Features
The library type annotations are checked in strict mode now.
Add support for setting cookies for individual request (#2387)
Application.add_domain implementation (#2809)
The default app in the request returned by test_utils.make_mocked_request can now have objects assigned to it and retrieved using the [] operator. (#3174)
Make request.url accessible when transport is closed. (#3177)
Add zlib_executor_size argument to Response constructor to allow compression to run in a background executor to avoid blocking the main thread and potentially triggering health check failures. (#3205)
Enable users to set ClientTimeout in aiohttp.request (#3213)
Don’t raise a warning if NETRC environment variable is not set and ~/.netrc file doesn’t exist. (#3267)
Add default logging handler to web.run_app
If the Application.debug flag is set and the default logger aiohttp.access is used, access logs will now be output using a stderr StreamHandler if no handlers are attached. Furthermore, if the default logger has no log level set, the log level will be set to DEBUG. (#3324)
Add method argument to session.ws_connect().
Sometimes server API requires a different HTTP method for WebSocket connection establishment.
For example, Docker exec needs POST. (#3378)
Create a task per request handling. (#3406)
Bugfixes
Enable passing access_log_class via handler_args (#3158)
Return empty bytes with end-of-chunk marker in empty stream reader. (#3186)
Accept CIMultiDictProxy instances for headers argument in web.Response constructor. (#3207)
Don’t uppercase HTTP method in parser (#3233)
Make method match regexp RFC-7230 compliant (#3235)
Add app.pre_frozen state to properly handle startup signals in sub-applications. (#3237)
Enhanced parsing and validation of helpers.BasicAuth.decode. (#3239)
Change imports from collections module in preparation for 3.8. (#3258)
Ensure Host header is added first to ClientRequest to better replicate browser (#3265)
Fix forward compatibility with Python 3.8: importing ABCs directly from the collections module will not be supported anymore. (#3273)
Keep the query string by normalize_path_middleware. (#3278)
Fix missing parameter raise_for_status for aiohttp.request() (#3290)
Bracket IPv6 addresses in the HOST header (#3304)
Fix default message for server ping and pong frames. (#3308)
Fix tests/test_connector.py typo and tests/autobahn/server.py duplicate loop def. (#3337)
Fix false-negative indicator end_of_HTTP_chunk in StreamReader.readchunk function (#3361)
Release HTTP response before raising status exception (#3364)
Fix task cancellation when sendfile() syscall is used by static file handling. (#3383)
Fix stack trace for asyncio.TimeoutError which was not logged, when it is caught in the handler. (#3414)
Improved Documentation
Deprecations and Removals
Deprecate modification of session.requote_redirect_url (#2278)
Deprecate stream.unread_data() (#3260)
Deprecated use of boolean in resp.enable_compression() (#3318)
Encourage creation of aiohttp public objects inside a coroutine (#3331)
Drop dead Connection.detach() and Connection.writer. Both methods were broken for more than 2 years. (#3358)
Deprecate app.loop, request.loop, client.loop and connector.loop properties. (#3374)
Deprecate explicit debug argument. Use asyncio debug mode instead. (#3381)
Deprecate body parameter in HTTPException (and derived classes) constructor. (#3385)
Deprecate bare connector close, use async with connector: and await connector.close() instead. (#3417)
Deprecate obsolete read_timeout and conn_timeout in ClientSession constructor. (#3438)
Misc
#3341, #3351
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
Hashes for aiohttp-3.5.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368ed312550bd663ce84dc4b032a962fcb3c7cae099dbbd48663afc305e3b939 |
|
MD5 | 945f4ef71f7e9952f408aa25592f06a3 |
|
BLAKE2b-256 | bcbd08f0900d62b4ea1ca10bb2e2a1596ac3b04024c7daf7350debee0bd022fb |
Hashes for aiohttp-3.5.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d5ec9b8948c3d957e75ea14d41e9330e1ac3fed24ec53766c780f82805140dc |
|
MD5 | bd7ceef98b92af47db2ce1a951319d99 |
|
BLAKE2b-256 | 2b6fa20c36018f2a1804b54bce2377f06ccd173572351f17e1df098be38eba5a |
Hashes for aiohttp-3.5.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00d198585474299c9c3b4f1d5de1a576cc230d562abc5e4a0e81d71a20a6ca55 |
|
MD5 | 143cf0610d720e4db6fb83aeb5209b2a |
|
BLAKE2b-256 | 3360c21acb7002110699761d3dec36fad3f5087c2752a4eb495444f877db6553 |
Hashes for aiohttp-3.5.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c3c582ee11af7f63a34a46f0448fca58e59889396ffdae1f482085061a2889 |
|
MD5 | da1ccf3a204e7b693f5a587ffd34f7a2 |
|
BLAKE2b-256 | 455de792594f40bb6bc306aa85bdfdd266ba1159cb9c67173eb1b4cab578618d |
Hashes for aiohttp-3.5.4-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a97a516e02b726e089cffcde2eea0d3258450389bbac48cbe89e0f0b6e7b0366 |
|
MD5 | a5dd0f63344c6a3ba06ea9e4827cbb22 |
|
BLAKE2b-256 | 1660c6ac986c2caeab6d3bae1e0b3400ab49df3aff23a8e37c543be68780d014 |
Hashes for aiohttp-3.5.4-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d7ea570b88db017c51392349cf99b7aefaaddd19d2c78368aeb0bddde9d390 |
|
MD5 | 089d546f24101b1b116a27780c7786f7 |
|
BLAKE2b-256 | 8026b613d3ddeddfb260c9894a5aae16f01fb94f2e53813f09408288241159d2 |
Hashes for aiohttp-3.5.4-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b05bd85cc99b06740aad3629c2585bda7b83bd86e080b44ba47faf905fdf1300 |
|
MD5 | c369153e23c52fdc19afd09639b3892f |
|
BLAKE2b-256 | 28a6b4b527203dee74918ec008b9c262b2073e0242843118355d82b1cb763972 |
Hashes for aiohttp-3.5.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a02a04bbe581c8605ac423ba3a74999ec9d8bce7ae37977a3d38680f5780b6d |
|
MD5 | d018e4fa6239299d669a6d033b8c6212 |
|
BLAKE2b-256 | b0b4b5b59a05ac9845712902ea87c6b7945e041a78462c2c6e094b394fca6840 |
Hashes for aiohttp-3.5.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296f30dedc9f4b9e7a301e5cc963012264112d78a1d3094cd83ef148fdf33ca1 |
|
MD5 | ef2512ad36fdaa20b86ca1ed7749dde9 |
|
BLAKE2b-256 | 41a9117a4f0a1791b7f9db0cc1d7d85a05a49b66990dc6302bd9fd635c92ab85 |
Hashes for aiohttp-3.5.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2bec436a2b5dafe5eaeb297c03711074d46b6eb236d002c13c42f25c4a8ce9d |
|
MD5 | 7ee91162450ed06f2b12ee8bf24c8e11 |
|
BLAKE2b-256 | 0d5cf87987f4dc8b2cfcf37c83a814ea4b2aff4d285cbffc0ab08b2b4fa3f584 |
Hashes for aiohttp-3.5.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4392defd4648badaa42b3e101080ae3313e8f4787cb517efd3f5b8157eaefd6 |
|
MD5 | 492adf005eed4eae21b9b67154bffa9f |
|
BLAKE2b-256 | f4b52997ebf5d44626b8ec9dd00952ea21c3e30d9afd48b3cc511f023affaf33 |
Hashes for aiohttp-3.5.4-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cddaff94c0135ee627213ac6ca6d05724bfe6e7a356e5e09ec57bd3249510f6 |
|
MD5 | f7b836f5ebe11be2e3960303fc7a920e |
|
BLAKE2b-256 | 743083e59bc133a04fb0db67f3bd80558129e2c5f53b12d75980d122162447fe |
Hashes for aiohttp-3.5.4-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5cbd7157b0e383738b8e29d6e556fde8726823dae0e348952a61742b21aeb12 |
|
MD5 | 856a31cf15c4c91176d4197586cbd09e |
|
BLAKE2b-256 | d30b68f2db07c7d2865f0a04b209599c5c59e0de2c121567438aa1e8b9713b72 |
Hashes for aiohttp-3.5.4-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87331d1d6810214085a50749160196391a712a13336cd02ce1c3ea3d05bcf8d5 |
|
MD5 | 3104ff1fa055e7913cf07e8cabc27261 |
|
BLAKE2b-256 | 572bd4ddec2e1b5f048e94efa86cf74f7b466dabab7d40f25260e53459047f34 |
Hashes for aiohttp-3.5.4-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a25237abf327530d9561ef751eef9511ab56fd9431023ca6f4803f1994104d72 |
|
MD5 | 3d77ea2bd34ed61c824786150b388164 |
|
BLAKE2b-256 | 4be498a2a1b1015427bff31cc390defaf55d01fd6aceda10c11f0f3c1ad6ffb0 |
Hashes for aiohttp-3.5.4-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acc89b29b5f4e2332d65cd1b7d10c609a75b88ef8925d487a611ca788432dfa4 |
|
MD5 | 27fa1136ab66c058a309ad71c7e047c2 |
|
BLAKE2b-256 | 2c015d1c5db6435da0c03967502d487bd2fcb87b5592de64e76c76a6f90d8980 |
Hashes for aiohttp-3.5.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 629102a193162e37102c50713e2e31dc9a2fe7ac5e481da83e5bb3c0cee700aa |
|
MD5 | 56b1d4207922988c910e8c908de3487b |
|
BLAKE2b-256 | 21e635e3f6b1a0aea0c5567ef7fadc727487cacb7a15a892403213fcee8f9280 |
Hashes for aiohttp-3.5.4-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09654a9eca62d1bd6d64aa44db2498f60a5c1e0ac4750953fdd79d5c88955e10 |
|
MD5 | 42de1baa009ad0263ba455f3e4c010a8 |
|
BLAKE2b-256 | 6d1631b2e95c396cf66e606eca5456099bc488a3f1f394f5587d6718f8874479 |
Hashes for aiohttp-3.5.4-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc619d974c8c11fe84527e4b5e1c07238799a8c29ea1c1285149170524ba9303 |
|
MD5 | 3e617939b53bf0261e5102b27a3febe6 |
|
BLAKE2b-256 | 926385e28605cd8f08a062974db3338c7e77437b662d980ef0dc6705fde167c6 |
Hashes for aiohttp-3.5.4-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0155af66de8c21b8dba4992aaeeabf55503caefae00067a3b1139f86d0ec50ed |
|
MD5 | de23fa96659f9835e5258c553998ccb9 |
|
BLAKE2b-256 | 9c4cbc69821c2cc440520a9569e5ad31554b7c35f5c2a26a34ef7b6ee1d07bd5 |
Hashes for aiohttp-3.5.4-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 199f1d106e2b44b6dacdf6f9245493c7d716b01d0b7fbe1959318ba4dc64d1f5 |
|
MD5 | 5536152af71471533fd3680658459235 |
|
BLAKE2b-256 | c46e88ee58bd3a69dcb39b8f14ee56a28421a0d28711c47b6c1282997020a95b |