- Welcome to AIOHTTP¶
- Key Features¶
- Library Installation¶
- Installing all speedups in one command¶
- Getting Started¶
- Client example¶
- Server example:¶
- What’s new in aiohttp 3?¶
- Tutorial¶
- Source code¶
- Dependencies¶
- Communication channels¶
- Contributing¶
- Authors and License¶
- Policy for Backward Incompatible Changes¶
- Table Of Contents¶
- aiohttp
Welcome to AIOHTTP¶
Asynchronous HTTP Client/Server for asyncio and Python.
Key Features¶
- Supports both Client and HTTP Server .
- Supports both Server WebSockets and Client WebSockets out-of-the-box without the Callback Hell.
- Web-server has Middlewares , Signals and plugable routing.
Library Installation¶
You may want to install optional cchardet library as faster replacement for charset-normalizer :
Note that the cchardet project is known not to support Python 3.10 or higher. See #6819 and GitHub: PyYoshi/cChardet/issues/77 for more details.
For speeding up DNS resolving by client API you may install aiodns as well. This option is highly recommended:
Installing all speedups in one command¶
The following will get you aiohttp along with cchardet , aiodns and Brotli in one bundle. No need to type separate commands anymore!
$ pip install aiohttp[speedups]
Getting Started¶
Client example¶
import aiohttp import asyncio async def main(): async with aiohttp.ClientSession() as session: async with session.get('http://python.org') as response: print("Status:", response.status) print("Content-type:", response.headers['content-type']) html = await response.text() print("Body:", html[:15], ". ") asyncio.run(main())
Status: 200 Content-type: text/html; charset=utf-8 Body: .
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.add_routes([web.get('/', handle), web.get('/ ', handle)]) if __name__ == '__main__': web.run_app(app)
For more information please visit Client and Server pages.
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¶
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.
Dependencies¶
- Python 3.6+
- async_timeout
- attrs
- charset-normalizer
- multidict
- yarl
- Optionalcchardet as faster replacement for charset-normalizer . Install it explicitly via:
Communication channels¶
Feel free to post your questions and ideas here.
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
- The aiohttp Request Lifecycle
- Tutorial
- Quickstart
- Advanced Usage
- Low Level
- Reference
- Logging
- Testing
- Deployment
- Abstract Base Classes
- Working with Multipart
- Multipart reference
- Streaming API
- Common data structures
- WebSocket utilities
- Are there plans for an @app.route decorator like in Flask?
- Does aiohttp have a concept like Flask’s “blueprint” or Django’s “app”?
- How do I create a route that matches urls with a given prefix?
- Where do I put my database connection so handlers can access it?
- How can middleware store data for web handlers to use?
- Can a handler receive incoming events from different sources in parallel?
- How do I programmatically close a WebSocket server-side?
- How do I make a request from a specific IP address?
- What is the API stability and deprecation policy?
- How do I enable gzip compression globally for my entire application?
- How do I manage a ClientSession within a web server?
- How do I access database connections from a subapplication?
- How do I perform operations in a request handler after sending the response?
- How do I make sure my custom middleware response will behave correctly?
- Why is creating a ClientSession outside of an event loop dangerous?
- Essays
- Glossary
- Changelog
- Indices and tables
- Third-Party libraries
- Built with aiohttp
- Powered by aiohttp
- Instructions for contributors
- Preconditions for running aiohttp test suite
- LLHTTP
- Run autoformatter
- Run aiohttp test suite
- Tests coverage
- Documentation
- Spell checking
- Changelog update
- Making a Pull Request
- Backporting
- How to become an aiohttp committer
aiohttp
Async HTTP client/server for asyncio and Python