Skip to main content

Signalling for FastAPI.

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


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.1.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file fastapi-signals-0.1.1.tar.gz.

File metadata

  • Download URL: fastapi-signals-0.1.1.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

Hashes for fastapi-signals-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8753e36914aa7be0b0ec65aeefa6cd31d6ecdceef8147213d7f6a6df69ea25f9
MD5 bedce92e885b4e2bdc7dbeb72a4e5f00
BLAKE2b-256 58e7678eaf5e1cd4c959476a93b3a63cc6738c7192a7c10d89bdaa3482ddccec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page