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.2 (2018-09-01)
Fix iter_chunks type annotation wrong (#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.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97e3f198da96d5833200d814812ee03dbf1b2ba5a85ea4751e5da1360fe9a7cd |
|
MD5 | ebb01f405203eb079e8a98b1df2d6f97 |
|
BLAKE2b-256 | a00c5a7f32696f8e37e9909c234e9491f7c9e98547220c2f951d00cda6027575 |
Hashes for aiohttp-3.4.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8de492b8c8d5acb60c30cf2275f36d0fb21d71e0a462bbed61f099a98264c635 |
|
MD5 | fcfecd343467714244dff4ad185aa31e |
|
BLAKE2b-256 | 93958dc7a15a958a770ad4aa951c0b59e08e901937904dbc7a38e2982c076b1e |
Hashes for aiohttp-3.4.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 540c02599fb3f913121fe5767506f2ce36d0ff9bda6f0cf3f4fe978d68f9a8f8 |
|
MD5 | efd3c8d8ddc2cf52dc9122a4368ef516 |
|
BLAKE2b-256 | 4df5070e7fe9151077c0cc21951360734cfbb12cb41693988d234fbea4e32d06 |
Hashes for aiohttp-3.4.2-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 613bc9d4513df36f76faf19f1010430c0cea45cc9db4af0df96d237e5fd42800 |
|
MD5 | e24482451da8c158fbde9815b0d32993 |
|
BLAKE2b-256 | a58e9ff528320cda850721efe14f1cf8155983d264f106d2d7e0af40d1dabd46 |
Hashes for aiohttp-3.4.2-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2421ca89978a037f0ed1cc77fc5678561cc416c2047aad2e1dd8259bce1192b3 |
|
MD5 | a83e3ed78e0870073cf875d2e27156b2 |
|
BLAKE2b-256 | e0d5edf92b3c88e0db738816a770f44ba21b90f972cd76481b2d3dbf4dfc186d |
Hashes for aiohttp-3.4.2-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f54001b0504f808a88aa786749af6c52e6ca00b5b7350fbe84d6274e537e7485 |
|
MD5 | d9e47f3d56fed8bb109c266ac7c2253e |
|
BLAKE2b-256 | 12ede64e2ead5da080d188b8f7e45ec731d12a8dca3cb97fc470a9fb7a19fd41 |
Hashes for aiohttp-3.4.2-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26e996559c8f723c19a638f5c315716c258d9e2e2e5fa31ef76cc62a4d676c99 |
|
MD5 | 9ceccdcc880d7d056f7cb289b22d2396 |
|
BLAKE2b-256 | 373ba01a07c2586cf722b4ee710cb59aeacf0f52caf8aed12bd552571363d486 |
Hashes for aiohttp-3.4.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17b105bfeefe7c1d122d5948f7fe20adb5eae83cbbf6c7b5a787176c883fc0ea |
|
MD5 | 5ec34b640bb57b70e21d19cd5de54931 |
|
BLAKE2b-256 | 5700620160b975b7a06c34a62d78223be70a6cb743cafe4fef15573c8e1e3d22 |
Hashes for aiohttp-3.4.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e452185e23f4a30208b057932b4ca5d528f4c4fdcc58028809e9f763fa52f36 |
|
MD5 | c500c6064408ae28295917289ce70a2b |
|
BLAKE2b-256 | 021088b615e7e2a2b699ed964b5cbb4369482489bbcefb4bec6f69de1e71ecfd |
Hashes for aiohttp-3.4.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07f025ea9fbc904f46cde7ba1e16c4085687cf8b6cabb6b815a8b5962605a743 |
|
MD5 | d50953e5f2cce177e8110bc585b2b67c |
|
BLAKE2b-256 | 6ee43c3a2a8dd28b8eb1c7313b234f7e5c4618cff5b42bb6db4cf6e5e5931268 |
Hashes for aiohttp-3.4.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21ec794275615fcf9b0715266ce6709eb40045560c75431a1439fb1ed0fb0241 |
|
MD5 | 04e54db4332f6369cda5edc1970c31dd |
|
BLAKE2b-256 | c1b86086b26c4df8227e5585b581f6b02a1b74df4527a6952bfb1978bcdcb3bd |
Hashes for aiohttp-3.4.2-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4cba665391bd31b3807277de3c73fd80cc17a0d280f11485fe9e58e228b6c5c |
|
MD5 | 098403299331d62648e196106b50aa5f |
|
BLAKE2b-256 | 0879a8da4ac7a9f5f7ffa605c18107c2dd4184e15c9a722030263fc902f8d9b2 |
Hashes for aiohttp-3.4.2-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fae84267df30e27b072da1a09835616e6872f7cc82cfc3eb260a52e9b6de340 |
|
MD5 | e887a308701854b93443116cf4d6d292 |
|
BLAKE2b-256 | d4270ae48843ad10ebc53c461433063d30c98f29dac6b4a668f8d65e16568234 |
Hashes for aiohttp-3.4.2-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d50047664a199eab5e596e4a18f09781fcdc1ad43b3203c5585dc65cf4c57592 |
|
MD5 | 991c79bb0bcdfe2c49638346a1f6dbd9 |
|
BLAKE2b-256 | 342fdff5fbae7aecaebcf987242a3ff0293d114aec515a72aac9562f587f7359 |
Hashes for aiohttp-3.4.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e59bcc461b6523b8c9105032f7664bd918f9c3be5f96462b814e6bf1c915c32e |
|
MD5 | 9322a29e3b40e9108cbf0368df87cf16 |
|
BLAKE2b-256 | b520cb1396877221b1eddccdbb381180e979692ad5d6a89999dcd9c5b4c541e5 |
Hashes for aiohttp-3.4.2-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f9ba7f4767a5e75aeb68f0441ddd3856f7129cbd0d188420e770d17e3b100a |
|
MD5 | 0c693e5edb28d12cac907d192083cb09 |
|
BLAKE2b-256 | 62b0fdca2aab68e55b89ce43709cfcb7941543cea3701ef3760e0714f39b3adc |
Hashes for aiohttp-3.4.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f35399afb09427523f97d6a6a000fb6562e9ed2d3560c2fdfb9d874beb46ecf |
|
MD5 | e42566db6811e787f50062f0b6119f35 |
|
BLAKE2b-256 | 96bbc6cf03e64578002a8b5224f3ffe230bea0c17be3969479fe7d214ccefef5 |
Hashes for aiohttp-3.4.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1958340035221643c0c27326fecf24e49265ba21c709e42163bc8b16cb2e0c7 |
|
MD5 | 03b505ae5444918c5285017a707a128e |
|
BLAKE2b-256 | 9c623e379e43fc5d23f880d7fde089cec578af41f45f25d4c7fb561ed6153ad6 |
Hashes for aiohttp-3.4.2-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d65a3942bce7717a1dc730927f583308e100a94375ed81fa06bcb02127e4c3ae |
|
MD5 | c15acfc62ed8e8a098c64ca7b4a97dbd |
|
BLAKE2b-256 | 3a2e5ec8c0f677731996526f496ab460f0214cecc19e16c9d866a1b1bc2a7d57 |
Hashes for aiohttp-3.4.2-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04087c38e45da5aa1a8b2345441b821bf270436f7954eba1a7e36cc55fed81f8 |
|
MD5 | b7d02aeb8153dd57731ee40fb43f478e |
|
BLAKE2b-256 | f28dda1b12ad7ab29927ef1a2c3cc174e47327d8d966401900da698c19b24682 |
Hashes for aiohttp-3.4.2-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2af48882b6d351ffe17423d19a1a51f0850ead5b7e7237b663a4e880e8d5b7 |
|
MD5 | 2fbf06557e91772007a2563c65a05b33 |
|
BLAKE2b-256 | 05b18ab7d367801cd51229eaaed5c4ec3c1ba7fbaa87e3b939575c2711f6b1fd |