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.0b1 (2018-12-20)
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.0b3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 234f599c2b1ae93cdc04afa01921c7113c9127d2ead5480fccdea0895c6429ac |
|
MD5 | 8bf990520fd343ef6cdce1a42a54092f |
|
BLAKE2b-256 | 99733d90dda08378bf147f433d87ba9c73c08912af7617dcc4a51f2b91c5f5b8 |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebf5f947c5cbb4407ab8d614b456dc8d3d600cb5470b9dfd97ca1d0969448c83 |
|
MD5 | 44bef946b95ee340a4030f140cdcfccc |
|
BLAKE2b-256 | f29275823dc02a1564acba8b205af2dc2856020ad77875ea2d31852b6ca945e9 |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c5d494085a4a5e5de2fd75c779e892ecb4f717650f1f911740af5883c589756 |
|
MD5 | d744b95ae9d5412e31f4b3f1d78d84d4 |
|
BLAKE2b-256 | ee88efbdc95e2d8210cf40ef58702a5f7c90bfa5a58d670e2310d4425bd46a90 |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99f96c71c8748624841e4f12d049c308e7f7ff445538f17e9ba9c0e7643a737b |
|
MD5 | ae11d9dc15db1cdb2bcf37ea7238c46d |
|
BLAKE2b-256 | 111ec22be7dd71bf3ae77b963c216bb4861bf5b7a7434356b6b4198eecbb504c |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52795004b2fcc286410f781bf3511bb0b97612c2fbef0db6fa0d944ddd7dc704 |
|
MD5 | 889680d916a35ffec12e8318f6dc97e7 |
|
BLAKE2b-256 | 4e846b32a239f96783f3cd1aef2fe843ae0bb1d322f434c94023fbebe3a037aa |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cd8fcd3769cd82aecaddd2d293c393669c34a47d00800ad2eb14d68770492b9 |
|
MD5 | a608e7d9731e7b8fade11bd1832829d7 |
|
BLAKE2b-256 | 04d05c4f495779fab817e828d11c55037fc031feb326ff487bee16b6696331ff |
Hashes for aiohttp-3.5.0b3-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcfc470f07b7ca161d091ddeeef6a3ffc72bf9120e23812c15fe0d502a32e3c2 |
|
MD5 | 967c089c509325edcee66fda9d349857 |
|
BLAKE2b-256 | b9c088da9f082c11986cd3d1499a235ceaf0dff08a54800667ccefd7da47ea9e |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01161311f77707afce8ccb0a080cbd56a5732bccb4e973fdf544563f462c6428 |
|
MD5 | 29c031a3393bae3115438b71794abc75 |
|
BLAKE2b-256 | e86adbd96ed41293cfad753c3512ad813d3b16421605724ce4e43fd241fa5e93 |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0459dcd38524e1b44d0b5996c6439c4cfb23edf5fda1c3b5dfcefb70a41285b4 |
|
MD5 | eb55368936a623d76e1a21e366c9933f |
|
BLAKE2b-256 | c93fbe99b859f6f87efec0e3491e89d2219416c18456f0ea91cc928db87c4366 |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c9ba24519b13baef1e3bd3e07ae3dad1e13d701e28985100d41ae3a8a4ed4f3 |
|
MD5 | f8383551968dc869f5fee6496694aa61 |
|
BLAKE2b-256 | 588a7cdd8482193ba40c77c0bcc9b7a06cc003a816c04a6c0039424832434bd8 |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e94691f28fe78f61d4802e2ab4c39a15fa1da573c3add307c323a8c7471d19e9 |
|
MD5 | 2e757963aaab032e1b0df39fa6b36b83 |
|
BLAKE2b-256 | 02a45cad823710eb194d8c73f01df56d20afe86f19165588707d89bc04099a0f |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2ba3ca698ce85d251d111c19af8c1fb1f8d7c74d4839bbbde4e078f1b8df2b |
|
MD5 | 78be0fa59fc45314f78358b0e536e7f3 |
|
BLAKE2b-256 | e409892ebd7ef55f771fed52d0afd0876bd2e23e153293ada659a64a8741ee79 |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fce987470dcb9f64c44c8fc7ebd35915e2140e655aa8e6ce14d5aa24b581600 |
|
MD5 | f9afb956023f648ffa2ce3e82ae5b8bd |
|
BLAKE2b-256 | 9a67900ae36b50c1385e9bd214f26a1b18958b65d6aaf47e23b5e378aaf2aad4 |
Hashes for aiohttp-3.5.0b3-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b0aa0afc1cb3b1fd2157ccb5febab62229098bc06ac4df95c2ffb4fb60b7517 |
|
MD5 | 0b093333eba4c3422be7ddda27f3b29f |
|
BLAKE2b-256 | bd9430ec5031f6f5da2a352fe9276af342fda9e6d176b395274662f553235c77 |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d461faffa480c290ffaf0c13c1f48b25d1d67fc8d680062bda0d0d8da8d93d66 |
|
MD5 | 12b779b061c13b69e3780c14695d4e70 |
|
BLAKE2b-256 | 3a7774b0f2ac3b5e97902d3f04170839a4995ec1ca66c9baed555eaa97179c4d |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a961d52715aa0d4ee57e28d5ed7f53030307db3439c80a5c276b65dbf5435f8 |
|
MD5 | 53ff5918765fa3aefb0dd46a886d285a |
|
BLAKE2b-256 | 3a344d23b0af0a9e0de52e9a3d2553f3a6818131e867d93eef3516cdb5541abc |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7735951a4ca36afcf5f2c7c1630cd4be2736271bd48675136a9e965c321a8cfc |
|
MD5 | 8c6d4ca65e10b18b2ef6e5ec6d99d7e2 |
|
BLAKE2b-256 | 02e2c17f1ec01cd67025c6264c147336361c84fedc6d9fd1e79dbc76f53434a0 |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c168df3e63df99ce3de7b2369fe25061c18afdbdd743e50cc74e26ece423bc65 |
|
MD5 | 9051388307331591f6c432e93b2ae249 |
|
BLAKE2b-256 | aa0aa5872be6b9ab90647ab2e6f6c755b7d4a2be42eb6a7fb049e62032cdc667 |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2cd4b2d214be4854c641c7a4360ecc81c11c2f0ebc8b9eafd34c5e6aab28f2 |
|
MD5 | be242f2a8a2310fface9ebaca4c7aad7 |
|
BLAKE2b-256 | 19b6b5df573b3c46f8cfbdf14d31633cdcbbedbdccb08ad830206efb942eb3b1 |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83c9cfb741fd79a389042dd63a0f11d89011a2264bb3c87a34cea4abcb5c8e1d |
|
MD5 | 821d2c409bc19f3394acc4eff5e5d6ea |
|
BLAKE2b-256 | 33e0cd89f35165626e40116f4bddc50b31436f79941dc710b9bd5f0403521422 |
Hashes for aiohttp-3.5.0b3-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c64f306715036a49eb1562c44fe15777a8c579df84f30541c063e17be52fce3 |
|
MD5 | dad855f6c478dbacdf7c4cd657d88ae1 |
|
BLAKE2b-256 | 986d6fc21078eae8167867e3df54aa9a347050f447f56637e0b0f30f3d415437 |