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.4 (2018-09-05)
Fix installation from sources when compiling toolkit is not available (#3241)
3.4.3 (2018-09-04)
Add app.pre_frozen state to properly handle startup signals in sub-applications. (#3237)
3.4.2 (2018-09-01)
Fix iter_chunks type annotation (#3230)
3.4.1 (2018-08-28)
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.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 589f2ec8a101a0f340453ee6945bdfea8e1cd84c8d88e5be08716c34c0799d95 |
|
MD5 | 91cff9becd351c837e0292102e71014a |
|
BLAKE2b-256 | 8d097127ad0b98322b375587bf93a8ef9764959ea4634d77598b50ff3089b014 |
Hashes for aiohttp-3.4.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b24e7845ae8de3e388ef4bcfcf7f96b05f52c8e633b33cf8003a6b1d726fc7c2 |
|
MD5 | b1ca8207510024338c7b7d04199bee90 |
|
BLAKE2b-256 | 7a584476d96f35cc18a5133330f06c9ff3bc44fa64a9b6d15d2716efa6043b80 |
Hashes for aiohttp-3.4.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab3d769413b322d6092f169f316f7b21cd261a7589f7e31db779d5731b0480d8 |
|
MD5 | 421620118e11f3be1769483a0c17510f |
|
BLAKE2b-256 | 97299d1912f2746d171fc2fc0042a9edd117d386d53382a3aa12f7853466d52e |
Hashes for aiohttp-3.4.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b066d3dec5d0f5aee6e34e5765095dc3d6d78ef9839640141a2b20816a0642bd |
|
MD5 | 984bd9adde629efe7318db59722bb4de |
|
BLAKE2b-256 | dca772b55cd45702805e47563a36348854ea15be70134f64a9f4bc7113ed7654 |
Hashes for aiohttp-3.4.4-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1b442195c2a77d33e4dbee67c9877ccbdd3a1f686f91eb479a9577ed8cc326b |
|
MD5 | c95e729527ef6313eaacac6dc8f34789 |
|
BLAKE2b-256 | 35c59d0f27660ce0b2f921178d8c56493dfb2c5365a42530cccc3531d514b76c |
Hashes for aiohttp-3.4.4-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 275909137f0c92c61ba6bb1af856a522d5546f1de8ea01e4e726321c697754ac |
|
MD5 | 9b4db30fd3214bc20f1994b709e9eea6 |
|
BLAKE2b-256 | 75d4c1761d7325979c1d2b124e4bb917f3f515d5537aa5eed4fbd3837dc5a34a |
Hashes for aiohttp-3.4.4-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0c9c8d4150ae904f308ff27b35446990d2b1dfc944702a21925937e937394c6 |
|
MD5 | d82d4dc1c16f685b5ac6c5381dc6c57d |
|
BLAKE2b-256 | e650e0b8dbb0e061291a2d4eafc6f762aab1399cb883649ac2b55c828a8397cf |
Hashes for aiohttp-3.4.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a968a0bdaaf9abacc260911775611c9a602214a23aeb846f2eb2eeaa350c4dc |
|
MD5 | 58cf2364f908af5928d2cd30096f2f86 |
|
BLAKE2b-256 | 385373cf2f1311b8efac732292aafa7f76df27150c6d3ae879e81ad645f46bac |
Hashes for aiohttp-3.4.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3df52362be39908f9c028a65490fae0475e4898b43a03d8aa29d1e765b45e07 |
|
MD5 | aa123674c132613603429cd7753bf20a |
|
BLAKE2b-256 | a4fde87f63ea0075dcf1f8189eb9c8768dd8e398d37520cec9dcaaf8a3fe0271 |
Hashes for aiohttp-3.4.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b2eb55c66512405103485bd7d285a839d53e7fdc261ab20e5bcc51d7aaff5de |
|
MD5 | 82d055604f7afc2446ea0682ac31890d |
|
BLAKE2b-256 | 52f9c22977fc95346911d8fe507f90c3c4e4f445fdf339b750be6f03f090498d |
Hashes for aiohttp-3.4.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3983611922b561868428ea1e7269e757803713f55b53502423decc509fef1650 |
|
MD5 | 12a814b369e0a95a615e24c4c258daa6 |
|
BLAKE2b-256 | 71e51175274087b6ee5efd5b31ad4f561c4ca2dea1cdfd243cc8d7bea7ab2320 |
Hashes for aiohttp-3.4.4-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1812fc4bc6ac1bde007daa05d2d0f61199324e0cc893b11523e646595047ca08 |
|
MD5 | 0a117fe30f79ed48bb89e36755bfd392 |
|
BLAKE2b-256 | 32001c43f609e5ec2007624de25e323bb0ea302787513e56d13b7089f407a6ad |
Hashes for aiohttp-3.4.4-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aeefbed253f59ea39e70c5848de42ed85cb941165357fc7e87ab5d8f1f9592b |
|
MD5 | 13444c728023aeb328f465bf310b669a |
|
BLAKE2b-256 | d5bd70c2d0db6d01d0fc4a2ef2fc5bd24d9e6efde92ee00bccaf36a0e3071179 |
Hashes for aiohttp-3.4.4-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d80e40db208e29168d3723d1440ecbb06054d349c5ece6a2c5a611490830dd7 |
|
MD5 | bd6941e6f3069f12e5cc966372c78067 |
|
BLAKE2b-256 | 51148f24e8003ba44ac96b0aa646b603f74f9d75ee06546db8fcc8ab7e04cb26 |
Hashes for aiohttp-3.4.4-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87bc95d3d333bb689c8d755b4a9d7095a2356108002149523dfc8e607d5d32a4 |
|
MD5 | 238b9bd186b4be03c612f6e793e412af |
|
BLAKE2b-256 | 5555a26fac3482228a0692eb5134cfee16ce89e78e3467a91bd4621cba649506 |
Hashes for aiohttp-3.4.4-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 789820ddc65e1f5e71516adaca2e9022498fa5a837c79ba9c692a9f8f916c330 |
|
MD5 | 32a5808a968e0465bb2e4bedec68c7bc |
|
BLAKE2b-256 | 09d7ac50b58fde46b1c2b1c8a88937029a2b85e98da1b9b1a14ca8bfcab6bef1 |
Hashes for aiohttp-3.4.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c59a953c3f8524a7c86eaeaef5bf702555be12f5668f6384149fe4bb75c52698 |
|
MD5 | a86ea4664727339eab48aa1c75ec9a08 |
|
BLAKE2b-256 | 70c0380f2bd0a6505998e984efd23b692afe662c4e27603f066c632eed7bf3ee |
Hashes for aiohttp-3.4.4-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf2cc6c2c10d242790412bea7ccf73726a9a44b4c4b073d2699ef3b48971fd95 |
|
MD5 | c561ecc8c35394e2537564da90fdf20c |
|
BLAKE2b-256 | c64446e2263e0c5880988366209d1fd8601c4f4e4b5143c7cf0d4c14461a7e8a |
Hashes for aiohttp-3.4.4-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2214b5c0153f45256d5d52d1e0cafe53f9905ed035a142191727a5fb620c03dd |
|
MD5 | dcaaadc1c7f66dc41b0d2133b2e97b65 |
|
BLAKE2b-256 | 21f82b6c96f13554550bcde0eba167d3f29854aced97a7557351b24de6920b8a |
Hashes for aiohttp-3.4.4-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0419705a36b43c0ac6f15469f9c2a08cad5c939d78bd12a5c23ea167c8253b2b |
|
MD5 | 75399a89379889c0e7a027d13a9155e8 |
|
BLAKE2b-256 | 0bcf73eb631f498b9196816a211da1ea0ecd9bf9469a02c17a0fee7ebf8a243b |
Hashes for aiohttp-3.4.4-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1839db4c2b08a9c8f9788112644f8a8557e8e0ecc77b07091afabb941dc55d0 |
|
MD5 | c59a8dc06c41533720197a19b7b722ab |
|
BLAKE2b-256 | 8f183e7f4a5e2e0e8d4cd412dc12994706255450de006302a173476284803d10 |