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.0 (2018-12-22)
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.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b535790eb0699b0f460af2ab787fe7e11efdc283e345c87c18bc4731b244aa06 |
|
MD5 | f638326f8a4bd721de4f72047d909c0c |
|
BLAKE2b-256 | 46df771c545d1a39c91cd54d7733723b64197048269bd4bcb5ce8dbfcab2c6ae |
Hashes for aiohttp-3.5.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d45e686c41d5fca62860440dd162a9046246ab53589db52a2effab608c613399 |
|
MD5 | 12da393be59cc0f611417ddb610912d3 |
|
BLAKE2b-256 | 2cfcf619bd5456755e6b5c66e3a9b7c03ec22ba6cda3fd8b350a46352208110f |
Hashes for aiohttp-3.5.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0aa8ccf0097501920508fa5c94f037a280c1fc87bc0f706b3cab5711974fb1e |
|
MD5 | 71e27b21a71163e23088ee19ffda7bd2 |
|
BLAKE2b-256 | 38a874ec4b28e1d13acd2a3d4196cc0753d0f50afe9eb571ccda1358c75cdb9a |
Hashes for aiohttp-3.5.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd309f639deab08efb5f546afc67ef66edf480acfce4a6e191b9f360a651d624 |
|
MD5 | 2ba50843932cadba46712cf3c0e8e7e9 |
|
BLAKE2b-256 | 32bcf4cc366bf00f50a1e0247d7288f07681d01dd61b80f74eadad12aabf34b6 |
Hashes for aiohttp-3.5.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c87ca2059a657898b3cd500475b00b6955182a2f1b6ac1940493386a4415c1c0 |
|
MD5 | c0f52424ae160247d742e2b6ffe15ead |
|
BLAKE2b-256 | 9565a602d0ff04d8a3ce81ccbfc9beb507aa40aadb49c12a6dc4e00573ddccfa |
Hashes for aiohttp-3.5.0-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | decdf0d9169187f150bd43a686c4f132c3cc5ef88cc293f0ecfeebcb911d8e84 |
|
MD5 | f6e3bc6a69807ae1ca30f67e3276be7f |
|
BLAKE2b-256 | 3ccd2d99c7fcefaa4de0fea38e324e591b207bf1925adaf7e476fc3fba13fc8d |
Hashes for aiohttp-3.5.0-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162a8397788d9cd117721b179145460d2754227f3db106b6a15c5a73877413d8 |
|
MD5 | ca9252ccae1934854b3df380af35c491 |
|
BLAKE2b-256 | 716a75b063519cec3556f3e0ce1ad4ba11599dd16c2236a0ad3ba837af2d92cf |
Hashes for aiohttp-3.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9531dbfb8c6182bb2378436769954d800818af5afe4fe0ba1ad8991fba8cc5ab |
|
MD5 | 776e73a1b04d644bb463735be56339ca |
|
BLAKE2b-256 | 840cd6034b35b027dcf19ecc4922ffa6d4c37c8885939dd7cc3d38181184e46b |
Hashes for aiohttp-3.5.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172ec2125df4bb8b4742a7e40b5938b5d9fa0b6a53d278c179ef2005f5a93b7a |
|
MD5 | 80d692b8b13cd344c6b0b86217eadea2 |
|
BLAKE2b-256 | e69fba33c056ac730855595a305bf4306e571b2197b6ddb1fba66a905045b2c9 |
Hashes for aiohttp-3.5.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f99d2ead8a453d0852f2f4023429020cdb55f4d443f5ba882962b169f520d77 |
|
MD5 | 85cc3f1c6347caafcadf9bf71f055584 |
|
BLAKE2b-256 | 6f109bcfc7d56208529374bd5b8be55932a87d38af9fdd34dd710689cbdfadf1 |
Hashes for aiohttp-3.5.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7f8b8091055af7f16020db4c760ff1f2803090f68b61e200eb8c36e8f50daa |
|
MD5 | 47046aec2eeacf37769684d8b7938a9a |
|
BLAKE2b-256 | a880372c4d7660904c9852f1ae849cab29fd0e2354ed97fc872e936ec6e99eb9 |
Hashes for aiohttp-3.5.0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcedfff6256eaa522ea9e0f861dd2825b6cd44a31010fc6cf823392fbf7ec762 |
|
MD5 | dd95113675430bf75c38cf73487a30a2 |
|
BLAKE2b-256 | a45174adef7d2e258c4af2142468cd950bf1bae56947210d49bd29e998e9b464 |
Hashes for aiohttp-3.5.0-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03c9c3e6041fd1be64f6f76d6415986e09d981bcec013c34bc1bc37d1f6b536b |
|
MD5 | a00092afa02e6e45b26949641a18dcfc |
|
BLAKE2b-256 | 8ea07f6abff6d49af1bc9af716995e8feae327e2ba3c74d0cbd4bf29d18c203e |
Hashes for aiohttp-3.5.0-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38793a9c183de8c032117496d3e595e757399ffad5963568ef88e7090836b6b9 |
|
MD5 | 2d4aaeaa72628469417134880d44be98 |
|
BLAKE2b-256 | 889f0d112e4c95d504728e711b71a7835ea4e12b670aa734e77be4453d840ce8 |
Hashes for aiohttp-3.5.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a0b82de118a614fc51c65d2d6d996425ee492abe9d137ebf5bc88aeccb2b353 |
|
MD5 | c0ed3a0bfd9cf3a9ced715771c699f30 |
|
BLAKE2b-256 | 3a7952e7c852ceabcd99bbe0ac7cc0acaa81969196c7d15e5c4719b1f917cb30 |
Hashes for aiohttp-3.5.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e86507463f3238f9df4d682091b809d2924635601c95f7a377925775f7064b3 |
|
MD5 | 5b060e671eb88b8ba46fc29ad9e791ff |
|
BLAKE2b-256 | 3c33fdbb4b910f21e8c32d0c0eca5175c5f0e1371629091dea4881fea36e763b |
Hashes for aiohttp-3.5.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e65bd6a05468497bd297e0298afef743803514b04896d4396ab44646f248844f |
|
MD5 | a6a5246298f47c15c903d8efa5c04158 |
|
BLAKE2b-256 | 4b09cc5ec44a2da2976f5907ed9bad383de222519e3575f21fb87f14c8233236 |
Hashes for aiohttp-3.5.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51db33266922798de0a05d0856b4bc30a16225572568595fffeecbd59e5d664a |
|
MD5 | bae6e0211cb8b7a11b28d9a07ab475e0 |
|
BLAKE2b-256 | c286e4cc3e9d01dbc7f1aa9247a8184c9dd074244bbcafb9b569082409b821e5 |
Hashes for aiohttp-3.5.0-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 869309240edd7ee245d23995064020fb3aff65aa754db2d4328fbd779ab72880 |
|
MD5 | f09c26e5d2349d2b0292fe53609086ae |
|
BLAKE2b-256 | 00b71911d99064c83426ed8db07414be8b3283bf09d8a0a33652e783b84bce44 |
Hashes for aiohttp-3.5.0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cba9014ab792b8219c0cfa573c9178232f315364a1c5aad4fc63a7f2fe575bb3 |
|
MD5 | bd2f23af458c74d93fb1eaee77350a28 |
|
BLAKE2b-256 | 048a538ad91579c61e6ccd46a9ae80d25f2d415d9ff28c9f8091af8e5cbe0396 |
Hashes for aiohttp-3.5.0-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03df17f456135e747e321821c8c350e590f75503e43fb93b38024e5afb4baa57 |
|
MD5 | b97e8929845eeb71c172096dee6d84a9 |
|
BLAKE2b-256 | f307618b8bcd5ab2a230aed1231d478b2699adf0c9bcc8663339348fb15f389d |