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.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.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61c3426e7818a56d0594b45091c910e318ba6ba96602ce69cd1cbdf8a779f1ae |
|
MD5 | 18a66aca776b92ecd73a6f81c2341354 |
|
BLAKE2b-256 | ecb601c260bec3ce4506470c84dbcd55017cd32a18962ef3b071fe69038a4296 |
Hashes for aiohttp-3.4.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 014e749e5acef211462c7932e29c34c6f5d03640d4a59404ac3cd6c18e7c8e8d |
|
MD5 | 772f5dbbde2425e0899000a56eb80b3b |
|
BLAKE2b-256 | 540c2a32410fa61b8e66b0f394b44c671d4911bd633a476c993cef4298bb8d62 |
Hashes for aiohttp-3.4.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138f5e5036773001241f3ed206fe4fe326e91d6422ff1e727d2ad7b2f7b46b91 |
|
MD5 | 28c4f5c60c3dd048c8a734db4776852a |
|
BLAKE2b-256 | 09c8bcb0a8b2b0174e0fc036c687e0d1a6a52a886bc73a159d5e47755e2d8dc6 |
Hashes for aiohttp-3.4.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 543eba8b65873f77fc22b91c6356e684bf0ed52a4407181d54ed97405d720589 |
|
MD5 | 880d1adaea277c6dff95cc19fdab1109 |
|
BLAKE2b-256 | 812954c3d135dd8fb894fb8533fee9fe85b75295f76015330b2e6efeb2321489 |
Hashes for aiohttp-3.4.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03f490c5e823f0843433e259bad8e15849df7d9cf6598a0d8659aa95d9bd3db4 |
|
MD5 | 119075dde0c91dcf33f7901f328bd73f |
|
BLAKE2b-256 | af3626b96058197a8b73984d5816416754874da93009df699cbd5048f0685683 |
Hashes for aiohttp-3.4.1-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fdd42cd0f39e2eda28745c329bdc4a7b2e3d17be67cba4097da8d7dd128f7ed |
|
MD5 | c3cf418130beb286c485bd91ee2249bd |
|
BLAKE2b-256 | 3a32cc4ec831b79350a4fae961a17f4d739d02e87a47e079caaac15a583369a0 |
Hashes for aiohttp-3.4.1-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4a44deaa7196fec6f9ed3ab0e46fd0e4bb94690be972fd4252c307fa7411a35 |
|
MD5 | f9b46f9b58b92871ff850120a9b69d41 |
|
BLAKE2b-256 | 31d664e612fae323514dac6ddab6092e12d0a4ee674c1b771426a33c31df9926 |
Hashes for aiohttp-3.4.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf33b25a8eafc71dcc04a255c0fd14fcf90dac28d939edefc8047579de8917ef |
|
MD5 | fc850384504d589768578fe416f4404e |
|
BLAKE2b-256 | 6b5b23e55a7681dc8801b3b6ded1d43da470d293cc2047f2f19d350c65fe8600 |
Hashes for aiohttp-3.4.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9610a30b14fdc3379dff42c61098e0234c44261e98a1467c0cc1d9c7c802242 |
|
MD5 | 9b7f0130ca9755013eafb5dca4264520 |
|
BLAKE2b-256 | 4a34a13fcde2af6f6bd93475963c784fd9f832ce5af88bfc94a794cdb09568b3 |
Hashes for aiohttp-3.4.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1514c83e7c7f482ce3876b13ccce2c8a7d2400ff992bebd6c6c049660ababb43 |
|
MD5 | 0a21380042dd3dfc75ebf8886a5f058d |
|
BLAKE2b-256 | 230cc0d4348c6fab8e5161cbb91c2901d9ea6136b456fdeff70c117ec613d92a |
Hashes for aiohttp-3.4.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6739c7b1c9ad41bed93c76ccdbf4f0c2e01efc1d5c01584f5716803a1072f5 |
|
MD5 | 115e52a25a3e78909a949876f17f293a |
|
BLAKE2b-256 | 8cca9aa62307650416f38fd39114f439485e6a9d7f5eaf081a83a75128750ed6 |
Hashes for aiohttp-3.4.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 483261bb4c8c04b6d7054178e61852ee23dac65dd9109ded50b8c01642cb28e7 |
|
MD5 | 537955feccc1a78e05912019bbbcf875 |
|
BLAKE2b-256 | 07fca38911401e5617c16e3ab50be80b85d8cc0cc67a138f386eb45d62cab4d7 |
Hashes for aiohttp-3.4.1-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca150aed4e6ad9b35ac51b01b89d0ad2f4d3704226dad809f0d87e7b9cf76a5 |
|
MD5 | e64463285e8ee47777829f89cac2cf08 |
|
BLAKE2b-256 | c68bf0651ddd9d93c1ca799e87f65580072cd06380c557562e8d933e450c06d4 |
Hashes for aiohttp-3.4.1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b88f03a87b4bdce7a5d8dceddf0e4b49909adb9e02c7cf5a124ff28fb0cf722 |
|
MD5 | 9931f753758597460b81fc8b190228bc |
|
BLAKE2b-256 | aff54992cb4bac8bbf73dd40d1682e6a7e1bbc12fc68a6bdaa7b029d0b3fd13c |
Hashes for aiohttp-3.4.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa611b9ba83b6434b3bad0da69f493d4db08dda5d260a3458459c3a1b4b6e8c2 |
|
MD5 | 68cf60a61c27cfd37d784d541a886ccf |
|
BLAKE2b-256 | 2da66fb2d83de0771ee7fc67d800bbf24703d9b83f3e56a5ca2de1ebca1dc62b |
Hashes for aiohttp-3.4.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8204969ce2de0786247d525223effaa5fe2cb6bdd5baa965809e119d7cbb6c8 |
|
MD5 | dbddb847f69cf80143dfa01b835889f4 |
|
BLAKE2b-256 | a05d2663d5dbbad6bf9fa8dacfb4b61051725bb4a2d44c40149a0cc4dd3444ac |
Hashes for aiohttp-3.4.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8573dd18032b2e99654e431ad2e863d1ea3cc9caa674958571f48820bd800c |
|
MD5 | c15190c84dcf2abc7c2602b4eba09a04 |
|
BLAKE2b-256 | fc0d786a5b32e551ac72e91256dab3c7747514d0a5a87554d5857f2e681b68da |
Hashes for aiohttp-3.4.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 870b73824ea62fea14e135ca68f5d291eafe800bce552cf770f0152a5b37bd98 |
|
MD5 | 932bffb3886c62fd8fc27dcb62818da6 |
|
BLAKE2b-256 | 3c3a9179c624af544f19b545ce5d79f9663b53b0471fab36d9413e810bcfcf98 |
Hashes for aiohttp-3.4.1-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f16f517e18753bf3167deca7ac5fbedb5484a72cb4b4f071ea2f79029c0da867 |
|
MD5 | e8b8c5c6cff4883594acc863ebee1a3a |
|
BLAKE2b-256 | eba932cfa5d293ac816c32f1c4cdab06ca069909b8081051b781570173b510f8 |
Hashes for aiohttp-3.4.1-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d42e8a343879ac9993b0e51a64a4e02fc6d3fb1c298aa9a8515f81c98658ae5 |
|
MD5 | e3c3f41ece0940d79afded240717d3b2 |
|
BLAKE2b-256 | 47394d8db83d438d4861f0fe4542b115a59af43ab8da25bc08cc47909a09f89c |
Hashes for aiohttp-3.4.1-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e076731b712298d2e1050465f549737dde924ea7cd1b7a86ccc2fe4726436c92 |
|
MD5 | ea806fbd2f1f32a913db3e8a374b8e35 |
|
BLAKE2b-256 | 0c23db91dcad4beaec3805d1c451091ce7888b0e12f429873bd80241dd19f799 |