Welcome to AIOHTTP¶
Asynchronous HTTP Client/Server for asyncio and Python.
Current version is 3.0.1-.
Key Features¶
- Supports both Client and HTTP Server.
- Supports both Server WebSockets and Client WebSockets out-of-the-box.
- Web-server has Middlewares, Signals and pluggable routing.
Library Installation¶
$ pip install aiohttp
You may want to install optional cchardet library as faster replacement for chardet:
$ pip install cchardet
For speeding up DNS resolving by client API you may install aiodns as well. This option is highly recommended:
$ pip install aiodns
Getting Started¶
Client example:
import aiohttp
import asyncio
import async_timeout
async def fetch(session, url):
async with async_timeout.timeout(10):
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)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Server example:
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)
web.run_app(app)
What’s new in aiohttp 3?¶
Go to What’s new in aiohttp 3.0 page for aiohttp 3.0 major release changes.
Tutorial¶
Source code¶
The project is hosted on GitHub
Please feel free to file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.
The library uses Travis for Continuous Integration.
Dependencies¶
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.
Contributing¶
Please read the instructions for contributors before making a Pull Request.
Authors and License¶
The aiohttp
package is written mostly by Nikolay Kim and Andrew Svetlov.
It’s Apache 2 licensed and freely available.
Feel free to improve this package and send a pull request to GitHub.
Policy for Backward Incompatible Changes¶
aiohttp keeps backward compatibility.
After deprecating some Public API (method, class, function argument, etc.) the library guaranties the usage of deprecated API is still allowed at least for a year and half after publishing new release with deprecation.
All deprecations are reflected in documentation and raises
DeprecationWarning
.
Sometimes we are forced to break the own rule for sake of very strong reason. Most likely the reason is a critical bug which cannot be solved without major API change, but we are working hard for keeping these changes as rare as possible.
Table Of Contents¶
- Client
- Quickstart
- Advanced Usage
- Reference
- Tracing Reference
- TraceConfig
- TraceRequestStartParams
- TraceRequestEndParams
- TraceRequestExceptionParams
- TraceRequestRedirectParams
- TraceConnectionQueuedStartParams
- TraceConnectionQueuedEndParams
- TraceConnectionCreateStartParams
- TraceConnectionCreateEndParams
- TraceConnectionReuseconnParams
- TraceDnsResolveHostStartParams
- TraceDnsResolveHostEndParams
- TraceDnsCacheHitParams
- TraceDnsCacheMissParams
- Server
- Tutorial
- Quickstart
- Advanced Usage
- Web Handler Cancellation
- Custom Routing Criteria
- Static file handling
- Template Rendering
- Reading from the same task in WebSockets
- Data Sharing aka No Singletons Please
- Middlewares
- Signals
- Nested applications
- Expect Header
- Custom resource implementation
- Application runners
- Graceful shutdown
- Background tasks
- Handling error pages
- Deploying behind a Proxy
- Swagger support
- CORS support
- Debug Toolbar
- Dev Tools
- Low Level
- Reference
- Logging
- Testing
- Deployment
- Utilities
- FAQ
- Are there any plans for @app.route decorator like in Flask?
- Has aiohttp the Flask Blueprint or Django App concept?
- How to create route that catches urls with given prefix?
- Where to put my database connection so handlers can access it?
- Why the minimal supported version is Python 3.4.2
- How a middleware may store a data for using by web-handler later?
- How to receive an incoming events from different sources in parallel?
- How to programmatically close websocket server-side?
- How to make request from a specific IP address?
- How to use aiohttp test features with code which works with implicit loop?
- API stability and deprecation policy
- How to enable gzip compression globally for the whole application?
- How to manage ClientSession inside web server?
- How to access db connection stored in app from subapplication?
- Miscellaneous
- Who use aiohttp?
- Contributing