Skip to content

Lifespan scope and messages

Use these mappings for application startup and shutdown events in the ASGI lifespan protocol.

LifespanScope

Bases: TypedDict

A lifespan scope in Scope.

typeinstance-attribute

type: Literal['lifespan']

asgiinstance-attribute

stateinstance-attribute

state: State

LifespanStartup

Bases: TypedDict

A lifespan startup event in ReceiveMessage.

typeinstance-attribute

type: Literal['lifespan.startup']

LifespanShutdown

Bases: TypedDict

A lifespan shutdown event in ReceiveMessage.

typeinstance-attribute

type: Literal['lifespan.shutdown']

LifespanStartupComplete

Bases: TypedDict

A lifespan startup-complete event in SendMessage.

typeinstance-attribute

type: Literal['lifespan.startup.complete']

LifespanStartupFailed

Bases: TypedDict

A lifespan startup-failed event in SendMessage.

typeinstance-attribute

type: Literal['lifespan.startup.failed']

messageinstance-attribute

message: NotRequired[str]

LifespanShutdownComplete

Bases: TypedDict

A lifespan shutdown-complete event in SendMessage.

typeinstance-attribute

type: Literal['lifespan.shutdown.complete']

LifespanShutdownFailed

Bases: TypedDict

A lifespan shutdown-failed event in SendMessage.

typeinstance-attribute

type: Literal['lifespan.shutdown.failed']

messageinstance-attribute

message: NotRequired[str]