An asynchronous event dispatching and handling library for FastAPI and Starlette applications.
FastAPI-Events is an asynchronous event dispatching and handling library specifically designed for FastAPI and Starlette applications. It enables developers to decouple business logic by emitting events that are processed after HTTP responses are sent, improving application scalability and maintainability. The library provides a straightforward API for event emission, supports payload validation with Pydantic, and offers both local and remote event handling capabilities.
Python developers building asynchronous web applications with FastAPI or Starlette who need to implement event-driven architectures, background task processing, or message queue integration without blocking request-response cycles.
Developers choose FastAPI-Events because it provides a native, framework-integrated solution for event handling that doesn't impact API response times. Its flexibility in handler creation, support for remote queue piping, and built-in features like OpenTelemetry tracing and Pydantic validation make it more comprehensive than basic task queue implementations.
Asynchronous event dispatching/handling library for FastAPI and Starlette
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Events are processed after HTTP responses are sent, ensuring zero impact on API latency, as emphasized in the README's promise of no response time impact.
Optional payload validation using Pydantic models ensures data integrity, with clear examples in the 'Event Payload Validation' section for registering schemas.
Supports custom handlers and built-in options like AWS SQS or local processing, allowing developers to tailor event handling without being limited by the library's defaults.
Native OpenTelemetry support for tracing event dispatches and handler executions, which can be enabled with an optional install as detailed in the OTEL section.
Dispatching events relies on ContextVars, causing LookupError when used outside request cycles—requiring workarounds like custom middleware_id, as admitted in the FAQs.
Built-in remote handlers only support AWS SQS and Google Cloud Pub/Sub, lacking native options for other popular brokers like RabbitMQ or Redis without custom development.
The library doesn't provide native mechanisms for retrying failed events or handling dead-letter queues, leaving error management entirely to the developer's implementation.