LitServe icon indicating copy to clipboard operation
LitServe copied to clipboard

Feat: Add support for fastapi lifespan events

Open robTheBuildr opened this issue 9 months ago • 5 comments

🚀 Feature

Add the ability for developers to customize the FastAPI lifespan, startup, and 'shutdown` event handlers.

Motivation

Users can use this to setup logging or resource management.

Pitch

There are 2 options here.

  1. Add a function attach_event_handler(event: str, func: Callable) which takes either 'lifespan', 'startup' or 'shutdown' as the event and applies the given logic.

  2. More explicit and abstracting away FastAPI Lifespan event knowledge from the user, add during_lifespan(func: Callable), on_startup(func: Callable), and on_shutdown(func: Callable) that the user can call on Server to apply these lifespan handlers.

Alternatives

Add custom template startup and shutdown event handler for logging and resource management. This will get cumbersome.

Additional context

robTheBuildr avatar May 23 '24 14:05 robTheBuildr