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.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.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62c38a2b0633271cc1ba7e8436e42bc3805428c34c4a57fe319f1c1c2be1b830 |
|
MD5 | de511cebb2d5392bf5432a736338f3e3 |
|
BLAKE2b-256 | eddb3da569f5545c54a63982a817b9dbacd5e77b824554c186615b4531071e7e |
Hashes for aiohttp-3.5.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e38f05245a953b5ae9961a947ba01be6fd2e5e7af9485eef488b80b894c2e68 |
|
MD5 | 61bcff1f9b0781f6768db3da89fce701 |
|
BLAKE2b-256 | 97586036ab4cf2b77e50d34c825eb1f3c1c06e86b4cfe0a1d3cdfba844203c30 |
Hashes for aiohttp-3.5.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70fe62a0291166320fc85dbae2634a24acc652b8bf11d0f91004a53361ad677e |
|
MD5 | 11427e98ae8e8cd20794bb30464845a0 |
|
BLAKE2b-256 | 4e40bfd114bce3db2f2a8788672dd88f52a801f4499634758729a76fceb585c0 |
Hashes for aiohttp-3.5.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00085baa76d8436991475af85c1384878399cc07cbb7260ec35197c051269ea4 |
|
MD5 | 20b3555470c9bb7b0222a1fc6c0f537d |
|
BLAKE2b-256 | b60217f734b43e3abdef663a2a2d2095f462b918febea9dbef2caa51e47a2f22 |
Hashes for aiohttp-3.5.3-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f84d4152d6e8f6ee2e768ceed8b62a1f3d65747599a475cfb82214eda7531403 |
|
MD5 | 2076c2fbfefc8c929cf2460eddbac5a4 |
|
BLAKE2b-256 | f5e786a9aa960d1b76ad653566d833894609d8ab822f8c5b332bbb529e972a96 |
Hashes for aiohttp-3.5.3-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 585972c1636f432ac579ebbd548792416967d7aca863495544b22ab58824e63f |
|
MD5 | 97a4be32e4ff6aa4571ee2fc559806a5 |
|
BLAKE2b-256 | fc2ea130e273a79268e315cb4ae5470215104f0e0c278d29f224b0092bbf8d58 |
Hashes for aiohttp-3.5.3-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1594b5e9f3c566c708b16f84b9c4e7f614d44bb3cad31e1a56222817de53c13d |
|
MD5 | 894d002ca281fc64deda6c0ba6956298 |
|
BLAKE2b-256 | 00de31c81b2bae86b49098ef5750d79f40964e47cfbc0bbbb1d2235cb090db99 |
Hashes for aiohttp-3.5.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e8a27e0b2ae1835a01302497178f2c512efc1e8b248aa3253e89e361dd2bb81 |
|
MD5 | 71d05f8f109fb6fc74d1a0bedae48fce |
|
BLAKE2b-256 | 4fe1e93338ab9d2b3765e85aa3bc58bd8c45acf59b00a98ab31b00985bc526f0 |
Hashes for aiohttp-3.5.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98c4cf50a9dea93e7241ee481593ad3a906399c017402ad183a6391aa959b6b5 |
|
MD5 | 7d5508655f99b7765c4ba5e49af4a488 |
|
BLAKE2b-256 | 98e0a85723f98074ec791ee13757bd14c7121fc356b1081a5cbcbbcc307c2701 |
Hashes for aiohttp-3.5.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5208115f302b84bc7de6e9e64dbb931694102d2b6b9137430992a1e061bfe964 |
|
MD5 | 6e2874d07995a810676612d6fcdee0bb |
|
BLAKE2b-256 | 6e5401b63fda9cc825cb91072acd96253cdc1e2f5aba14fcaf67f36c99b8e838 |
Hashes for aiohttp-3.5.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d2870e1caa6a14fdfb75b5b2ad513177247fae178224e36a5b4e16e24cb8cb2 |
|
MD5 | 2aa50e65668018414766f72e69236e83 |
|
BLAKE2b-256 | 397c38fbe25b7d6ecd703faeed3acf9f1ab2dbde016667a3a0b706fbb00ba7da |
Hashes for aiohttp-3.5.3-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 872d87583baa384bf4e8d99a517d9a1b94264eca3b91d3899448c57c60a0e582 |
|
MD5 | 67a3fcc0d8996f99e7e353abbb3d5752 |
|
BLAKE2b-256 | cbaf4643468017a504efb7443d97b6a3b07a9da151c09de0e42656580dbfd33d |
Hashes for aiohttp-3.5.3-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c9340aba607652fcb776be7bbad8f03f780d3c0131230d2bda59901e0fc194f |
|
MD5 | 03e4c62c5aca66a357033a853710200c |
|
BLAKE2b-256 | b73ff842d2747887e75505e4e6afed1f18605a03cc9880c329bdffb266842d1a |
Hashes for aiohttp-3.5.3-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e83ef478bf81d53086798bbe262dcfa46b068f92b590cc2b6f116be1736340ac |
|
MD5 | 9554f6a959a8502dcc901857e4f5205d |
|
BLAKE2b-256 | b3f31218ee4b1266d0b378061a1b0b4ced17c49bb2fc6ef83b849812b96ce0fe |
Hashes for aiohttp-3.5.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab479a60b73a9986495653309572de4e70fd73319ccc06f32fe777486af346a6 |
|
MD5 | 433b4addc223ae2da4b5fdfd8a9d1ca2 |
|
BLAKE2b-256 | 3194edb655ce5914dc45b13e5bef8380f4cdb8773e8a748edde0b7458887d695 |
Hashes for aiohttp-3.5.3-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f86d74127d160530a8f10d16388ad5d7ebdb92619c70f9d5758571b6b673fb8d |
|
MD5 | 2b83703cc96b18b776a3c96579c5dd36 |
|
BLAKE2b-256 | d44bb49815e0bf2cc7aee8a7dc02326729e01a51bfbbc1c1c38d7543d8e71759 |
Hashes for aiohttp-3.5.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd64eb7cc9c1bd5502085b53ccbd256662151cfd8d287350c00d3e05ab731649 |
|
MD5 | 5430bc3f3212b3a521e2a3ba7c6eddcf |
|
BLAKE2b-256 | 0056989a57878a6869adff576b073611f78da9ba4866403184f04dc5e41e4f12 |
Hashes for aiohttp-3.5.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c959eac80233fa3181ebc4a5da4563ad27975ff8294a2b331972b401e261c95d |
|
MD5 | 5bac31be7aafac1944ae149311aa69ba |
|
BLAKE2b-256 | 6e4ff6da7811ef211659b3b91725a33a38950e43b4a0f73c9860eff226e791f3 |
Hashes for aiohttp-3.5.3-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bdae1298716279577fd76a6f71ab4dd696eecf12c11f70a33da114a46c47224 |
|
MD5 | c87f12eec07f6a2506993bd30889574e |
|
BLAKE2b-256 | 1a48e9e83c7f786508cc4d1326cb632bb5ea07e8269f7d8cda07a5583f3dca2c |
Hashes for aiohttp-3.5.3-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f14d8a6f6cf5e3b680a7c498c17df2a9383ee2a3c8f1b7cc0742cb7952ec62a5 |
|
MD5 | ab7867773e22f3a10f7806f8fb0229a9 |
|
BLAKE2b-256 | ddaadc496fcbfb620ed1792da4f0b1abad529d05fd69afefd2c71ce5384e85ee |
Hashes for aiohttp-3.5.3-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 632d4d14f81febec236e5f11c822f7b984930dc3327dcdf163fa893e574cc78a |
|
MD5 | 61e92e1fa9f19e8a6f06a1f6ea8c1a2e |
|
BLAKE2b-256 | 8edaa17641fdc0f13312cad1b3a9d7c47aee78159c35bedbc8db98aaa5c3b3d9 |