msaSignal - Signals/Events for Starlette/FastAPI.
Signals/Events for Starlette/FastAPI. Run background task without blocking the function that creates the signal.
msaSDK.signals tries to stay as a background task runner.
Documentation: msaSignal Documentation (https://msaSignal.u2d.ai/)
- Middleware: for Signal or Task.
- Decorators: for signal registry
- Helpers: for Handler, initiate a Signalor a Task
- Starlette 0.20.x
!!! note Only one signal per function, must take request object as arg
from msaSignal import MSASignalMiddleware, signal
from fastapi import FastAPI
app = FastAPI()
app.add_midleware(MSASignalMiddleware, handler=signal)
# OR enable MSASetting for this feature (settings.signal_middleware)
Specify how the fired signal should work.
from msaSignal import signal
import asyncio
@signal.register
async def handler(**kwargs):
await asyncio.sleep(5)
print(kwargs)
print('Works!')
!!! note Only one signal call is allowed using background task.
from msaSignal import initiate_signal
@app.get("/")
async def endpoint(request: Request):
await initiate_signal(request, 'handler',some_data="test value")
return {"status":"Success"}
Any number of tasks, no request object needed.
from msaSignal import MSATaskMiddleware
from fastapi import FastAPI
app = FastAPI()
app.add_midleware(MSATaskMiddleware)
# OR enable MSASetting for this feature (settings.task_middleware)
Specify how the fired task should work.
async def handler():
await asyncio.sleep(5)
print('Works!')
from msaSignal import initiate_task
@app.get("/")
async def endpoint():
await initiate_task(handler,some_data="test value")
return {"status":"Success"}
msaSignal
Based onMIT
open source and free to use, it is free for commercial use, but please show/list the copyright information about msaSignal somewhere.
We use mkdocs and mkdocsstring. The code reference and nav entry get's created virtually by the triggered python script /docs/gen_ref_pages.py while mkdocs
serve
or build
is executed.
PDF Export is using mainly weasyprint, if you get some errors here pls. check there documentation. Installation is part of the msaSignal, so this should be fine.
We can now test and view our documentation using:
mkdocs serve
Build static Site:
mkdocs build
Build:
python setup.py sdist
Publish to pypi:
twine upload dist/*