types

Callable types

litestar.types.AfterExceptionHookHandler = 'Callable[[ExceptionT, Scope], SyncOrAsyncUnion[None]]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.AfterRequestHookHandler = 'AsyncAfterRequestHookHandler | SyncAfterRequestHookHandler'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.AfterResponseHookHandler = 'AsyncAfterResponseHookHandler | SyncAfterResponseHookHandler'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.AnyCallable

alias of Callable[[…], Any]

litestar.types.AsyncAnyCallable

alias of Callable[[…], Awaitable[Any]]

litestar.types.BeforeMessageSendHookHandler = 'Callable[[Message, Scope], SyncOrAsyncUnion[None]]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.BeforeRequestHookHandler = 'Callable[[Request], Any | Awaitable[Any]]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.CacheKeyBuilder = 'Callable[[Request], str]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.ExceptionHandler = 'Callable[[Request, ExceptionT], Response]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.Guard = 'AsyncGuard | SyncGuard'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.LifespanHook = 'Callable[[Litestar], SyncOrAsyncUnion[Any]] | Callable[[], SyncOrAsyncUnion[Any]]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.OnAppInitHandler = 'Callable[[AppConfig], AppConfig]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.Serializer

alias of Callable[[Any], Any]

ASGI Types

litestar.types.Method

alias of Union[Literal[‘GET’, ‘POST’, ‘DELETE’, ‘PATCH’, ‘PUT’, ‘HEAD’, ‘TRACE’, ‘OPTIONS’], HttpMethod]

ASGI Application

litestar.types.ASGIApp

alias of Callable[[Union[HTTPScope, WebSocketScope], Callable[[…], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]], Awaitable[None]]], Awaitable[None]]

ASGI Application Parameters

litestar.types.Scope

alias of Union[HTTPScope, WebSocketScope]

litestar.types.Receive

alias of Callable[[…], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]]]

litestar.types.Send

alias of Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]], Awaitable[None]]

ASGI Scopes

class litestar.types.ASGIVersion

Bases: TypedDict

ASGI spec version.

class litestar.types.BaseScope

Bases: HeaderScope

Base ASGI-scope.

class litestar.types.HTTPScope

Bases: BaseScope

HTTP-ASGI-scope.

class litestar.types.LifeSpanScope

Bases: TypedDict

Lifespan-ASGI-scope.

class litestar.types.WebSocketScope

Bases: BaseScope

WebSocket-ASGI-scope.

ASGI Events

class litestar.types.HTTPRequestEvent

Bases: TypedDict

ASGI http.request event.

class litestar.types.HTTPResponseStartEvent

Bases: HeaderScope

ASGI http.response.start event.

class litestar.types.HTTPResponseBodyEvent

Bases: TypedDict

ASGI http.response.body event.

class litestar.types.HTTPServerPushEvent

Bases: HeaderScope

ASGI http.response.push event.

class litestar.types.HTTPDisconnectEvent

Bases: TypedDict

ASGI http.disconnect event.

class litestar.types.WebSocketConnectEvent

Bases: TypedDict

ASGI websocket.connect event.

class litestar.types.WebSocketAcceptEvent

Bases: HeaderScope

ASGI websocket.accept event.

class litestar.types.WebSocketReceiveEvent

Bases: TypedDict

ASGI websocket.receive event.

class litestar.types.WebSocketSendEvent

Bases: TypedDict

ASGI websocket.send event.

class litestar.types.WebSocketResponseStartEvent

Bases: HeaderScope

ASGI websocket.http.response.start event.

class litestar.types.WebSocketResponseBodyEvent

Bases: TypedDict

ASGI websocket.http.response.body event.

class litestar.types.WebSocketDisconnectEvent

Bases: TypedDict

ASGI websocket.disconnect event.

class litestar.types.WebSocketCloseEvent

Bases: TypedDict

ASGI websocket.close event.

class litestar.types.LifeSpanStartupEvent

Bases: TypedDict

ASGI lifespan.startup event.

class litestar.types.LifeSpanShutdownEvent

Bases: TypedDict

ASGI lifespan.shutdown event.

class litestar.types.LifeSpanStartupCompleteEvent

Bases: TypedDict

ASGI lifespan.startup.complete event.

class litestar.types.LifeSpanStartupFailedEvent

Bases: TypedDict

ASGI lifespan.startup.failed event.

class litestar.types.LifeSpanShutdownCompleteEvent

Bases: TypedDict

ASGI lifespan.shutdown.complete event.

class litestar.types.LifeSpanShutdownFailedEvent

Bases: TypedDict

ASGI lifespan.shutdown.failed event.

Event Groupings

litestar.types.HTTPReceiveMessage

alias of Union[HTTPRequestEvent, HTTPDisconnectEvent]

litestar.types.WebSocketReceiveMessage

alias of Union[WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]

litestar.types.LifeSpanReceiveMessage

alias of Union[LifeSpanStartupEvent, LifeSpanShutdownEvent]

litestar.types.HTTPSendMessage

alias of Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent]

litestar.types.WebSocketSendMessage

alias of Union[WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]

litestar.types.LifeSpanSendMessage

alias of Union[LifeSpanStartupCompleteEvent, LifeSpanStartupFailedEvent, LifeSpanShutdownCompleteEvent, LifeSpanShutdownFailedEvent]

litestar.types.LifeSpanReceive

alias of Callable[[…], Awaitable[Union[LifeSpanStartupEvent, LifeSpanShutdownEvent]]]

litestar.types.LifeSpanSend

alias of Callable[[Union[LifeSpanStartupCompleteEvent, LifeSpanStartupFailedEvent, LifeSpanShutdownCompleteEvent, LifeSpanShutdownFailedEvent]], Awaitable[None]]

Send / Receive Parameter Types

litestar.types.Message

alias of Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]

litestar.types.ReceiveMessage

alias of Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]

Helper Types

Helper types are useful generic types that can be used.

litestar.types.SyncOrAsyncUnion

alias of Union[T, Awaitable[T]]

litestar.types.AnyIOBackend

alias of Literal[‘asyncio’, ‘trio’]

litestar.types.OptionalSequence

alias of Optional[Sequence[T]]

Protocols

class litestar.types.Logger

Bases: Protocol

Logger protocol.

debug(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘DEBUG’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

info(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘INFO’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

warning(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘WARNING’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

warn(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘WARN’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

error(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘ERROR’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

fatal(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘FATAL’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

exception(event: str, *args: Any, **kwargs: Any) Any

Log a message with level ‘ERROR’ on this logger. The arguments are interpreted as for debug(). Exception info is added to the logging message.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

critical(event: str, *args: Any, **kwargs: Any) Any

Output a log message at ‘INFO’ level.

Parameters:
  • event – Log message.

  • *args – Any args.

  • **kwargs – Any kwargs.

setLevel(level: int) None

Set the log level

Parameters:

level – Log level to set as an integer

Returns:

None

__init__(*args, **kwargs)

Composite Types

litestar.types.Dependencies

alias of Mapping[str, Union[Provide, AnyCallable]]

litestar.types.ExceptionHandlersMap

alias of MutableMapping[Union[int, type[Exception]], ExceptionHandler]

litestar.types.Middleware

alias of Callable[[…], ASGIApp]

litestar.types.ResponseCookies

alias of Union[Sequence[Cookie], Mapping[str, str]]

litestar.types.ResponseHeaders

alias of Union[Sequence[ResponseHeader], Mapping[str, str]]

litestar.types.PathType

alias of Union[Path, PathLike, str]

litestar.types.Scopes = 'set[Literal[ScopeType.HTTP, ScopeType.WEBSOCKET]]'

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

litestar.types.TypeEncodersMap

alias of Mapping[Any, Callable[[Any], Any]]

litestar.types.TypeDecodersSequence

alias of Sequence[tuple[Callable[[Any], bool], Callable[[Any, Any], Any]]]

litestar.types.ParametersMap

alias of Mapping[str, ParameterKwarg]