Skip to main content

http client/server for asyncio

Project description

http client/server for asyncio

aiohttp logo https://secure.travis-ci.org/KeepSafe/aiohttp.png

Features

  • Supports both client and server side of HTTP protocol.

  • Supports Web-Sockets out-of-the-box.

  • Web-server has middlewares and pluggable routing.

Requirements

License

aiohttp is offered under the Apache 2 license.

Documentation

http://aiohttp.readthedocs.org/

Source code

The latest developer version is available in a github repository: https://github.com/KeepSafe/aiohttp

Getting started

Client

To retrieve something from the web:

import aiohttp

def get_body(url):
    response = yield from aiohttp.request('GET', url)
    return (yield from response.read())

You can use the get command like this anywhere in your asyncio powered program:

response = yield from aiohttp.request('GET', 'http://python.org')
body = yield from response.read()
print(body)

If you want to use timeouts for aiohttp client side please use standard asyncio approach:

yield from asyncio.wait_for(request('GET', url), 10)

Server

In aiohttp 0.12 we’ve added highlevel API for web HTTP server.

There is simple usage example:

import asyncio
from aiohttp import web


@asyncio.coroutine
def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(body=text.encode('utf-8'))


@asyncio.coroutine
def init(loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', '/{name}', handle)

    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8080)
    print("Server started at http://127.0.0.1:8080")
    return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever()

CHANGES

0.15.0 (03-27-2015)

  • Client WebSockets support

  • New Multipart system #273

  • Support for “Except” header #287 #267

  • Set default Content-Type for post requests #184

  • Fix issue with construction dynamic route with regexps and trailing slash #266

  • Add repr to web.Request

  • Add repr to web.Response

  • Add repr for NotFound and NotAllowed match infos

  • Add repr for web.Application

  • Add repr to UrlMappingMatchInfo #217

  • Gunicorn 19.2.x compatibility

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-0.15.0.tar.gz (446.2 kB view details)

Uploaded Source

File details

Details for the file aiohttp-0.15.0.tar.gz.

File metadata

  • Download URL: aiohttp-0.15.0.tar.gz
  • Upload date:
  • Size: 446.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiohttp-0.15.0.tar.gz
Algorithm Hash digest
SHA256 f83c78b1188873edf4cf06d99e73011826458f61cc7519f6c00c89171db66efc
MD5 0055b1731cdecff6e96af9e1d5788543
BLAKE2b-256 700c299203e95813cf79c5023d241c7189e828424cabe288db26f3e84b8a83f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page