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 without the Callback Hell.
Web-server has middlewares and pluggable routing.
Getting started
Client
To retrieve 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
This is simple usage example:
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 it’s 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 by efficiency, AsyncIO community maintains a list of benchmarks on the official wiki: https://github.com/python/asyncio/wiki/Benchmarks
Changelog
3.4.0 (2018-08-25)
Features
Add type hints (#3049)
Add raise_for_status request parameter (#3073)
Add type hints to HTTP client (#3092)
Minor server optimizations (#3095)
Preserve the cause when HTTPException is raised from another exception. (#3096)
Add close_boundary option in MultipartWriter.write method. Support streaming (#3104)
Added a remove_slash option to the normalize_path_middleware factory. (#3173)
The class AbstractRouteDef is importable from aiohttp.web. (#3183)
Bugfixes
Prevent double closing when client connection is released before the last data_received() callback. (#3031)
Make redirect with normalize_path_middleware work when using url encoded paths. (#3051)
Postpone web task creation to connection establishment. (#3052)
Fix sock_read timeout. (#3053)
When using a server-request body as the data= argument of a client request, iterate over the content with readany instead of readline to avoid Line too long errors. (#3054)
fix UrlDispatcher has no attribute add_options, add web.options (#3062)
correct filename in content-disposition with multipart body (#3064)
Many HTTP proxies has buggy keepalive support. Let’s not reuse connection but close it after processing every response. (#3070)
raise 413 “Payload Too Large” rather than raising ValueError in request.post() Add helpful debug message to 413 responses (#3087)
Fix StreamResponse equality, now that they are MutableMapping objects. (#3100)
Fix server request objects comparison (#3116)
Do not hang on 206 Partial Content response with Content-Encoding: gzip (#3123)
Fix timeout precondition checkers (#3145)
Improved Documentation
Add a new FAQ entry that clarifies that you should not reuse response objects in middleware functions. (#3020)
Add FAQ section “Why is creating a ClientSession outside of an event loop dangerous?” (#3072)
Fix link to Rambler (#3115)
Fix TCPSite documentation on the Server Reference page. (#3146)
Fix documentation build configuration file for Windows. (#3147)
Remove no longer existing lingering_timeout parameter of Application.make_handler from documentation. (#3151)
Mention that app.make_handler is deprecated, recommend to use runners API instead. (#3157)
Deprecations and Removals
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.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a2059a0505460828854d218cf090d80db277033b8e6906144ab9bd4677fc82 |
|
MD5 | 20d8cc2bb6a87bec535ece5289c33632 |
|
BLAKE2b-256 | 5db5d6349b718eb10f8622939c1ca776fc5354cc62cd17d06842d0b9ef1a5cbb |
Hashes for aiohttp-3.4.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6132db365def76145084041cede574a0c8ed53aa1a680a3027e41ee8f291bd4 |
|
MD5 | 32a20f558dee528a5b49627b78005726 |
|
BLAKE2b-256 | be99e5ae79499beacc79f24e1a3d44388ef9fe7b1fdd6af6e5e8ceb4f814c0ee |
Hashes for aiohttp-3.4.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6f73c812c1830a06de76ccbea10a4ebb1fd46230a80f280362e84578e4932a2 |
|
MD5 | ceef6cf9032cc180091238c94fe12ee1 |
|
BLAKE2b-256 | de43f097895f05c1a2c122f32519fb55cb60919f769222871ddf6e8282db7beb |
Hashes for aiohttp-3.4.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bc9c87845962f583d6929f837b02b80d2544920be65daf0d0a1306ad1a2089b |
|
MD5 | a27743b618ea9e5b45e40b01d967afb3 |
|
BLAKE2b-256 | f9face62ea4710ccb4b4804e6788637514cf033c75a06c09596d826e8e2b8b36 |
Hashes for aiohttp-3.4.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f88a3428f40c788321cf5b8191f9dd9e002145545fa0cefc023b4b11e17aaa7 |
|
MD5 | 34d2725c69d13ae14bcccd7e6e698e21 |
|
BLAKE2b-256 | 3d4d944a89cdbf4d2a98196affbf6ee04935558472ab8c80ef1916b2c2ac40c9 |
Hashes for aiohttp-3.4.0-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81456c04c54288928da4e7e1893314c8e74d5e9f33163e39aa47c26c5e5c7911 |
|
MD5 | 54b5cafeec70cbc8f7c971dbd2794999 |
|
BLAKE2b-256 | acb80110cfcbaaaf4d578b866f547e3d4f8d164ea489abadf9631b8b493bf9de |
Hashes for aiohttp-3.4.0-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb4224e3a3d7dd2ee18f6c42c1925c3200cd46fe18ec9f293b9bc88644c4878 |
|
MD5 | 15a805f71408f9e8ddef43db119925e0 |
|
BLAKE2b-256 | 3030eb8ef6bf7eb5c9104e44e83e1443a59215583cad5ddeec5fd2abb65e1083 |
Hashes for aiohttp-3.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4f9fc91d617d2e54bda97bc1db9814918691fe799e037ccf973fda434fd2c18 |
|
MD5 | e92ffe333f473d6cef59d396ab8246b8 |
|
BLAKE2b-256 | 1e294c1d96c9bf5187310975559f6c5de383e67bd0ba8d8c94278fa44c32ed7b |
Hashes for aiohttp-3.4.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ddf47c31048efad5a566d82822194bbb680fc1be852915c2949eb69891b5d5a |
|
MD5 | d0870db0d68a4abc63dee1cbc43a89df |
|
BLAKE2b-256 | 06830464c2c4313e259dfb5726b82afb5595d2cf1448341ce93ca9404082194a |
Hashes for aiohttp-3.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4785935328facee0878c29d46f02b12f1e8e8db1cd3d9ec9af666eb163418a64 |
|
MD5 | 1c742621af4a8bcfc3d5cd773541cac1 |
|
BLAKE2b-256 | c6ee7ea531447cdf5ca7687a28928fd8b97124f0791992614b804742375e33ac |
Hashes for aiohttp-3.4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddee38858a9ef52ca33cb5dd1607d07d0fb99e2efe523ecb437b1758c49622a5 |
|
MD5 | fde8555d81b8e644c8c5f8148575d663 |
|
BLAKE2b-256 | b67804b118eddb26f8caa53aa466f8817d5d9eb34c21b6b285c406026fd89806 |
Hashes for aiohttp-3.4.0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48e8d1973ba62a952f19a7916e54a7155f4b14505507432fc0559d8b5b0e5cad |
|
MD5 | 405fc8d17c04ad00956cf85ed3df9e38 |
|
BLAKE2b-256 | f4c5d9a999a085ae623c3ae6826829887af103b3a165cef72a5ccbe4d70e8afc |
Hashes for aiohttp-3.4.0-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 199ea4a9c424904f04a86563a8e9e2759d49e3a0bf789496714253237f16015f |
|
MD5 | 6515a9ecb26a5ad9870f2e36a68982e3 |
|
BLAKE2b-256 | a2a1a59dd805353eb7dcec432ade67308bc3c4c68168a3933c68092d930546b4 |
Hashes for aiohttp-3.4.0-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de703f333381864dce788dbfa1a49ef4551e8f082b607a943b94b239d97965cc |
|
MD5 | 198178ded4be107b77dd4d862abeda27 |
|
BLAKE2b-256 | 74a5808e1fcfaee8662bc62882c33cec3cf20aa76b445e31e19619c680cb161e |
Hashes for aiohttp-3.4.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229975cb8ff6056c8ef581383a653e7110480d52c9f46eaf560113f8d5005510 |
|
MD5 | f26c9c5f0684d522fc22af042ec0e734 |
|
BLAKE2b-256 | c9931d13174331d845ee2c9ff153c04a602d02d6fa822f15e43630e392d5dd7a |
Hashes for aiohttp-3.4.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01bcaf83911c5a88f74629f116540a1b80391e6e496e6fb8708bb2987b60da63 |
|
MD5 | 3337b377d6db5abdbf1e370da14b303a |
|
BLAKE2b-256 | 05445de76481fe1c8c3cf04b971ffc0a631fa8485836e7618c68f53e0cfa1cfd |
Hashes for aiohttp-3.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6880406a0c776fbff63c0d9eb8a2d96d8134b17fafeeea01180b58ab8ff0f6f5 |
|
MD5 | efb132475e5b47b1fea6338c0c7a2156 |
|
BLAKE2b-256 | 24f190c210be1db8c988be5620b5f02e1158bc453e205d0bbadeb9d41acc0478 |
Hashes for aiohttp-3.4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e08cacfede41291c05b4668c3178d303d078417c013bc3d5287b2b0d0e6a3aa7 |
|
MD5 | 41c6ec46d7933c0674cbb0be18ffcd3b |
|
BLAKE2b-256 | 5d6077a3e66630295b53df84ee61f8e2579a391bd07d485943fdb7412ebbe4de |
Hashes for aiohttp-3.4.0-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cd8662ddd7c95e99010e30cc52e20a092939844e8e8a4f37abf1866231f1880 |
|
MD5 | 6c3c5ad8d347f5fb9c2286a9dea22397 |
|
BLAKE2b-256 | 4622c51a8896c8c3c562531b0f6781876d915feab7744513d532e13f3dec07df |
Hashes for aiohttp-3.4.0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a8e447742fc45791ffea0b3ce308f1476a9f4707fb6525a2f23b43d4b26cfb3 |
|
MD5 | d89ed99be20b76ae0de91f8941513e52 |
|
BLAKE2b-256 | 78f9f3ba20b2a868c565f6a1dd3bb2e16de7f12f1533de0c2b8092eb4dbf4d1e |
Hashes for aiohttp-3.4.0-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4c37c7ec1e1157ae4af73fd1d7f201accebf6ed2222120bc660fd002c45cbac |
|
MD5 | fe6f60b4239314f2c9ab675b22d59f8e |
|
BLAKE2b-256 | 385268188f35c3a52c019d81d284965f5d733444077b52c57e2d56a7d2e07ce9 |