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 without the Callback Hell.
Web-server has middlewares and pluggable routing.
Getting started
Client
To retrieve 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
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 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 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.3.2 (2018-06-12)
3.3.1 (2018-06-05)
3.3.0 (2018-06-01)
Features
Raise ConnectionResetError instead of CancelledError on trying to write to a closed stream. (#2499)
Implement ClientTimeout class and support socket read timeout. (#2768)
Enable logging when aiohttp.web is used as a program (#2956)
Add canonical property to resources (#2968)
Forbid reading response BODY after release (#2983)
Implement base protocol class to avoid a dependency from internal asyncio.streams.FlowControlMixin (#2986)
Cythonize @helpers.reify, 5% boost on macro benchmark (#2995)
Optimize HTTP parser (#3015)
Implement runner.addresses property. (#3036)
Use bytearray instead of a list of bytes in websocket reader. It improves websocket message reading a little. (#3039)
Remove heartbeat on closing connection on keepalive timeout. The used hack violates HTTP protocol. (#3041)
Limit websocket message size on reading to 4 MB by default. (#3045)
Bugfixes
Improved Documentation
Deprecations and Removals
Deprecate custom application’s router. (#3021)
Misc
#3008, #3011
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.3.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96bb80b659cc2bafa160f3f0c346ce7fc10de1ffec4908d7f9690797f155f658 |
|
MD5 | 9ca4deb3c2d5a103957b3001ebd9f96f |
|
BLAKE2b-256 | 233af9aaa8e67463ad0cef7e3e957d8e17492366328686b2575a1424af177905 |
Hashes for aiohttp-3.3.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33aa7c937ebaf063a860cbb0c263a771b33333a84965c6148eeafe64fb4e29ca |
|
MD5 | 7d1a4590c0bc41d634b5bd07f3468976 |
|
BLAKE2b-256 | eee96c1744c7e8bb44a1fb9388fc340bede1aeb3d531462fc975aa14138dacfe |
Hashes for aiohttp-3.3.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70d56c784da1239c89d39fefa166fd429306dada641178389be4184a9c04e501 |
|
MD5 | 458b31471fff2b9187a22f51895abe55 |
|
BLAKE2b-256 | 54f98b47199ceae89a867edc45c43dc908384fd2e1ac22406b60d101d988752b |
Hashes for aiohttp-3.3.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae7501cc6a6c37b8d4774bf2218c37be47fe42019a2570e8510fc2044e59d573 |
|
MD5 | 1c45d91905b6dbe9d5a409165ac5f1d6 |
|
BLAKE2b-256 | e266756ad4b3d0456dcbcc3ab59e297dcdc58a3e8a6fee3f14aa474a97964abf |
Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 550b4a0788500f6d00f41b7fdd9fcce6d78f99706a7b2f6f81d4d331c7ca468e |
|
MD5 | a101b417691638ece08f929b2d635097 |
|
BLAKE2b-256 | 7b581d258b6853a3ba9b6627933f53f307958932701ffb2318f89d0d077a1de1 |
Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c833aa6f4c9ac3e3eb843e3d999bae51339ad33a937303f43ce78064e61cb4b6 |
|
MD5 | f5081453cc5769bd5b344c4ea4c2f781 |
|
BLAKE2b-256 | d069d84453c151bf9a06bd7f0f13915cc2d0b4337c7d4124da2f221f68e67575 |
Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe7b2972ff7e779e812f974aa5695edc328ecf559ceeea887ac46f06f090ad4c |
|
MD5 | 7171ca6e5ec70bddb7d76962dbfea018 |
|
BLAKE2b-256 | 623908e33c975b4d8149b3806f06344077ec17b78fb0eadafb03563e871e5963 |
Hashes for aiohttp-3.3.2-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 620f19ba7628b70b177f5c2e6a55a6fd6e7c8591cde38c3f8f52551733d31b66 |
|
MD5 | 5772cc9e13e1decc96cf187ab40dde26 |
|
BLAKE2b-256 | dcc20b6b6cfde08b068e9592cbe309401023a841b99a50b0bed1189ffcfe3725 |
Hashes for aiohttp-3.3.2-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff1447c84a02b9cd5dd3a9332d1fb181a4386c3625765bb5caf1cfbc210ab3f9 |
|
MD5 | c01baebc8cf00dabd19af08aeb959dd0 |
|
BLAKE2b-256 | eab24936aa1db329d27efdec02b4a4fb4e743a1ed19f6daa205b0b9badabbed1 |
Hashes for aiohttp-3.3.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de2c9e445a5d257935011268202338538abef1aaff341a4733eca56419ca6f6 |
|
MD5 | 4f6fa8f8590ec9c2ecc1a289d734a434 |
|
BLAKE2b-256 | 30e773221dc4f32a5c34fa131d64d18003a8940d4f489607ae7f231e32d9d42c |
Hashes for aiohttp-3.3.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f52e7287eb9286a1e91e4c67c207c2573147fbaddc68f70efb5aeee5d1992f2e |
|
MD5 | 1dc9898a0f6daaf8e29f3c5a937b8589 |
|
BLAKE2b-256 | da7a4c31e0e2884b1e982cae4bd8b066010e76f5e5653037ccd403e9f04f71ec |
Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 601e8e83123b4d423a9dfddf7d6943f4f520651a78ffcd50c99d065136c7ff7b |
|
MD5 | 99a90146b745a7f6e341e5195cd37165 |
|
BLAKE2b-256 | 7401e1653fb30a8d112c0dc4837a93775faca2461b62791494855ee046b7cef3 |
Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a112a1fdf3802b7f2b182e22e51d71e4a8fa7387d0d38e79a268921b869e384 |
|
MD5 | 18ae22066b7b07bc44e113cc0eb31ce4 |
|
BLAKE2b-256 | 6fc9340265675d4b553b46e94560eb1d0d1df7c9484a246b873ddc0516a74a74 |
Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd81d85a342edf3d2a388e2f24d9facebc9c04550043888f970ee2f228c93059 |
|
MD5 | 5b26010d63745c5a1e1ce1b291239923 |
|
BLAKE2b-256 | 8ed76c4716413cbaacb1ca371ee142f0edac87e7d8df8bba8f63165a32aa81cd |