You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Sviatoslav Sydorenko 7bf5fa4878
Suppress LegacyVersion deprecation @ pytest
4 days ago
.github Stop blocking CI tests with linting 1 week ago
CHANGES Add a change note to PR #6872 4 days ago
aiohttp Fixed ClientConnectorError docstring (#6846) 2 weeks ago
docs Stop installing cchardet speedup under >Python 3.9 1 week ago
examples Add aioredis for type checking examples (#6553) 6 months ago
requirements Bump coveragepy to v6.4.2 1 week ago
tests Suppress LegacyVersion deprecation @ pytest 4 days ago
tools Bump black to fix CI (#6675) 4 months ago
vendor http-parser -> llhttp (#6144) 10 months ago
.cherry_picker.toml Fix cherry-picker config 4 years ago
.codecov.yml Last attempt to delay codecov reports (#5973) 12 months ago
.editorconfig Dont inherit web exceptions for web.Response (#3462) 4 years ago
.git-blame-ignore-revs Ignore black commits in `git blame` (#6825) 4 weeks ago
.gitattributes Reformat git files 2 years ago
.gitignore http-parser -> llhttp (#6144) 10 months ago
.gitmodules Bump llhttp version to 6.0.6 10 months ago
.lgtm.yml Cleanup lgtm errors (#3902) 3 years ago
.mypy.ini Remove legacy examples (#5625) 10 months ago
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#6790) 2 months ago
.readthedocs.yml Implement future changelog previews in the docs (#6055) 10 months ago
CHANGES.rst Typing Errors Fixed (#6415) 8 months ago
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 4 years ago
CONTRIBUTING.rst Fix typos (#6464) 8 months ago
CONTRIBUTORS.txt Add Path support on web app run (#6843) 3 weeks ago
HISTORY.rst Spelling fixes (#5897) 10 months ago
LICENSE.txt Update copyright year from 2020 to 2022 (#6601) 6 months ago
MANIFEST.in Type annotations (#3049) 4 years ago
Makefile Makefile: replace which(1) with more portable `command -v` (#6784) 2 months ago
README.rst fix DeprecationWarning (#6749) 3 months ago
pyproject.toml Set the minimum required `setuptools` to v46.4.0 (#6225) 9 months ago
setup.cfg Update setup.cfg 6 days ago
setup.py Convert type comments to type annotations (#6410) 8 months ago

README.rst

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

Discourse status

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

https://github.com/aio-libs/aiohttp-demos

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

Communication channels

aio-libs discourse group: https://aio-libs.discourse.group

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