aiohttp_request
- 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
aiohttp-request works nicely with threads via contextvars_executor , no ThreadContext is needed
import asyncio
from aiohttp import web
from aiohttp_request import middleware_factory, grequest
from contextvars_executor import ContextVarExecutor
def thread():
assert grequest['sense'] == 42
async def hello(request):
request['sense'] = 42
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, thread)
return web.Response(text="Hello, world")
loop = asyncio.get_event_loop()
loop.set_default_executor(ContextVarExecutor())
app = web.Application(middlewares=[middleware_factory()])
app.add_routes([web.get('/', hello)])
web.run_app(app)
Metadata
Release files for aiohttp-request 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aiohttp_request-0.0.2.tar.gz | 2.9 kB | Without provenance | Details |
Release files / aiohttp_request-0.0.2.tar.gz
| Download URL | aiohttp_request-0.0.2.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e17701b995fccb036971bd82e7616e809ccb776bf61084c24f4f3bfbf54fdfbf
|
|
BLAKE2b-256 checksum How to use checksums |
eea4754f0aed1dccf724de3c593c441e9497ec2590ab8f523eba5ad188a307c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for aiohttp-request 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.