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 and avoids Callback Hell.
Provides Web-server with middlewares and pluggable routing.
Getting started
Client
To get 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
An example using a simple server:
# examples/server_simple.py
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 its 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 efficiency, the AsyncIO community maintains a list of benchmarks on the official wiki: https://github.com/python/asyncio/wiki/Benchmarks
Changelog
3.5.0b1 (2018-12-20)
Features
The library type annotations are checked in strict mode now.
Add support for setting cookies for individual request (#2387)
Application.add_domain implementation (#2809)
The default app in the request returned by test_utils.make_mocked_request can now have objects assigned to it and retrieved using the [] operator. (#3174)
Make request.url accessible when transport is closed. (#3177)
Add zlib_executor_size argument to Response constructor to allow compression to run in a background executor to avoid blocking the main thread and potentially triggering health check failures. (#3205)
Enable users to set ClientTimeout in aiohttp.request (#3213)
Don’t raise a warning if NETRC environment variable is not set and ~/.netrc file doesn’t exist. (#3267)
Add default logging handler to web.run_app
If the Application.debug flag is set and the default logger aiohttp.access is used, access logs will now be output using a stderr StreamHandler if no handlers are attached. Furthermore, if the default logger has no log level set, the log level will be set to DEBUG. (#3324)
Add method argument to session.ws_connect().
Sometimes server API requires a different HTTP method for WebSocket connection establishment.
For example, Docker exec needs POST. (#3378)
Create a task per request handling. (#3406)
Bugfixes
Enable passing access_log_class via handler_args (#3158)
Return empty bytes with end-of-chunk marker in empty stream reader. (#3186)
Accept CIMultiDictProxy instances for headers argument in web.Response constructor. (#3207)
Don’t uppercase HTTP method in parser (#3233)
Make method match regexp RFC-7230 compliant (#3235)
Add app.pre_frozen state to properly handle startup signals in sub-applications. (#3237)
Enhanced parsing and validation of helpers.BasicAuth.decode. (#3239)
Change imports from collections module in preparation for 3.8. (#3258)
Ensure Host header is added first to ClientRequest to better replicate browser (#3265)
Fix forward compatibility with Python 3.8: importing ABCs directly from the collections module will not be supported anymore. (#3273)
Keep the query string by normalize_path_middleware. (#3278)
Fix missing parameter raise_for_status for aiohttp.request() (#3290)
Bracket IPv6 addresses in the HOST header (#3304)
Fix default message for server ping and pong frames. (#3308)
Fix tests/test_connector.py typo and tests/autobahn/server.py duplicate loop def. (#3337)
Fix false-negative indicator end_of_HTTP_chunk in StreamReader.readchunk function (#3361)
Release HTTP response before raising status exception (#3364)
Fix task cancellation when sendfile() syscall is used by static file handling. (#3383)
Fix stack trace for asyncio.TimeoutError which was not logged, when it is caught in the handler. (#3414)
Improved Documentation
Deprecations and Removals
Deprecate modification of session.requote_redirect_url (#2278)
Deprecate stream.unread_data() (#3260)
Deprecated use of boolean in resp.enable_compression() (#3318)
Encourage creation of aiohttp public objects inside a coroutine (#3331)
Drop dead Connection.detach() and Connection.writer. Both methods were broken for more than 2 years. (#3358)
Deprecate app.loop, request.loop, client.loop and connector.loop properties. (#3374)
Deprecate explicit debug argument. Use asyncio debug mode instead. (#3381)
Deprecate body parameter in HTTPException (and derived classes) constructor. (#3385)
Deprecate bare connector close, use async with connector: and await connector.close() instead. (#3417)
Deprecate obsolete read_timeout and conn_timeout in ClientSession constructor. (#3438)
Misc
#3341, #3351
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.5.0b2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cac62b510fc6f697b12ddeebec7bef7bfb98f40806a2b367556b3e3acf5c6cb6 |
|
MD5 | 78d76bd0aace8ae1c8679a9db4a15aee |
|
BLAKE2b-256 | afc8869285bc4efa8722725851b27a1597ca1a325c571f709fdfbde57d0145d9 |
Hashes for aiohttp-3.5.0b2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f82302c93f375497faaddd39ece633619435cb4ba4c6d562d0c9b4fd2c9a22c |
|
MD5 | f84c486929142f3c9028eeb8b34c10ed |
|
BLAKE2b-256 | c32054df9426d3d72553c9a9f4de4520407d8550dca52cf5073255417221a00b |
Hashes for aiohttp-3.5.0b2-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e2057e2c1683640fe111e8b60c5ea03738fd8ee06fc5f719560416fee6d60e |
|
MD5 | afdb8008c401dbb0329fe3241af0d906 |
|
BLAKE2b-256 | 16ccc0d8741f1a0e56da8d08917217f80af385d77fd41d14c92313fec077596c |
Hashes for aiohttp-3.5.0b2-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d663b35a9d8ed09cc7650609696623cfbe20a3997098cf247447ab23b98ab45c |
|
MD5 | 35c28108df412c5178f5219e719799d2 |
|
BLAKE2b-256 | 070cc4dd2f3cc9109924889390f4db893e750dfe3beffc34190cd66b3666f478 |
Hashes for aiohttp-3.5.0b2-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c5ca6324d2e94705dd1bd0cb3825a43918850cb922eeaea611534c911c112b7 |
|
MD5 | d927699578dec9da5e54a9f319e18e8b |
|
BLAKE2b-256 | 06cd016845da0a8f45f9a71fff2b7d23f14cc20d7b41780c917f7bc418bc603e |
Hashes for aiohttp-3.5.0b2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9464ed2c903a665834d2fc15315de105f52ce2c178360ff5b4ceea46548cc243 |
|
MD5 | f3f3725aeb395a4e5e6bf7303b8c329a |
|
BLAKE2b-256 | 61deddbe99c1471ad0026c56d9a39bb549ea5e3bb81947d854dec3cfa5580584 |
Hashes for aiohttp-3.5.0b2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dd389253044d0c3c584a6261f09d16ba0b2e9fddb73bbf99c48751823545cb4 |
|
MD5 | 42dde406032c0a2683e503289f400f43 |
|
BLAKE2b-256 | c31b7fd948611b8656037e0d7cd84081024ccd4a1e0bc284836c4c53e48b0714 |
Hashes for aiohttp-3.5.0b2-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f72eb56bb8e5a79220ddbff0026f9cb056d52193298f8bfedfbc403998ee915f |
|
MD5 | d5a186dbf5da0c8fe9424b5842315972 |
|
BLAKE2b-256 | 1908a58b51f8ad47db7179b5880b1ee1e97aafd0c3b849a45953fe6d6b09b681 |
Hashes for aiohttp-3.5.0b2-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 082b5f8440f677d75d23327f208aafdd1d1d0c2cc01f9478148cb06d190fde8c |
|
MD5 | 82a464efeccb4952bc3a2f3a17552dac |
|
BLAKE2b-256 | d8f56542f0c4530ad21d7cf173c134dc65cbf3d4a16f69efdce004d9b5d95455 |
Hashes for aiohttp-3.5.0b2-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78996a313d9b6c45205d8f16bb6cad2bd699a41c11c639ca92614176075f88e3 |
|
MD5 | 2d84a1ebbb33a4357baab32ca4f9f159 |
|
BLAKE2b-256 | 192ecfc92709cb9cf1081147db781ba112bb7c76d384b315916906a117b8f592 |
Hashes for aiohttp-3.5.0b2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07e9df64813e2659250865c38714e4f374d832f05baab3fdf61961e9e9961247 |
|
MD5 | 097f6b3019f3bc89f11f9d676987e0d3 |
|
BLAKE2b-256 | 22b9379d4af4d1ec666d0aa335d745a3a914b742aae758a9cd28b5e31c1c1bb2 |
Hashes for aiohttp-3.5.0b2-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f85f4e963ceff78127987d24317ce01816717c79e9b8ce6ac5d036167fb400df |
|
MD5 | 751d625a42dabb26efba86b8e199cc45 |
|
BLAKE2b-256 | c811395ce3767a2011103d5e0798b1877a9b8196f2136f74c8dceaecb872be7b |
Hashes for aiohttp-3.5.0b2-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e5674beedd6983d1049316089bcc3c76a0f495d38d642161f73c90a16176bb1 |
|
MD5 | d046c55dc8061a3db77c533149572d1f |
|
BLAKE2b-256 | 820ff5d80fcd83b11c591860f1c3a7257632016c4b35f7f544d809aa8f383c22 |
Hashes for aiohttp-3.5.0b2-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb220b17bf8b1973c01a86df6af94a03eeb23966fe9cbc568846d4cd84ec7dfb |
|
MD5 | c454d6d43c268aa8b54fd37906945965 |
|
BLAKE2b-256 | ad5ece9a8056b2d7ce3f4e3a1cb7b8075a0f5fe80bc6cacee2659495bcbdcf32 |
Hashes for aiohttp-3.5.0b2-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01dd045c65c1e9dc1dbe50513895217e7409ba2cc1c106cd937cbd4057458e00 |
|
MD5 | 2e1f7c5bc5f0b03a256c34a6196ddf9d |
|
BLAKE2b-256 | b887d3bf86ce4eb0d032f5c8864672fc2149c6c7baf764bab4fd5e73fbfbc18b |