Events
Full attribute and method reference for the event system, generated from docstrings. For a task-oriented walkthrough, see Events.
Event bus
starlette_admin.events.AdminEventBus
Admin-level event bus. Delegates view lifecycle events to view buses;
handles admin-level events (e.g. AFTER_LOGIN) itself, since they are not
tied to any view.
Source code in starlette_admin/events.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
emit(ctx)
async
Fire handlers registered for an admin-level event (e.g. AFTER_LOGIN).
View lifecycle events are emitted by the matching view's EventBus
instead; this is only for events not tied to any view.
Source code in starlette_admin/events.py
off(event, handler)
Remove a handler from all view buses, or from the admin-level bus.
Source code in starlette_admin/events.py
on(event, handler=None, *, keys=None, priority=0)
Register a handler. For view lifecycle events, delegates to matching view buses.
Admin-level events (e.g. AFTER_LOGIN) are handled directly and ignore keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
AdminEvent | str
|
The event to handle. |
required |
handler
|
Callable[[EventContext], Awaitable[None]] | None
|
The callback to invoke. If omitted, returns a decorator. |
None
|
keys
|
list[str] | None
|
Restricts the handler to views whose key is in this
list. |
None
|
priority
|
int
|
Handlers with a higher priority run first. |
0
|
Source code in starlette_admin/events.py
subscribe(subscriber, *, keys=None)
Delegate all subscriptions declared by subscriber to matching view buses.
Source code in starlette_admin/events.py
unsubscribe(subscriber)
Remove all handlers from a subscriber across all buses.
Source code in starlette_admin/events.py
starlette_admin.events.EventBus
Per-view event bus. This is the only bus type that emits events directly;
AdminEventBus delegates lifecycle
events to the matching view's EventBus instead of emitting them itself.
Source code in starlette_admin/events.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
emit(ctx)
async
Fire all registered handlers in priority order.
Source code in starlette_admin/events.py
off(event, handler)
Remove a handler for an event.
Source code in starlette_admin/events.py
on(event, handler=None, *, priority=0)
Register a handler. Usable as a decorator or a direct call.
Source code in starlette_admin/events.py
subscribe(subscriber)
Register a subscriber object for multiple events at once.
Source code in starlette_admin/events.py
unsubscribe(subscriber)
Remove all handlers registered by a subscriber.
Source code in starlette_admin/events.py
starlette_admin.events.AdminEventSubscriber
Source code in starlette_admin/events.py
subscriptions()
Return event → handler(s) mapping.
The default implementation discovers methods decorated with @on.
Override to use the explicit dict API instead.
Source code in starlette_admin/events.py
starlette_admin.events.on(*events, priority=0)
Decorator that marks a subscriber method as a handler for one or more events.
Usage::
class MyHandler(AdminEventSubscriber):
@on(AdminEvent.BEFORE_CREATE, priority=10)
async def handle(self, ctx):
...
Source code in starlette_admin/events.py
starlette_admin.events.AdminEvent
Bases: StrEnum
Source code in starlette_admin/events.py
Event contexts
starlette_admin.events.EventContext
dataclass
starlette_admin.events.BeforeCreateContext
dataclass
starlette_admin.events.AfterCreateContext
dataclass
starlette_admin.events.BeforeEditContext
dataclass
starlette_admin.events.AfterEditContext
dataclass
starlette_admin.events.BeforeDeleteContext
dataclass
starlette_admin.events.AfterDeleteContext
dataclass
starlette_admin.events.BeforeBulkDeleteContext
dataclass
starlette_admin.events.AfterBulkDeleteContext
dataclass
starlette_admin.events.BeforeActionContext
dataclass
Bases: EventContext
selection.pks() (and .rows(), .count()) are async and resolved lazily:
call them from a handler only if you need the target rows, since a select-all
action can otherwise skip materializing them entirely.
Source code in starlette_admin/events.py
starlette_admin.events.AfterActionContext
dataclass
Bases: EventContext
See BeforeActionContext for selection's lazy-resolution contract.