Welcome to AIOHTTP

Asynchronous HTTP Client/Server forasyncio and Python.

Current version is 3.11.14.

Key Features

Library Installation

$pipinstallaiohttp

For speeding up DNS resolving by client API you may installaiodns as well.This option is highly recommended:

$pipinstallaiodns

Installing all speedups in one command

The following will get youaiohttp along withaiodns andBrotli in onebundle.No need to type separate commands anymore!

$pipinstallaiohttp[speedups]

Getting Started

Client example

importaiohttpimportasyncioasyncdefmain():asyncwithaiohttp.ClientSession()assession:asyncwithsession.get('http://python.org')asresponse:print("Status:",response.status)print("Content-type:",response.headers['content-type'])html=awaitresponse.text()print("Body:",html[:15],"...")asyncio.run(main())

This prints:

Status: 200Content-type: text/html; charset=utf-8Body: <!doctype html> ...

Coming fromrequests ? Readwhy we need so many lines.

Server example:

fromaiohttpimportwebasyncdefhandle(request):name=request.match_info.get('name',"Anonymous")text="Hello, "+namereturnweb.Response(text=text)app=web.Application()app.add_routes([web.get('/',handle),web.get('/{name}',handle)])if__name__=='__main__':web.run_app(app)

For more information please visitClient andServer pages.

Development mode

When writing your code, we recommend enabling Python’sdevelopment mode(python-Xdev). In addition to the extra features enabled for asyncio, aiohttpwill:

  • Use a strict parser in the client code (which can help detect malformed responsesfrom a server).

  • Enable some additional checks (resulting in warnings in certain situations).

What’s new in aiohttp 3?

Go toWhat’s new in aiohttp 3.0 page for aiohttp 3.0 major releasechanges.

Tutorial

Polls tutorial

Source code

The project is hosted onGitHub

Please feel free to file an issue on thebug tracker if you have found a bugor have some suggestion in order to improve the library.

Dependencies

  • attrs

  • multidict

  • yarl

  • Optionalaiodns for fast DNS resolving. Thelibrary is highly recommended.

    $pipinstallaiodns
  • OptionalBrotli orbrotlicffi for brotli (RFC 7932)client compression support.

    $pipinstallBrotli

Communication channels

aio-libs Discussions:https://github.com/aio-libs/aiohttp/discussions

Feel free to post your questions and ideas here.

Matrix:#aio-libs:matrix.org

We supportStack Overflow.Please addaiohttp tag to your question there.

Contributing

Please read theinstructions for contributorsbefore making a Pull Request.

Authors and License

Theaiohttp package is written mostly by Nikolay Kim and Andrew Svetlov.

It’sApache 2 licensed and freely available.

Feel free to improve this package and send a pull request toGitHub.

Policy for Backward Incompatible Changes

aiohttp keeps backward compatibility.

After deprecating somePublic API (method, class, function argument,etc.) the library guaranties the usage ofdeprecated API is stillallowed at least for a year and half after publishing new release withdeprecation.

All deprecations are reflected in documentation and raisesDeprecationWarning.

Sometimes we are forced to break the own rule for sake of very strongreason. Most likely the reason is a critical bug which cannot besolved without major API change, but we are working hard for keepingthese changes as rare as possible.

Table Of Contents