Asynchronous HTTP Client/Server for asyncio
and Python.
Current version is .
- Supports both
aiohttp-client
andHTTP Server <aiohttp-web>
. - Supports both
Server WebSockets <aiohttp-web-websockets>
andClient WebSockets <aiohttp-client-websockets>
out-of-the-box without the Callback Hell. - Web-server has
aiohttp-web-middlewares
,aiohttp-web-signals
and plugable routing.
$ pip install aiohttp
You may want to install optional cchardet
library as faster replacement for chardet
:
$ pip install cchardet
For speeding up DNS resolving by client API you may install aiodns
as well. This option is highly recommended:
$ pip install aiodns
The following will get you aiohttp
along with chardet
, aiodns
and Brotli
in one bundle. No need to type separate commands anymore!
$ pip install aiohttp[speedups]
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('http://python.org') as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
print("Body:", html[:15], "...")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
This prints:
Status: 200
Content-type: text/html; charset=utf-8
Body: <!doctype html> ...
Coming from requests
? Read why we need so many lines <aiohttp-request-lifecycle>
.
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
if __name__ == '__main__':
web.run_app(app)
For more information please visit aiohttp-client
and aiohttp-web
pages.
Go to aiohttp_whats_new_3_0
page for aiohttp 3.0 major release changes.
Polls tutorial <aiohttp-demos-polls-beginning>
The project is hosted on GitHub
Please feel free to file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.
The library uses Azure Pipelines for Continuous Integration.
- Python 3.6+
- async_timeout
- attrs
- chardet
- multidict
- yarl
Optional
cchardet
as faster replacement forchardet
.Install it explicitly via:
$ pip install cchardet
Optional
aiodns
for fast DNS resolving. The library is highly recommended.$ pip install aiodns
aio-libs discourse group: https://aio-libs.discourse.group
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.
Please read the instructions for contributors<aiohttp-contributing>
before making a Pull Request.
The aiohttp
package is written mostly by Nikolay Kim and Andrew Svetlov.
It's Apache 2 licensed and freely available.
Feel free to improve this package and send a pull request to GitHub.
aiohttp keeps backward compatibility.
After deprecating some Public API (method, class, function argument, etc.) the library guaranties the usage of deprecated API is still allowed at least for a year and half after publishing new release with deprecation.
All deprecations are reflected in documentation and raises DeprecationWarning
.
Sometimes we are forced to break the own rule for sake of very strong reason. Most likely the reason is a critical bug which cannot be solved without major API change, but we are working hard for keeping these changes as rare as possible.
client web utilities faq misc external contributing