Signalling for FastAPI.
Reason this release was yanked:
Bug
Project description
fastapi-signals
Signalling for FastAPI.
Usage - SignalMiddleware
NB: Only one signal per function, must take request object
Add middleware
from fastapi_signals import SignalMiddleware, signal
app = FastAPI()
app.add_midleware(SignalMiddleware, handler=signal)
Add handler
Specify how the fired signal should work.
from fastapi_signals import signal
import asyncio
@signal.register
async def handler():
await asyncio.sleep(3)
print('Heyy, it works!')
Fire signal in function
Note that only one signal call is allowed using backgroud task.
from fastapi_signals import initiate_signal
@app.get("/")
async def endpoint(request):
await initiate_signal('handler',some_data="value")
return {"status":"Success"}
Usage - TaskMiddleware
Any number of tasks, no request object needed.
Add middleware
from fastapi_signals import TaskMiddleware
app = FastAPI()
app.add_midleware(TaskMiddleware)
Write handler
Specify how the fired task should work.
async def handler():
await asyncio.sleep(3)
print('Heyy, it works!')
Fire task in function
from fastapi_signals import initiate_task
@app.get("/")
async def endpoint():
await initiate_task(handler,some_data="value")
return {"status":"Success"}
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
fastapi-signals-0.1.0.tar.gz
(3.4 kB
view details)
File details
Details for the file fastapi-signals-0.1.0.tar.gz
.
File metadata
- Download URL: fastapi-signals-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c12e751c6976ef0693ac62257652ab122df633040f2efa682b52238b606988e9 |
|
MD5 | 38e48f8290bd378e4e9bdfcb8459238d |
|
BLAKE2b-256 | 369d3c3d8278b37ef3004dfebcb2d4ad231fb16e554811d91fd5ea18e3e20f66 |