aiohttp¶
HTTP client/server for asyncio (PEP 3156).
Features¶
- Supports both HTTP Client and HTTP Server.
- Supports both Server WebSockets and Client WebSockets out-of-the-box.
- Web-server has Middlewares and pluggable routing.
Library Installation¶
pip install aiohttp
Getting Started¶
Client example:
import asyncio
import aiohttp
@asyncio.coroutine
def fetch_page(url):
response = yield from aiohttp.request('GET', url)
assert response.status == 200
return (yield from response.read())
content = asyncio.get_event_loop().run_until_complete(
fetch_page('http://python.org'))
print(content)
Server 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))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
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.
Contributing¶
Please read the instructions for contributors before making a Pull Request.
Authors and License¶
The aiohttp
package is written mainly 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.
Contents:
- HTTP Client
- Example
- Make a Request
- Passing Parameters In URLs
- Response Content
- Binary Response Content
- JSON Response Content
- Streaming Response Content
- Custom Headers
- Custom Cookies
- More complicated POST requests
- POST a Multipart-Encoded File
- Streaming uploads
- Keep-Alive, connection pooling and cookie sharing
- Connectors
- Limiting connection pool size
- SSL control for tcp sockets
- Unix domain sockets
- Proxy support
- Response Status Codes
- Response Headers
- Response Cookies
- Timeouts
- HTTP Client Reference
- WebSockets Client
- HTTP Server Usage
- HTTP Server Reference
- Low-level HTTP Server
- Multidicts
- Working with Multipart
- Helpers API
- aiohttp web application with Gunicorn
- Contributing
- CHANGES
- 0.16.0 (05-26-2015)
- 0.15.3 (04-22-2015)
- 0.15.2 (04-19-2015)
- 0.15.1 (03-31-2015)
- 0.15.0 (03-27-2015)
- 0.14.4 (01-29-2015)
- 0.14.3 (01-28-2015)
- 0.14.2 (01-23-2015)
- 0.14.1 (01-15-2015)
- 0.13.1 (12-31-2014)
- 0.13.0 (12-29-2014)
- 0.12.0 (12-12-2014)
- 0.11.0 (11-29-2014)
- 0.10.2 (11-19-2014)
- 0.10.1 (11-17-2014)
- 0.10.0 (11-13-2014)
- 0.9.3 (10-30-2014)
- 0.9.2 (10-16-2014)
- 0.9.1 (08-30-2014)
- 0.9.0 (07-08-2014)
- 0.8.4 (07-04-2014)
- 0.8.3 (07-03-2014)
- 0.8.2 (06-22-2014)
- 0.8.1 (06-18-2014)
- 0.8.0 (06-06-2014)
- 0.7.3 (05-20-2014)
- 0.7.2 (05-14-2014)
- 0.7.1 (04-28-2014)
- 0.7.0 (04-16-2014)
- 0.6.5 (03-29-2014)
- 0.6.4 (02-27-2014)
- 0.6.3 (02-27-2014)
- 0.6.2 (02-18-2014)
- 0.6.1 (02-17-2014)
- 0.6.0 (02-12-2014)
- 0.5.0 (01-29-2014)
- 0.4.4 (11-15-2013)
- 0.4.3 (11-15-2013)
- 0.4.2 (11-14-2013)
- 0.4.1 (11-12-2013)
- 0.4 (11-06-2013)
- 0.3 (11-04-2013)
- 0.2
- Glossary