Skip to content
forked from aio-libs/aiohttp

Asynchronous HTTP client/server framework for asyncio and Python

License

Notifications You must be signed in to change notification settings

NewUserHa/aiohttp

This branch is 1 commit ahead of, 5317 commits behind aio-libs/aiohttp:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a2830c1 · May 26, 2019
May 7, 2019
May 23, 2019
May 23, 2019
May 23, 2019
May 10, 2019
May 17, 2019
May 26, 2019
Apr 20, 2019
Aug 23, 2018
May 10, 2019
Apr 13, 2018
May 10, 2019
Jan 14, 2019
Mar 7, 2018
May 10, 2019
May 18, 2018
Aug 30, 2017
Aug 28, 2018
May 10, 2019
Jan 12, 2019
Mar 20, 2018
May 18, 2018
May 10, 2019
Dec 20, 2018
Jan 2, 2019
Jun 18, 2018
May 10, 2019
May 21, 2019
Oct 22, 2018
Jan 1, 2019
Dec 2, 2018
Dec 2, 2018
Dec 28, 2018
May 11, 2019
Oct 20, 2018

Repository files navigation

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 and avoids Callback Hell.
  • Provides Web-server with middlewares and pluggable routing.

Getting started

Client

To get 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

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

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

About

Asynchronous HTTP client/server framework for asyncio and Python

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 89.2%
  • C 10.4%
  • Shell 0.2%
  • Makefile 0.2%
  • Batchfile 0.0%
  • Gherkin 0.0%