Python C Other
Switch branches/tags
Clone or download
pyup-bot and webknjaz Scheduled weekly dependency update for week 32 (#3193)
* Update tox from 3.1.3 to 3.2.1

* Update uvloop from 0.11.1 to 0.11.2
Latest commit 82a2c2a Aug 14, 2018
Permalink
Failed to load latest commit information.
.github Fix pull request template (#2866) Mar 21, 2018
CHANGES AbstractRouteDef is importable from aiohttp.web (#3183) (#3188) Aug 12, 2018
aiohttp AbstractRouteDef is importable from aiohttp.web (#3183) (#3188) Aug 12, 2018
docs Add option to remove slash to `normalize_path_middleware` (#3173) Aug 10, 2018
examples Send welcome message at very first of communication channel May 4, 2018
requirements Scheduled weekly dependency update for week 32 (#3193) Aug 14, 2018
tests Add option to remove slash to `normalize_path_middleware` (#3173) Aug 10, 2018
tools Add jobs for testing and releasing 3.7.0 specific stuff in CIs Jul 10, 2018
vendor Turn vendored Node.js' http-parser into a git submodule (#3011) May 18, 2018
.appveyor.yml Add jobs for testing and releasing 3.7.0 specific stuff in CIs Jul 10, 2018
.cherry_picker.toml Fix cherry-picker config Apr 13, 2018
.editorconfig Add editorconfig Mar 27, 2018
.gitattributes Mark more test files as binary Mar 7, 2018
.gitignore Micro-optimization (#3095) Jun 22, 2018
.gitmodules Turn vendored Node.js' http-parser into a git submodule (#3011) May 18, 2018
.pyup.yml Run pyup bot every week Aug 30, 2017
.readthedocs.yml Enable Read The Docs build sphinx rst using py 3.6 (#2655) Jan 12, 2018
.travis.yml Add jobs for testing and releasing 3.7.0 specific stuff in CIs Jul 10, 2018
CHANGES.rst Fix changelog links Jun 12, 2018
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Mar 20, 2018
CONTRIBUTING.rst Turn vendored Node.js' http-parser into a git submodule (#3011) May 18, 2018
CONTRIBUTORS.txt Add option to remove slash to `normalize_path_middleware` (#3173) Aug 10, 2018
HISTORY.rst Bump to 3.3.0 Jun 1, 2018
LICENSE.txt Mention 2018 year Jan 1, 2018
MANIFEST.in Type annotations (#3049) Jun 18, 2018
Makefile Type annotations (#3049) Jun 18, 2018
README.rst Replace AppVeyor project with new official (#3065) Jun 10, 2018
codecov.yml prevent codecov blames about reducing total lines in code, check PR only Jul 15, 2017
pyproject.toml Fix CHANGES name in towncrier config Oct 18, 2017
setup.cfg Type annotations (#3049) Jun 18, 2018
setup.py Use env marker for conditional dependency Jul 10, 2018
tox.ini Fix tox May 11, 2018

README.rst

Async http client/server framework

aiohttp logo


Travis status for master branch AppVeyor status for master branch codecov.io status for master branch Latest PyPI package version 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 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

https://aiohttp.readthedocs.io/

Demos

https://github.com/aio-libs/aiohttp-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

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