Aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
Alternatives To Aiohttp
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Aiohttp13,3767,3554,894a day ago220November 14, 2021499otherPython
Asynchronous HTTP client/server framework for asyncio and Python
Httpx10,229321,4242 days ago58May 23, 202242bsd-3-clausePython
A next generation HTTP client for Python. 🦋
Uvicorn6,29235784921 hours ago143June 27, 202240bsd-3-clausePython
An ASGI web server, for Python. 🦄
Nonebot23,920
a day ago21June 20, 202214mitPython
跨平台 Python 异步聊天机器人框架 / Asynchronous multi-platform chatbot framework written in Python
Pulsar1,8413413 years ago65December 29, 201727bsd-3-clausePython
Event driven concurrent framework for Python
Nonebot1,807547 months ago21September 28, 202110mitPython
基于 OneBot 标准的 Python 异步 QQ 机器人框架 / Asynchronous QQ robot framework based on OneBot for Python
Aioquic1,23692 days ago36February 03, 202222bsd-3-clausePython
QUIC and HTTP/3 implementation in Python
Blacksheep1,200554 days ago49May 15, 202230mitPython
Fast ASGI web framework for Python
Python Proxy96754a year ago138May 09, 202131mitPython
HTTP/HTTP2/HTTP3/Socks4/Socks5/Shadowsocks/ShadowsocksR/SSH/Redirect/Pf TCP/UDP asynchronous tunnel proxy implemented in Python 3 asyncio.
Socketify.py921
2 days ago28mitPython
Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
Alternatives To Aiohttp
Select To Compare


Alternative Project Comparisons
Readme

Async http client/server framework

aiohttp logo

GitHub Actions status for master branch codecov.io status for master branch Latest PyPI package version Downloads count Latest Read The Docs Chat on Gitter

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 plugable routing.

Getting started

Client

To get something from the web:

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], "...")

asyncio.run(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.

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)])

if __name__ == '__main__':
    web.run_app(app)

Documentation

https://aiohttp.readthedocs.io/

Demos

aio-libs/aiohttp-demos

External links

Feel free to make a Pull Request for adding your link to these pages!

Communication channels

aio-libs Discussions: https://github.com/aio-libs/aiohttp/discussions

gitter chat https://gitter.im/aio-libs/Lobby

We support Stack Overflow. Please add aiohttp tag to your question there.

Requirements

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: 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

Popular Asyncio Projects
Popular Http Projects
Popular Control Flow Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Python
Server
Http
Http Server
Http Client
Asyncio
Gitter
Aiohttp