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.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-4.0.0a0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1af72f53ccead6d161296e576aa2b5d0c6c7403a389601dd7aa7a7a30a9f41c3 |
|
MD5 | f6b7939f5dafda5b105ff6bd0f016198 |
|
BLAKE2b-256 | d7ce54337d8270600f214b293e763fded18352e19b3c1ee65ddbe83548a33558 |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c65d65d0de79f1a4391bc29c8c8ec7655671a03ad7902d5e66fd735531893e |
|
MD5 | a973b6f04554a85c556476e07242623d |
|
BLAKE2b-256 | c5b095f47a79cab51300af846e8e83da149336d1f7e639b7c90091836d04322b |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32eeef64a5bcf6dc652f19e020b16f36ec66d291957f62ffad18ecfc58695966 |
|
MD5 | 4f6b0394d32be84b9f887001d2bb0465 |
|
BLAKE2b-256 | 3274652b3103e10c036eefbaadba5a4d7cfc146fbf352f132fd4ef33dc29ea2d |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ebf518c7bc08e65b5396f80e8155c7bb1380b921b84b510570e62196c9fca56 |
|
MD5 | f4ad234a3b06a82c98e23d38938ed1ff |
|
BLAKE2b-256 | 5649d33ce192f876034d6b41108a1c0bf089ed95228f3a95e81ddfc215f25b4a |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f2c905ab82aa0ee8a06210d5a6c1359c79f3f2088cc1b53c8758cae1dbc0d55 |
|
MD5 | a07abe47374f6cb86af6b20b7c454067 |
|
BLAKE2b-256 | 356c4291d4a5df67cfc6b30926331c688c0d0806c3e82b6994e8fc6d37e0e8e8 |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb9c2f27d2db6d709a02421733bb6ad22e16104beb2cf403e1120c24f3cc8668 |
|
MD5 | 2080c7d45e0b04b3b263c29a7a4739d2 |
|
BLAKE2b-256 | 2eb718eb453a8dad77fa26be0c4e459bd30f59c694a25429618d9f6a1d349c92 |
Hashes for aiohttp-4.0.0a0-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02396865118790ebb0bd14d6935e9e4fa80d87683240618894e585048a8b83ec |
|
MD5 | 0e26a25f82c36c19d82e1cdd9433a87f |
|
BLAKE2b-256 | 507a20a174ce0ab8c65ddee27d886e95b334f9338a34db9c7e711a55f1d23810 |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9efc80ced0936f3fb2774e1bc981006324c74d1e58fc7f7164ecd98ede727c7d |
|
MD5 | bd50374fb1f0a64642fd4253e942e0bb |
|
BLAKE2b-256 | b52f47e14bf2bdf53a6e87daa7f777210fe4e23eed719de4df1c24aab13dac1e |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c30eca95e7d60fbf13e6ebcaf62b7c0f3f93ec5de8862919aa5ede3720b1c86 |
|
MD5 | 5fa9bdf5ab54eeedf5b616617dd23987 |
|
BLAKE2b-256 | 5f3af1855591da81066203282207085be693568c6b33ccfb1e1cd0a397b6cc92 |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abc43651f2c6d70b812cb874fc8caa00eb69fac11930cd2640d32a11ee7beef0 |
|
MD5 | 0a30fc78d7723768a189e86563c1271b |
|
BLAKE2b-256 | 02d095aa6e81c978fe436d41a1a0511dfb66598888c7fc7d93ade5fee9483d7a |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f448b5d5cd45e642b9fcf4798e48cca4149ae479022f59bd67a47caed44657e |
|
MD5 | e2c0b69264dd48a97d465a355dffa2a6 |
|
BLAKE2b-256 | 473d6c23a267ab99835ffd098331f8398544238721dc4698624e191c42e77c57 |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f5a30f67e4152d4075063ae9f2286313af2e39b950869edba76232569e08793 |
|
MD5 | 42abaf2020c395ae2235a3c3905edc76 |
|
BLAKE2b-256 | 5a6b4b857c8d35dcff7742fecf4dacbb86f3beb9c8452bc4b99d1941862ef59c |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67cb8e71c043686f806cfdb4189774c57ef929d32890024c3775d72b54381797 |
|
MD5 | 61f008e27a293ffc98a64c6a29282515 |
|
BLAKE2b-256 | e4066c258d420304ad36437d3f7f04b6b7c97518e3b7736df560ccc79a846e0f |
Hashes for aiohttp-4.0.0a0-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53228028648b40f59fc941c0cd67b7899bce52f35eb66aeb9e33b75bac0aac0a |
|
MD5 | 768a36748ffc1375ce43a8375ad594bb |
|
BLAKE2b-256 | aa0efc1fb21b224ef1d0a5984e6b342a04ed95c6b6e01207326c0f37537e251f |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee80820a8ef5f6bddd58d762fc9f981ef1041a464d382d7d9a992bb94cd23c6 |
|
MD5 | fde7c1d61fb9221577e9ca5526ab158f |
|
BLAKE2b-256 | f25dd0170507c42d5ede061927fb65bfc9e34280fb45b4ffbb34713f780b6687 |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 746b73eff86a1618025093b9c86ff4d642cff71a7ac7244f7fd8a186967cee22 |
|
MD5 | f8a39fad30cd7b185294d828884e14b0 |
|
BLAKE2b-256 | b1987410e7ee22fd76dafba53a349f929a9cd6bf12cf34b4714811dd3088d396 |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ede22808195126d55879f1a14aaa3d1004f188c341f92ec3b9ca5ea13e695b9 |
|
MD5 | 5aca7f112c4ed66a995b3f2ca7594ad0 |
|
BLAKE2b-256 | 4a9fc0bfc666ec3295d05139daad63b26f366cb4cd0654e61243be6916e1c231 |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b1e99dc838c28f14e45bffef6fb77bf5b54bd2bfb1a475c776da5ba8a9fec2d |
|
MD5 | 17467ca684f96ef9717fb2e80ee72b78 |
|
BLAKE2b-256 | 43212ea6706620c287b7077a890b40c0e099cfdb5ce5b8a605d8dcc9c469be1b |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c4e234a85a81e325d8b1d7fdeb696a3d51bb8eb09a8c8e69c7532b421e8a29 |
|
MD5 | 75bac0888b2ceaf123ab0a27aa8e02ba |
|
BLAKE2b-256 | 4ce9d57f4f96978198c060aa47504ee5c51d52ebefb74640147c2529ef6fd6f6 |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c6e1f5a591511537d4ccd4c807f6c8bb8d1b8a5043395950ba339086380904 |
|
MD5 | 95ab6abee159214e24100948a818c708 |
|
BLAKE2b-256 | ad41703b5c7149ded3a580951e3b9306d55274002c1453126164d551e0eeec9a |
Hashes for aiohttp-4.0.0a0-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c304dcc1494dbc3fc492ebc2e61d0db323be9756a1bb14f407097d8adf82ec |
|
MD5 | fbd58967abca868a75aa102bcbb481cb |
|
BLAKE2b-256 | c50dd3da901cfbd2094e4f91827d61391d588098ff3afa9d53cc07468b7c9b19 |