Global request for aiohttp server
Project description
- info:
Global request for aiohttp server
Installation
pip install aiohttp_request
Usage
import asyncio
from aiohttp import web
from aiohttp_request import ThreadContext, middleware_factory, grequest, get_request
def thread():
assert grequest['sense'] == 42
async def task():
# grequest is `lazy` version of request
assert grequest['sense'] == 42
loop = asyncio.get_event_loop()
# works for threads as well with ThreadContext
await loop.run_in_executor(None, ThreadContext(thread))
async def hello(request):
# get_request is on-demand function to get current request
assert get_request() is request
request['sense'] = 42
# asyncio.Task is supported
await asyncio.ensure_future(task())
return web.Response(text="Hello, world")
app = web.Application(middlewares=[middleware_factory()])
app.add_routes([web.get('/', hello)])
web.run_app(app)
Python 3.7+ is required, there is no way to support older python versions!!!
Notes
The library relies on PEP 567 and its asyncio support
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_request-0.0.1.tar.gz
(2.7 kB
view details)
File details
Details for the file aiohttp_request-0.0.1.tar.gz
.
File metadata
- Download URL: aiohttp_request-0.0.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0499529a839d6f6c71ef5fcc60fa5fad87743d7d1abcd2c3b883df14e876aeff |
|
MD5 | 2d8e3975882d7b2474f638c8d52c9669 |
|
BLAKE2b-256 | 8e6f132d3d77feb1234d867fa1e3328d1071b5fc535703bc3be969b554750987 |