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.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.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a68232a60b8c1a822c4ac4096bfb42b4f873ac7dcef265642223690220b5af4f |
|
MD5 | 756bde6c56721e0fc7c5ebaedbfd5526 |
|
BLAKE2b-256 | 24b7cb6f90b733db21eea886774f576f8e68359c0f7fc419b6751468754f3d75 |
Hashes for aiohttp-3.5.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed65392135299698b0ebff4ee53ccf19d5c7c12077652a7faab05db369eb3996 |
|
MD5 | c63d243469d213fbf84e93e636cbfc58 |
|
BLAKE2b-256 | 96db612309801331f993afe0d59c10e7ddd2dc868d671b4a359e322d41814437 |
Hashes for aiohttp-3.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5202ac2d00226f0b2990af9f3301c1ba5eebb673ae0a0acfe499eaea8a1b23ad |
|
MD5 | db7a03b27890b8b3f966595b2da36210 |
|
BLAKE2b-256 | af9a2a29d0da3a864cb7fb64a2d6344f0cc1d234b6ec201a6050e91a5b7576fa |
Hashes for aiohttp-3.5.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af664f067d3c905f4f44d724e65406ed95dd2b4adfcc3d23a9203320ce497950 |
|
MD5 | 884ed052d1e021de2cc2cc63f62952a7 |
|
BLAKE2b-256 | fdb79dd4cff248aa576ab53f300a4a8d7c3cf92ce4852cf125a81126938cea31 |
Hashes for aiohttp-3.5.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f438eab30868997407b73814ba097b80862d6d5bc5f7f2fda384e60df769777b |
|
MD5 | 64d0196b8675bedc46b9bb8197f48129 |
|
BLAKE2b-256 | 94c55b6bc7bb2ff7a21f1f5c16299ae5cd8c655e7e7647a0230a61b63647e04d |
Hashes for aiohttp-3.5.1-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53fc0ad2e8d8f2f0c87bdc3009784de61f5dd9a4259f67301b317525eedc3ed5 |
|
MD5 | 573ecc3af5d1eede3b9cdf41c6e952d1 |
|
BLAKE2b-256 | 50dea59b10d9f51f2cf9341546bfa4fd2df1f386bf0e4908b1554c74053a34ab |
Hashes for aiohttp-3.5.1-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 168f0ecc91200784467479765eb26a80d6d9cf0025b8a9cc5e501413812d32e7 |
|
MD5 | 619a2ba2eca931704313b6eac073fd4d |
|
BLAKE2b-256 | 16e627d8969e0259fcbc5ed096613a71838c69018a16fd5598924aace5353769 |
Hashes for aiohttp-3.5.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b29248c9180fd6a30619b2714c534e3165e523a568296250337fe8952d39b8 |
|
MD5 | 425ac75bf7dbe3a13cc07cdf0b13ec76 |
|
BLAKE2b-256 | 265501ea30200d5d50c5772696eb8c7514b59e2d2db5c9b6833eb084fd3fcb5b |
Hashes for aiohttp-3.5.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f73d6a3e711f26be58bfa13a65a425638fa9d3f4a081eebff0eb70e42fee40a8 |
|
MD5 | 31b6b50ae4970b74b3bd6546beeca663 |
|
BLAKE2b-256 | 8773ff8aecd740250612a0959ec39e67d1977fb54504346b0adaa67edc468005 |
Hashes for aiohttp-3.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bbaec0b171b1ea77d34bc7c49db71a15e511ef34c45065fd2c7fad8daf1483f |
|
MD5 | 2c9eca95bfe8be3275c9ae6960a898a8 |
|
BLAKE2b-256 | b21b77c21d6bc5ce567e12a7fd6a79cca109188baafaa625238cc22bfaffda73 |
Hashes for aiohttp-3.5.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9b47b2ee669b2f01824e0f3b364a8cdfab8d40df1b5987c7c2103d3e13ec9e9 |
|
MD5 | b285806006994cb105da03d6c4c4901e |
|
BLAKE2b-256 | ec0a7a933efff6a82186ae2b1d9d156acc088f1848a5ce36752e48c9823070c0 |
Hashes for aiohttp-3.5.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb96d5e0a82f67a04cde32f970ca837fbcf7ef44124170bc5e34f26c0ed92f7d |
|
MD5 | df5591e01e5506a999a2c35926f8fc80 |
|
BLAKE2b-256 | d0f6d60a81640378a9227f74ba2d6049b703b0503250b01ab64ccb046eaf5b88 |
Hashes for aiohttp-3.5.1-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310c95f1da5f92e937b136e55c2013e4bccd1b53bc88780256ba8ed75699dbdb |
|
MD5 | a4d7fafb7f5fc942c35cfb835e93fe42 |
|
BLAKE2b-256 | 0da48f938d1fe5ac4897968c8fd0903f54713d944ac36e2ffe76d5444424d0ec |
Hashes for aiohttp-3.5.1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5691c630435fd6bd09a789de9ffd5a61b812445dfd515525c738a97d4f9b550a |
|
MD5 | d663c71f01eae1cba2055d6c8f88bbcf |
|
BLAKE2b-256 | 01874a48135642149f54ad9dc842993cb2eef95b927d7dcb16e5626c5e0e1981 |
Hashes for aiohttp-3.5.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9def7acd7c84ca86d0c3247e83180782c423d0e8a68254718fcc69e521570da |
|
MD5 | 6de6044b39e735d0a91c247988d881c5 |
|
BLAKE2b-256 | 9595d7ee3e153f798f780dd9d57299b44e0b22a884c8b2c3dcaab59c13d75e32 |
Hashes for aiohttp-3.5.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd07976a2f2615d4f2ed3654b24e53fe837708602c00934ce1e963690c91c933 |
|
MD5 | 18c9706eddfd2acc7b307aa91e38e532 |
|
BLAKE2b-256 | 4db72470471ea8b034a03f19b0c428c49ab4aa8fa1145c0b7d34d52969edae2c |
Hashes for aiohttp-3.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3011371a48fdef061a8669b6636306b33cf2bf621e1960513c6ce70449f7cd3d |
|
MD5 | 0e38c456382100ac5da1352b73ddba88 |
|
BLAKE2b-256 | d0b3c2ddc48ded429a07959e3f224920b9c24342a1ccdf5c64bfa4a4e793c62b |
Hashes for aiohttp-3.5.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c642901f6c53b965785e57a597229dd87910991b3e2d8aecf552da7d48cfe170 |
|
MD5 | 7fd0e23e0bb402ef80f6302bd6e73fd2 |
|
BLAKE2b-256 | 1b0f0d31c51c30f3f459c57a1e9db46de0bf54f0cca4886a1a9f88c2ce030452 |
Hashes for aiohttp-3.5.1-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6739494376c90806cbb88e7ea2c9e2c35949e6c7089507d19e8f489170a26156 |
|
MD5 | 5279596b356a04985f5fdfa7f080d5c2 |
|
BLAKE2b-256 | a90af82c961676dd45640b88645047522f587ffa29c66cffe3004bb18c267fc4 |
Hashes for aiohttp-3.5.1-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55355947c4fe4b37d2a51b8f1d3f36f7fca541cf012031225be836d1f743c011 |
|
MD5 | fce1f2f04449829bf8891461a20885f3 |
|
BLAKE2b-256 | 430365cae015c80500a4797f318122fc7034ad5c7db878622e9c4edf48f542f6 |
Hashes for aiohttp-3.5.1-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 359baeea2ca640e0dde31a03c3bf3d3008bcbd136c6b1768b58a3499a46a6cc2 |
|
MD5 | cd6f777984c72cbdbe2d3ee9f9cd21b2 |
|
BLAKE2b-256 | 6a2ca30ca52d35afe353d9a7ff3a715492ea83898dc3dfaf179d0d019f10d6c5 |