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.
Web-server has middlewares and pluggable routing.
Getting started
Client
To retrieve something from the web:
import aiohttp
import asyncio
import async_timeout
async def fetch(session, url):
async with async_timeout.timeout(10):
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 wshandler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
async for msg in ws:
if msg.type == web.MsgType.text:
await ws.send_str("Hello, {}".format(msg.data))
elif msg.type == web.MsgType.binary:
await ws.send_bytes(msg.data)
elif msg.type == web.MsgType.close:
break
return ws
app = web.Application()
app.router.add_get('/echo', wshandler)
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)
web.run_app(app)
Documentation
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.0.0 (2018-02-12)
Features
Speed up the PayloadWriter.write method for large request bodies. (#2126)
StreamResponse and Response are now MutableMappings. (#2246)
ClientSession publishes a set of signals to track the HTTP request execution. (#2313)
Content-Disposition fast access in ClientResponse (#2455)
Added support to Flask-style decorators with class-based Views. (#2472)
Signal handlers (registered callbacks) should be coroutines. (#2480)
Support async with test_client.ws_connect(...) (#2525)
Introduce site and application runner as underlying API for web.run_app implementation. (#2530)
Only quote multipart boundary when necessary and sanitize input (#2544)
Make the aiohttp.ClientResponse.get_encoding method public with the processing of invalid charset while detecting content encoding. (#2549)
Add optional configurable per message compression for ClientWebSocketResponse and WebSocketResponse. (#2551)
Add hysteresis to StreamReader to prevent flipping between paused and resumed states too often. (#2555)
Support .netrc by trust_env (#2581)
Avoid to create a new resource when adding a route with the same name and path of the last added resource (#2586)
MultipartWriter.boundary is str now. (#2589)
Allow a custom port to be used by TestServer (and associated pytest fixtures) (#2613)
Add param access_log_class to web.run_app function (#2615)
Add ssl parameter to client API (#2626)
Fixes performance issue introduced by #2577. When there are no middlewares installed by the user, no additional and useless code is executed. (#2629)
Rename PayloadWriter to StreamWriter (#2654)
New options reuse_port, reuse_address are added to run_app and TCPSite. (#2679)
Use custom classes to pass client signals parameters (#2686)
Use attrs library for data classes, replace namedtuple. (#2690)
Pytest fixtures renaming (#2578)
Bugfixes
Correctly process upgrade request from server to HTTP2. aiohttp does not support HTTP2 yet, the protocol is not upgraded but response is handled correctly. (#2277)
Fix ClientConnectorSSLError and ClientProxyConnectionError for proxy connector (#2408)
Fix connector convert OSError to ClientConnectorError (#2423)
Fix connection attempts for multiple dns hosts (#2424)
Fix writing to closed transport by raising asyncio.CancelledError (#2499)
Fix warning in ClientSession.__del__ by stopping to try to close it. (#2523)
Fixed race-condition for iterating addresses from the DNSCache. (#2620)
Fix default value of access_log_format argument in web.run_app (#2649)
Freeze sub-application on adding to parent app (#2656)
Do percent encoding for .url_for() parameters (#2668)
Correctly process request start time and multiple request/response headers in access log extra (#2641)
Improved Documentation
Improve tutorial docs, using literalinclude to link to the actual files. (#2396)
Small improvement docs: better example for file uploads. (#2401)
Rename from_env to trust_env in client reference. (#2451)
Fixed mistype in Proxy Support section where trust_env parameter was used in session.get(“http://python.org”, trust_env=True) method instead of aiohttp.ClientSession constructor as follows: aiohttp.ClientSession(trust_env=True). (#2688)
Fix issue with unittest example not compiling in testing docs. (#2717)
Deprecations and Removals
Simplify HTTP pipelining implementation (#2109)
Drop StreamReaderPayload and DataQueuePayload. (#2257)
Drop md5 and sha1 finger-prints (#2267)
Drop WSMessage.tp (#2321)
Drop Python 3.4 and Python 3.5.0, 3.5.1, 3.5.2. Minimal supported Python versions are 3.5.3 and 3.6.0. yield from is gone, use async/await syntax. (#2343)
Drop aiohttp.Timeout and use async_timeout.timeout instead. (#2348)
Drop resolve param from TCPConnector. (#2377)
Add DeprecationWarning for returning HTTPException (#2415)
send_str(), send_bytes(), send_json(), ping() and pong() are genuine async functions now. (#2475)
Drop undocumented app.on_pre_signal and app.on_post_signal. Signal handlers should be coroutines, support for regular functions is dropped. (#2480)
StreamResponse.drain() is not a part of public API anymore, just use await StreamResponse.write(). StreamResponse.write is converted to async function. (#2483)
Drop deprecated slow_request_timeout param and **kwargs` from RequestHandler. (#2500)
Drop deprecated resource.url(). (#2501)
Remove %u and %l format specifiers from access log format. (#2506)
Drop deprecated request.GET property. (#2547)
Simplify stream classes: drop ChunksQueue and FlowControlChunksQueue, merge FlowControlStreamReader functionality into StreamReader, drop FlowControlStreamReader name. (#2555)
Do not create a new resource on router.add_get(…, allow_head=True) (#2585)
Drop access to TCP tuning options from PayloadWriter and Response classes (#2604)
Drop deprecated encoding parameter from client API (#2606)
Deprecate verify_ssl, ssl_context and fingerprint parameters in client API (#2626)
Get rid of the legacy class StreamWriter. (#2651)
Forbid non-strings in resource.url_for() parameters. (#2668)
Deprecate inheritance from ClientSession and web.Application and custom user attributes for ClientSession, web.Request and web.Application (#2691)
Drop resp = await aiohttp.request(…) syntax for sake of async with aiohttp.request(…) as resp:. (#2540)
Forbid synchronous context managers for ClientSession and test server/client. (#2362)
Misc
#2552
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
File details
Details for the file aiohttp-3.0.0.tar.gz
.
File metadata
- Download URL: aiohttp-3.0.0.tar.gz
- Upload date:
- Size: 737.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f986bd51fc80b42b880d5579f47ef4f5ec8ef37cf7a799b6a8b61fab1b88d2cd |
|
MD5 | 603b66b819b0c0d51feee310193cb4cf |
|
BLAKE2b-256 | c64464f7669c65a35b7f339e28ce2419fec4bd7791d2ae5ac9df76f1341fa959 |
File details
Details for the file aiohttp-3.0.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 359.7 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41f5b1ce439db446f18d0f882ecbb65c19bd03edfa53ee92e21e87b788167ef6 |
|
MD5 | 2feba0567607d273a417e8305477e096 |
|
BLAKE2b-256 | 78b4fc92b2ea275e594753fca0021c1593cc75fcf866e57abe1b0936f3bd0964 |
File details
Details for the file aiohttp-3.0.0-cp36-cp36m-win32.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp36-cp36m-win32.whl
- Upload date:
- Size: 348.4 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f506a35e49cac5bbcc9f10fe4abe3c4ac5294790f4aba117d3c16b573ecfb56 |
|
MD5 | 43b72a642120d8fc1f492074f45a148a |
|
BLAKE2b-256 | 1cf587d501a8e0a5717b9812353b17ed193aefcd5580f8824d92130efefa23de |
File details
Details for the file aiohttp-3.0.0-cp36-cp36m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp36-cp36m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 363.8 kB
- Tags: CPython 3.6m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b510eae1a8cb70064f7b274793cd77874634a60158a1588a4a970dfe7dfdaf2e |
|
MD5 | c1d1650b5e90a39b07257a86cc9d5742 |
|
BLAKE2b-256 | f7a835ff262e491daf2a7f81f56d400d01d95b5792515867e6694e12d1998856 |
File details
Details for the file aiohttp-3.0.0-cp36-cp36m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp36-cp36m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 371.9 kB
- Tags: CPython 3.6m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cbf6380acd7b851d6abbeb722492f043eba11dc041520b17b40bd18dc358185 |
|
MD5 | e2804aa53c2c839ee7d6fc9c0f65e44c |
|
BLAKE2b-256 | e73a1a8055a1ca0fa8ba4ab8797ff4d2003310ee908cdabfcc122a75466b16f1 |
File details
Details for the file aiohttp-3.0.0-cp36-cp36m-macosx_10_10_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp36-cp36m-macosx_10_10_x86_64.whl
- Upload date:
- Size: 373.0 kB
- Tags: CPython 3.6m, macOS 10.10+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c217970cba1904211c387cc6ea07c3eff31287f2ff26c27b418dc0d0320f9da1 |
|
MD5 | 4dc8ff71def8248daab44fd89457b2a4 |
|
BLAKE2b-256 | 4762a585758ab12466a40ef70be232336dfad17dafdfe6a7e3f67cfeededd528 |
File details
Details for the file aiohttp-3.0.0-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 357.8 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ae6e6392a85a3dde72e158ae375f01d58410c5bfdbe0547cafc93e1b7318ff |
|
MD5 | dd09c3e9ec10a857653933f44041594f |
|
BLAKE2b-256 | 2b33c09ba026ff81357f9f7ccd5c53972383ea47e53328a916916818efcca0e7 |
File details
Details for the file aiohttp-3.0.0-cp35-cp35m-win32.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp35-cp35m-win32.whl
- Upload date:
- Size: 346.8 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7241ef86003b5e69d4916361f083a77f682cd6070b328358bbb2bf3a90ab5347 |
|
MD5 | 32dd0d4c16e5de3969731c5a02e6b548 |
|
BLAKE2b-256 | dd2dd30646e87ce9cdbc9f56de08b336c03d32256b2f9700df39d7f98fec0ea1 |
File details
Details for the file aiohttp-3.0.0-cp35-cp35m-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp35-cp35m-macosx_10_12_x86_64.whl
- Upload date:
- Size: 362.5 kB
- Tags: CPython 3.5m, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acef6d4f06c036f4633440abae07064a4fd46de09b7b8c385697036ba3c706a3 |
|
MD5 | 290de630acea183b07ece5f3e72a99bb |
|
BLAKE2b-256 | 17f7eae6439368fcfbcc9f07d66d131e460fde6a24d44eeaee1337669082ec8c |
File details
Details for the file aiohttp-3.0.0-cp35-cp35m-macosx_10_11_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp35-cp35m-macosx_10_11_x86_64.whl
- Upload date:
- Size: 369.5 kB
- Tags: CPython 3.5m, macOS 10.11+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72e8a0f26305628d54d7984489261d7ff52f3bd337d43ff2f11b011361265d55 |
|
MD5 | f6c394c94d0d7f16e0be6c00862677e0 |
|
BLAKE2b-256 | f0f8dbf1e8bbc96da4567ccd8376835b637fa42d2878815f14ae5d61865388b3 |
File details
Details for the file aiohttp-3.0.0-cp35-cp35m-macosx_10_10_x86_64.whl
.
File metadata
- Download URL: aiohttp-3.0.0-cp35-cp35m-macosx_10_10_x86_64.whl
- Upload date:
- Size: 370.5 kB
- Tags: CPython 3.5m, macOS 10.10+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 990767e6ce98d58b3ff748975592e8c64d26748b7a8791bb194d3e28a3532e1a |
|
MD5 | 1e37eb514ddc125f01a6c93d4ed12363 |
|
BLAKE2b-256 | e7537ba8e07eccbf1a83bea96ca28b5f1240a6741f702678e9830c2cb1635b7f |