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 = 'Callable[[ASGIApp], SyncOrAsyncUnion[ASGIApp]] | Callable[[Response], SyncOrAsyncUnion[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.AfterResponseHookHandler = 'Callable[[Request], 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.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 = 'Callable[[ASGIConnection, BaseRouteHandler], 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.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#

litestar.types.ASGIVersion = <class 'litestar.types.asgi_types.ASGIVersion'>#

ASGI spec version.

litestar.types.BaseScope = <class 'litestar.types.asgi_types.BaseScope'>#

Base ASGI-scope.

litestar.types.HTTPScope = <class 'litestar.types.asgi_types.HTTPScope'>#

HTTP-ASGI-scope.

litestar.types.LifeSpanScope = <class 'litestar.types.asgi_types.LifeSpanScope'>#

Lifespan-ASGI-scope.

litestar.types.WebSocketScope = <class 'litestar.types.asgi_types.WebSocketScope'>#

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 = 'Union[Callable[..., ASGIApp], DefineMiddleware, Iterator[Tuple[ASGIApp, Dict[str, Any]]], Type[MiddlewareProtocol]]'#

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.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]

File types#

class litestar.types.FileInfo#

Bases: TypedDict

File information gathered from a file system.

created: float#

Created time stamp, equal to ‘stat_result.st_ctime’.

destination: NotRequired[bytes | None]#

Output of loading a symbolic link.

gid: int#

Group ID of owner.

ino: int#

inode value.

True if the file is a symbolic link.

mode: int#

Protection mode.

mtime: float#

Modified time stamp.

name: str#

The path of the file.

Number of hard links.

size: int#

Total size, in bytes.

type: Literal['file', 'directory', 'other']#

The type of the file system object.

uid: int#

User ID of owner.

class litestar.types.FileSystemProtocol#

Bases: Protocol

Base protocol used to interact with a file-system.

This protocol is commensurable with the file systems exported by the fsspec <https://filesystem-spec.readthedocs.io/en/latest/> library.

__init__(*args, **kwargs)#
info(path: PathType, **kwargs: Any) FileInfo | Awaitable[FileInfo]#

Retrieve information about a given file path.

Parameters:
  • path – A file path.

  • **kwargs – Any additional kwargs.

Returns:

A dictionary of file info.

open(file: PathType, mode: OpenBinaryMode, buffering: int = -1) IO[bytes] | Awaitable[AsyncFile[bytes]]#
open(file: PathType, mode: OpenTextMode, buffering: int = -1) IO[str] | Awaitable[AsyncFile[str]]

Return a file-like object from the filesystem.

Notes

  • The return value must function correctly in a context with block.

Parameters:
  • file – Path to the target file.

  • mode – Mode, similar to the built open.

  • buffering – Buffer size.