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.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’.
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.BaseScope#
Bases:
HeaderScope
Base ASGI-scope.
ASGI Events#
- class litestar.types.HTTPResponseStartEvent#
Bases:
HeaderScope
ASGI http.response.start event.
- class litestar.types.HTTPServerPushEvent#
Bases:
HeaderScope
ASGI http.response.push event.
- class litestar.types.WebSocketAcceptEvent#
Bases:
HeaderScope
ASGI websocket.accept 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.LifeSpanStartupCompleteEvent#
Bases:
TypedDict
ASGI lifespan.startup.complete event.
- class litestar.types.LifeSpanStartupFailedEvent#
Bases:
TypedDict
ASGI lifespan.startup.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.
Protocols#
- class litestar.types.Logger#
Bases:
Protocol
Logger protocol.
- 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.
- 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.
- type: Literal['file', 'directory', 'other']#
The type of the file system object.
- 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.
- 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.