Skip to main content

http client/server for asyncio

Project description

http client/server for asyncio

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

Requirements

License

aiohttp is offered under the BSD license.

Documentation

http://aiohttp.readthedocs.org/

Getting started

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)

The signature of request is the following:

request(method, url, *,
        params=None,
        data=None,
        headers=None,
        cookies=None,
        auth=None,
        allow_redirects=True,
        max_redirects=10,
        encoding='utf-8',
        version=aiohttp.HttpVersion11,
        compress=None,
        chunked=None,
        expect100=False,
        connector=None,
        read_until_eof=True,
        request_class=None,
        response_class=None,
        loop=None
)

It constructs and sends a request. It returns response object. Parameters are explained as follow:

  • method: HTTP method

  • url: Request url

  • params: (optional) Dictionary or bytes to be sent in the query string of the new request

  • data: (optional) Dictionary, bytes, StreamReader or file-like object to send in the body of the request

  • headers: (optional) Dictionary of HTTP Headers to send with the request

  • cookies: (optional) Dict object to send with the request

  • auth: (optional) BasicAuth tuple to enable Basic HTTP Basic Auth

  • allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

  • version: Request http version.

  • compress: Boolean. Set to True if request has to be compressed with deflate encoding.

  • chunked: Boolean or Integer. Set to chunk size for chunked transfer encoding.

  • expect100: Boolean. Expect 100-continue response from server.

  • connector: aiohttp.connector.BaseConnector instance to support connection pooling and session cookies.

  • read_until_eof: Read response until eof if response does not have Content-Length header.

  • request_class: Custom Request class implementation.

  • response_class: Custom Response class implementation.

  • loop: Optional event loop.

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

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

Gunicorn worker

Since version 0.19.0 gunicorn has native support for aiohttp.

Paster configuration example:

[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 8080
worker_class = aiohttp.worker.AsyncGunicornWorker

CHANGES

  • Improve redirect handling #157

  • Send raw files as is #153

  • Better websocket support #150

0.9.1 (08-30-2014)

  • Added MultiDict support for client request params and data #114.

  • Fixed parameter type for IncompleteRead exception #118.

  • Strictly require ASCII headers names and values #137

  • Keep port in ProxyConnector #128.

  • Python 3.4.1 compatibility #131.

0.9.0 (07-08-2014)

  • Better client basic authentication support #112.

  • Fixed incorrect line splitting in HttpRequestParser #97.

  • Support StreamReader and DataQueue as request data.

  • Client files handling refactoring #20.

  • Backward incompatible: Replace DataQueue with StreamReader for request payload #87.

0.8.4 (07-04-2014)

  • Change ProxyConnector authorization parameters.

0.8.3 (07-03-2014)

  • Publish TCPConnector properties: verify_ssl, family, resolve, resolved_hosts.

  • Don’t parse message body for HEAD responses.

  • Refactor client response decoding.

0.8.2 (06-22-2014)

  • Make ProxyConnector.proxy immutable property.

  • Make UnixConnector.path immutable property.

  • Fix resource leak for aiohttp.request() with implicit connector.

  • Rename Connector’s reuse_timeout to keepalive_timeout.

0.8.1 (06-18-2014)

  • Use case insensitive multidict for server request/response headers.

  • MultiDict.getall() accepts default value.

  • Catch server ConnectionError.

  • Accept MultiDict (and derived) instances in aiohttp.request header argument.

  • Proxy ‘CONNECT’ support.

0.8.0 (06-06-2014)

  • Add support for utf-8 values in HTTP headers

  • Allow to use custom response class instead of HttpResponse

  • Use MultiDict for client request headers

  • Use MultiDict for server request/response headers

  • Store response headers in ClientResponse.headers attribute

  • Get rid of timeout parameter in aiohttp.client API

  • Exceptions refactoring

0.7.3 (05-20-2014)

  • Simple HTTP proxy support.

0.7.2 (05-14-2014)

  • Get rid of __del__ methods

  • Use ResourceWarning instead of logging warning record.

0.7.1 (04-28-2014)

  • Do not unquote client request urls.

  • Allow multple waiters on transport drain.

  • Do not return client connection to pool in case of exceptions.

  • Rename SocketConnector to TCPConnector and UnixSocketConnector to UnixConnector.

0.7.0 (04-16-2014)

  • Connection flow control.

  • Http client session/connection pool refactoring.

  • Better handling for bad server requests.

0.6.5 (03-29-2014)

  • Added client session reuse timeout.

  • Better client request cancellation support.

  • Better handling responses without content length.

  • Added HttpClient verify_ssl parameter support.

0.6.4 (02-27-2014)

  • Log content-length missing warning only for put and post requests.

0.6.3 (02-27-2014)

  • Better support for server exit.

  • Read response body until eof if content-length is not defined #14

0.6.2 (02-18-2014)

  • Fix trailing char in allowed_methods.

  • Start slow request timer for first request.

0.6.1 (02-17-2014)

  • Added utility method HttpResponse.read_and_close()

  • Added slow request timeout.

  • Enable socket SO_KEEPALIVE if available. (@polymorphm)

0.6.0 (02-12-2014)

  • Better handling for process exit.

0.5.0 (01-29-2014)

  • Allow to use custom HttpRequest client class.

  • Use gunicorn keepalive setting for async worker.

  • Log leaking responses.

  • python 3.4 compatibility

0.4.4 (11-15-2013)

  • Resolve only AF_INET family, because it is not clear how to pass extra info to asyncio.

0.4.3 (11-15-2013)

  • Allow to wait completion of request with HttpResponse.wait_for_close()

0.4.2 (11-14-2013)

  • Handle exception in client request stream.

  • Prevent host resolving for each client request.

0.4.1 (11-12-2013)

  • Added client support for expect: 100-continue header.

0.4 (11-06-2013)

  • Added custom wsgi application close procedure

  • Fixed concurrent host failure in HttpClient

0.3 (11-04-2013)

  • Added PortMapperWorker

  • Added HttpClient

  • Added tcp connection timeout to http client

  • Better client connection errors handling

  • Gracefully handle process exit

0.2

  • Fix packaging

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.9.2.tar.gz (632.6 kB view details)

Uploaded Source

Built Distribution

aiohttp-0.9.2-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aiohttp-0.9.2.tar.gz
Algorithm Hash digest
SHA256 a76ded64204fa4f06eaa37dcc29d7bf529c996943e12ee2c3e21151da2bac513
MD5 8b0bde9116e91860319e3250b3897a3f
BLAKE2b-256 a78294c71f3cadba40ca43c1f97924c23c16743cb5826344662b378e294df11e

See more details on using hashes here.

File details

Details for the file aiohttp-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4c6e2771e5530711863c6723141bdf31a177dfa0c7a02c48e1f2075b797ae36
MD5 4409e8dce68baaa480e56b46f6aa0fb3
BLAKE2b-256 50be5ddca1c94b666886d1520f49fc7fdcff7c2d17328a52e1dd4e8ee3d1f1d5

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