FastAPIEventEmitter
class¶
Bases: EventEmitter
An event emitter subclass that utilizes FastAPI's BackgroundTasks system to handle the execution of event emissions.
Notes:
- It provides a convenient way to incorporate event-driven functionality into FastAPI apps.
- This class offers a powerful mechanism for implementing asynchronous and decoupled operations in FastAPI, such as asynchronously sending emails in an event-driven manner.
Read more in the Pyventus docs for FastAPI Event Emitter.
Source code in pyventus/emitters/fastapi/fastapi_event_emitter.py
Functions¶
emit
¶
Emits an event and triggers its associated event handlers.
Notes:
- When emitting
dataclass
objects orException
objects, they are automatically passed to the event handler as the first positional argument, even if you pass additional*args
or**kwargs
. - If there are event handlers subscribed to the global event
...
, also known asEllipsis
, they will also be triggered each time an event or exception is emitted.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to be emitted. It can be
TYPE:
|
args
|
Positional arguments to be passed to the event handlers.
TYPE:
|
kwargs
|
Keyword arguments to be passed to the event handlers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
Source code in pyventus/emitters/event_emitter.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
options
classmethod
¶
options(event_linker: Type[EventLinker] = EventLinker, debug: bool | None = None) -> Callable[[BackgroundTasks], FastAPIEventEmitter]
Returns a decorator that allows you to configure the FastAPIEventEmitter
class
when using FastAPI's Depends
method.
PARAMETER | DESCRIPTION |
---|---|
event_linker
|
Specifies the type of event linker used to manage and access events along with their corresponding event handlers. Defaults to
TYPE:
|
debug
|
Specifies the debug mode for the logger. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable[[BackgroundTasks], FastAPIEventEmitter]
|
A decorator that can be used with the |
Source code in pyventus/emitters/fastapi/fastapi_event_emitter.py
__init__
¶
__init__(background_tasks: BackgroundTasks, event_linker: Type[EventLinker] = EventLinker, debug: bool | None = None) -> None
Initialize an instance of FastAPIEventEmitter
.
PARAMETER | DESCRIPTION |
---|---|
background_tasks
|
The FastAPI
TYPE:
|
event_linker
|
Specifies the type of event linker to use for associating events with their respective event handlers. Defaults to
TYPE:
|
debug
|
Specifies the debug mode for the logger. If
TYPE:
|