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.4.4 (2018-09-05)
Fix installation from sources when compiling toolkit is not available (#3241)
3.4.3 (2018-09-04)
Add app.pre_frozen state to properly handle startup signals in sub-applications. (#3237)
3.4.2 (2018-09-01)
Fix iter_chunks type annotation (#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.5.0a1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ea2f604af1717d5f0532a3117e97f30cf2dc35b97ca06097b12deb59cefe71 |
|
MD5 | 5eb13648e5263ff047b44fe7197194a9 |
|
BLAKE2b-256 | b1099849d50cb9270d43ac9d8002ff5a3f2602a89c42d370846e158caedeab90 |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 296a3b65791367f754e13fe225f2de6b204e75944a1643a0a8ad9206e1d55cff |
|
MD5 | 1da909a6779b57c7d564ef930107fb41 |
|
BLAKE2b-256 | 98fcab4dcc1f41b11f9ea9c77af3b706470a4c8df050338e500f1a5974149b87 |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7db662b79154c1066ad15d2b97b9693beaa4166a4dcc10914db8873b9f436253 |
|
MD5 | 4d672ea0a33d23ba0d2933b95f4a37c6 |
|
BLAKE2b-256 | 9dd6c2962ec4b05487029d83f8d406a6583a15fcdfa2b92d2510a0c77f9d8b8e |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6a4fff396221b0de3db349c871bba53183aabc431ab6530cd00fdba6ed08f6c |
|
MD5 | bc6ce024850406b1ef7afc9c71a533cd |
|
BLAKE2b-256 | 7c69da4033f748fdf0a9fc405807fe5655f641ef1e4983f4647ac43f1b8e19cd |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3837d3af51ce207979d45bcde03de00a8ab488a4907af45b0f1faddda55f925f |
|
MD5 | 423e9a14701c6433f708d6bb391623df |
|
BLAKE2b-256 | ee185ad85b9a955f62db654f1b51003c358a7f1f3a5a7dacc6c590c5033f9360 |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23c39e5a25409ec17be1205932520d82aa9e241d52058792e1f7ba2788543ff8 |
|
MD5 | 9aa63436c4d106ce767615e5d059010e |
|
BLAKE2b-256 | ffe642751c2579c25e612dbc655511638dbc6113801f1096458eab93fffb457e |
Hashes for aiohttp-3.5.0a1-cp37-cp37m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e92a0f11c1d39f68639c97d5dd39ed30089e7c3ff0bf27c0bfd32e54f2f537 |
|
MD5 | 48ee16da17ccdf0e88f9bca1e9b48289 |
|
BLAKE2b-256 | 1b1eff7ec1a4ec37261addc350f01dab9bb2189dd325c165be63d3aed3684194 |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c0b3e191b4a4b21656b29ad3c0fe125b844ff1c2a5b6e6e2295bac60330df3d |
|
MD5 | 60396f0a81b99798eb4f627d34bf76af |
|
BLAKE2b-256 | 63ce95dd616a89d693ed680712a88ca4a65ee198fd866d8b583717b4c1768319 |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f32ae1dd73fa98fafbc5b7d19686dd69f549dc84a02be3f8dc6bd4a318838fc9 |
|
MD5 | 68f501a8940276649277d4c578dbb660 |
|
BLAKE2b-256 | 856a94034c29ca1a7582594a01ca2059145c693deeb089c00243f45ef2e60488 |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12e5dcc07b11ccc371b2300e37275434a4dd3d38f73690e498255431d9713c65 |
|
MD5 | 096f99d7e82e5c225cd006383dbcac83 |
|
BLAKE2b-256 | 4d23542b486a2b131963ba3d5cd6e3c055f1b770e74d0d29385d0a678a2f26a4 |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 094d32fc32146b63dc766849dbe37a479cf8b38416f5d4599d9acb52f67390b2 |
|
MD5 | c1576d1eb8eb721055b504d2117eef7e |
|
BLAKE2b-256 | d5cf6b1e0982a4fbd7c1311ee35b6eaf1827f0976470691f419f5e2315066f4a |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ba76ac10dcda10fee8d82cdd6a78ccbd4042a3a7286f4d435619e8317d95a16 |
|
MD5 | bc6a99ae5b9f41239eb8cab2e3cf401c |
|
BLAKE2b-256 | d0f36d769ee8f4225330f18d320d35e196a95e95efbe7e4ab7557db5ab1f4f78 |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76798572bd4b815d31887c3e0b7de467a913ef950850e684167b2381872e5143 |
|
MD5 | 2653d7d79b3f1b058a233aea448725eb |
|
BLAKE2b-256 | 5b4b686a7d55a562d37391b48f8fe974f5d1a72a12e6f0bdc294468d790f2a6c |
Hashes for aiohttp-3.5.0a1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60a700b244e893e1c1d9b6a506b7bc85086ad4b2bb56275c5a0659dc0ab9f0b3 |
|
MD5 | 068830a55c6ef5e7459748399253168b |
|
BLAKE2b-256 | 129e1ab0decb8a8aa104b291a3ba709ce153fb2f4878e2980fa72a6b4e806dd7 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6941ccb0e1b8bdf6500aebaa13364cce25986483c519b045275151df7c715b7 |
|
MD5 | 8475c2778c66439253701baec8d187fb |
|
BLAKE2b-256 | c2944b17b41da9a3f0cf8031c607c3ad26dff25d6814714cbf60df74550cd759 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8c36c9ca6932742b2ea2f79d93953076e25ec0fdee4de644aa498e28786cce |
|
MD5 | 5e5b31f043b2c4fdad76219ee0b0b0f0 |
|
BLAKE2b-256 | febb210e64c1750f490eec540151f813728c49e7349bb397f5c964e49329d7b3 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f7df58f13680bd715a54965da7dff99f1266ea9e0d5735ec86017cb8170065d |
|
MD5 | 7d10c6e4d478d372d8a3d25d77c5035c |
|
BLAKE2b-256 | 2d7c8631518d955724460c9dcfdccea978f0df84f079ef8e088ee4ff1330e935 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c57a9353f7a6a421f381d90002fc8dc5874983a4f1bc8bc9ee419b33dee34f2f |
|
MD5 | 16fe3019e89efb6d8f447c43a36f6b0b |
|
BLAKE2b-256 | d53289ed11b831daed55e0313f2c95d875bbb4d1ce3930e1a61b382b1fe3d781 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94c9d1e6fece7fa6f1ed093491953db4a040b87c3791db9d30a5607edc44e21f |
|
MD5 | 6bec21c244c161313bb040a2f4a4f281 |
|
BLAKE2b-256 | 00a4f32d4fe56563aa98aa815fa72ffaef26fbf880c42be16dd5196713d3217f |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6692f1b6b1b55e6b7bf13ef7cfbe70930833fa80e864718841243a6da0082044 |
|
MD5 | 227c375ea983fbc5906c0e05b94aada7 |
|
BLAKE2b-256 | 7cbf0c005bfb8b765e593be1b154f3cff69093900e394fc93218c668da79f5c5 |
Hashes for aiohttp-3.5.0a1-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c45e271f37a85b97bc30fd3567dcb38bc7865911ee04730fe10e1372e8a4955e |
|
MD5 | 56a5ab10119ab10254679d00c68b0af8 |
|
BLAKE2b-256 | d41ec45763dc02cd4e4d3775f11679821ceb6df43fd92f7b5cc8fb1084b3605c |