{"id":21324,"library":"fastapi-events","title":"fastapi-events","description":"Event dispatching library for FastAPI that supports synchronous and asynchronous event handlers, multiple backends (AWS SQS, Google Cloud Pub/Sub, RabbitMQ, Redis, etc.), OpenTelemetry integration, and Pydantic model dispatching. Current version 0.12.2, release cadence ~monthly.","status":"active","version":"0.12.2","language":"python","source_language":"en","source_url":"https://github.com/melvinkcx/fastapi-events","tags":["fastapi","events","async","middleware","event-driven","pydantic"],"install":[{"cmd":"pip install fastapi-events","lang":"bash","label":"Core install"},{"cmd":"pip install fastapi-events[aws]","lang":"bash","label":"With AWS SQS support"},{"cmd":"pip install fastapi-events[gcp]","lang":"bash","label":"With Google Cloud Pub/Sub support"},{"cmd":"pip install fastapi-events[rabbit]","lang":"bash","label":"With RabbitMQ support"},{"cmd":"pip install fastapi-events[redis]","lang":"bash","label":"With Redis support"}],"dependencies":[{"reason":"Required; the library is built on top of FastAPI","package":"fastapi","optional":false},{"reason":"Required for event schema definition and validation","package":"pydantic","optional":false},{"reason":"Required for AWS SQS backend","package":"boto3","optional":true},{"reason":"Required for Google Cloud Pub/Sub backend","package":"google-cloud-pubsub","optional":true},{"reason":"Required for RabbitMQ backend","package":"aio-pika","optional":true},{"reason":"Required for Redis backend","package":"redis","optional":true},{"reason":"Required for OpenTelemetry integration","package":"opentelemetry-api","optional":true}],"imports":[{"note":"Wrong import path; the dispatcher is directly under fastapi_events","wrong":"from fastapi_events.dispatcher import event_dispatch","symbol":"event_dispatch","correct":"from fastapi_events import event_dispatch"},{"note":"Pre-0.9.0 pattern; LocalHandler moved to .local submodule","wrong":"from fastapi_events.handlers import LocalHandler","symbol":"EventHandler","correct":"from fastapi_events.handlers.local import LocalHandler"},{"note":"Model schema classes were renamed in 0.10.0","wrong":"from fastapi_events.models import Payload","symbol":"Payload","correct":"from fastapi_events.typing import EventModel"}],"quickstart":{"code":"from fastapi import FastAPI\nfrom fastapi_events import event_dispatch\nfrom fastapi_events.middleware import EventHandlerASGIMiddleware\nfrom fastapi_events.handlers.local import LocalHandler\n\napp = FastAPI()\nhandler = LocalHandler()\n\napp.add_middleware(\n    EventHandlerASGIMiddleware,\n    handlers=[handler],\n)\n\n@app.get(\"/\")\nasync def root():\n    # Dispatch an event that will be handled locally\n    event_dispatch(\"my_event\", payload={\"key\": \"value\"})\n    return {\"message\": \"Event dispatched\"}\n\n@handler.register(\"my_event\")\ndef handle_my_event(payload: dict):\n    print(f\"Received event with payload: {payload}\")","lang":"python","description":"Basic FastAPI app that dispatches a local event and handles it synchronously."},"warnings":[{"fix":"Use event_dispatch('event_name', payload=...) instead of relying on function name.","message":"Implicit event name from function name as string literal is deprecated in 0.10.0+; use explicit event_name argument.","severity":"deprecated","affected_versions":">=0.10.0"},{"fix":"Use .model_dump() for Pydantic v2 models, or set config to opt-out of schema dump.","message":"Pydantic v1 .dict() method is deprecated and removed in Pydantic v2; events using Pydantic models require model_dump().","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Ensure handler function signature matches the dispatcher context (sync vs async).","message":"Event handlers registered as coroutines must be awaited; mixing sync and async handlers can cause missing events.","severity":"gotcha","affected_versions":"all"},{"fix":"Add EventHandlerASGIMiddleware as the first middleware using app.add_middleware() at the top.","message":"Middleware order matters: EventHandlerASGIMiddleware must be added before other middleware that may intercept events.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from fastapi_events import event_dispatch","cause":"Wrong import path; event_dispatch is directly under fastapi_events.","error":"ImportError: cannot import name 'event_dispatch' from 'fastapi_events.dispatcher'"},{"fix":"Use: from fastapi_events.handlers.local import LocalHandler","cause":"LocalHandler moved to fastapi_events.handlers.local in version 0.9.0.","error":"AttributeError: module 'fastapi_events.handlers' has no attribute 'LocalHandler'"},{"fix":"Upgrade to fastapi-events >=0.11.0 or configure Pydantic v2 to use model_dump.","cause":"Pydantic v2 deprecation; fastapi-events >=0.10.2 emits this warning.","error":"DeprecationWarning: The 'dict' method is deprecated; use 'model_dump' instead"},{"fix":"Make sure event handlers return None (implicitly) and do not return FastAPI Response objects.","cause":"Event handler returns an HTTP response object instead of None; handlers should not return responses.","error":"fastapi.exceptions.FastAPIError: Invalid args for response. Response must be a Starlette Response, or a subclass thereof."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}