Releases: melvinkcx/fastapi-events
Releases · melvinkcx/fastapi-events
v0.6.0
What's Changed
- feat: add support for google-cloud-pubsub closes #25 by @Mohsin-Ul-Islam in #30
New Contributors
- @Mohsin-Ul-Islam made their first contribution in #30
Full Changelog: v0.5.1...v0.6.0
v0.5.1
v0.5.0
v0.4.0
What's Changed?
Event Chaining: Dispatching Events Within Handlers
Previously, dispatch()
can only be called within a request-response cycle.
With v0.4.0, it is now possible to invoke dispatch()
within event handlers. A huge thanks to @ndopj for contributing his idea in #23.
Please refer to this section for more details.
v0.3.0
What's Changed
Event payload validation via Pydantic
Full documentation can be found here
import uuid
from enum import Enum
from datetime import datetime
from pydantic import BaseModel
from fastapi_events.registry.payload_schema import registry as payload_schema
class UserEvents(Enum):
SIGNED_UP = "USER_SIGNED_UP"
ACTIVATED = "USER_ACTIVATED"
# Registering your event payload schema
@payload_schema.register(event_name=UserEvents.SIGNED_UP)
class SignUpPayload(BaseModel):
user_id: uuid.UUID
created_at: datetime
# Events with payload schema registered
dispatch(UserEvents.SIGNED_UP) # raises ValidationError, missing payload
dispatch(UserEvents.SIGNED_UP,
{"user_id": "9e79cdbb-b216-40f7-9a05-20d223dee89a"}) # raises ValidationError, missing `created_at`
dispatch(UserEvents.SIGNED_UP,
{"user_id": "9e79cdbb-b216-40f7-9a05-20d223dee89a", created_at: datetime.utcnow()}) # OK!
# Events without payload schema -> No validation will be performed
dispatch(UserEvents.ACTIVATED,
{"user_id": "9e79cdbb-b216-40f7-9a05-20d223dee89a"}) # OK! no validation will be performed