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.0b3 (2018-02-09)
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)
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
Hashes for aiohttp-3.0.0b4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4b2bb59c3462239b3112ce5c0845a1410d4ae9ad4befd703fde664a6088ebe |
|
MD5 | b6264be54f449ce43a3c46c7e503402b |
|
BLAKE2b-256 | f93c5874226a5f1971731f0b619001455f4a3bd3f9f78a10ba01da82339f6ac3 |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dfa103542aae8121301fa0fa8c2d6175b0d1abf7fe9494bcb008068ded3c109 |
|
MD5 | 366c745b5e12fe6751ea3a0519557b48 |
|
BLAKE2b-256 | 3fc18723dc5e7b8c45e141dcfe0fec6d5448ec3d75d4337e0ad4a8ea9072fc0a |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cabf53010b11e5160b187c995a29450f34bc874415e555991d38819c6d53591 |
|
MD5 | 2edff8d1eb9e58aa4f54af4daa8b85ac |
|
BLAKE2b-256 | 4516caa257b1914b3c47eba108669c2c6f03ce0c6e0efe87bdcdea211ad6b15c |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea1b2641b87c288103e7c72bf088a704d8854b9c653d69fa914ae33514035bc |
|
MD5 | 36927ba8e42c0efcf1424439ff9ab302 |
|
BLAKE2b-256 | de1fc812d5991c88ac7b443c62b3eb9a986b3406e363ce50642e89a3778e842f |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0cb32edbcd76796bb77c794349f438fa7775394f35a95a1c4d00fe0d128b087 |
|
MD5 | 19a71c4e87db9cef4b8b55c9a740716f |
|
BLAKE2b-256 | faca3cebebcaf19a90ed019dac10560f1e87ed5ef6d4a75bdccaf736a2eec10c |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7e0406a5841d0ec011ceadb57e6f7b8bfdb5b64092d8b655adb6fb54d05125 |
|
MD5 | fac678263a8cb8a443b494000e4b99c9 |
|
BLAKE2b-256 | 09345a062537d4a0dd6dacaa3b6db0299e0b427b1523fc3e117481af712e6bac |
Hashes for aiohttp-3.0.0b4-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a0af29d8855ba866124737d49609f309b001dc4f95e3671d0c51f065da3102b |
|
MD5 | 0706593f2785299521803c8703ab5bc9 |
|
BLAKE2b-256 | 719fd0e9d7c77ea0b494c0bba4cb72d0190d7e13400df54ba71745c24240aa34 |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6729c1c7c1ab5a8867f3db1909f3fe1c600bb35ce7751542c4b963e7c765c773 |
|
MD5 | 48cc7e4170929ac738d5335a054eeb21 |
|
BLAKE2b-256 | 05ed8d875dbc2793783560b21a8aaba0d1c39313f566c9a708e944ab2bd6bcf6 |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9467b9ab0ee5ed390ae2164aa51a1690be12d784b6f53549b4ca0b5943607fe2 |
|
MD5 | 828b923fe3fb931c69a902a42459f40f |
|
BLAKE2b-256 | 13db2b6c3abb7e91978219900a2e4355cbbd71b260c0f05acdc526ccf2d150f5 |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ce68d87989dd33c418aa2fc5f5bc328ab2287928fc68b061361745547e27577 |
|
MD5 | 58f324f80a36591db66149c75894e72d |
|
BLAKE2b-256 | 588144ff07404b2f572e5be7d1060b7161a1b7e47e0cd513f7ee77056312bde7 |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fff53bbd05e797fdfc6ab286107d3bf0e0cdc7e117e6e6706ce209dff84d430 |
|
MD5 | 3665f35b0c8ce2494fc7ac4ce8a20987 |
|
BLAKE2b-256 | ef2156dfc7bc2d6afd039e6ce580b0e10bb88b488a18a1ff2565931ebfa80d5b |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9d1393d436163252ae8e8916b07cccf8cd91e4436356f2815bbff71461f4d66 |
|
MD5 | 9849893c7b251f3c4d321cc53562bc52 |
|
BLAKE2b-256 | a14d387d821905e86c6c1454985e0e135b9a4910f160428344ac9d176b5f917a |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51e6f7f93277734f0deb440273d792abc6cf535f0055ebc42311df387dd62d5f |
|
MD5 | 234e11802369c06973efac4f36345d79 |
|
BLAKE2b-256 | cb7c5204fc95e9797e282575408478a2c536d34b40378026e4d153d337455788 |
Hashes for aiohttp-3.0.0b4-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc3a77748fc27ea400ede17e994418aa99e62bed031c26dffc94996bd9e45c40 |
|
MD5 | dd513d784c606fb87499c8a33f73e37f |
|
BLAKE2b-256 | 375e3241be559a93063833cb18ce5997e77ed32aa1b6eb5ca09ad3fdf4b0943b |