starlite.types#

Callable types#

starlite.types.AfterExceptionHookHandler#

alias of Callable[[Exception, Union[HTTPScope, WebSocketScope], Any], Union[None, Awaitable[None]]]

starlite.types.AfterRequestHookHandler#

alias of Union[Callable[[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]]], Union[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]], Awaitable[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]]]]], Callable[[Any], Union[Any, Awaitable[Any]]]]

starlite.types.AfterResponseHookHandler#

alias of Callable[[Any], Union[None, Awaitable[None]]]

starlite.types.AnyCallable#

alias of Callable[[…], Any]

starlite.types.AsyncAnyCallable#

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

starlite.types.BeforeMessageSendHookHandler#

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

starlite.types.BeforeRequestHookHandler#

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

starlite.types.CacheKeyBuilder#

alias of Callable[[Any], str]

starlite.types.ExceptionHandler#

alias of Callable[[Any, _ExceptionT], Any]

starlite.types.Guard#

alias of Callable[[Any, Any], Union[None, Awaitable[None]]]

starlite.types.LifeSpanHandler#

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

starlite.types.LifeSpanHookHandler#

alias of Callable[[Any], Union[None, Awaitable[None]]]

starlite.types.OnAppInitHandler#

alias of Callable[[Any], Any]

starlite.types.Serializer#

alias of Callable[[Any], Any]

ASGI Types#

starlite.types.Method#

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

ASGI Application#

starlite.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#

starlite.types.Scope#

alias of Union[HTTPScope, WebSocketScope]

starlite.types.Receive#

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

starlite.types.Send#

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

ASGI Scopes#

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

ASGI spec version.

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

Base ASGI-scope.

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

WebSocket-ASGI-scope.

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

HTTP-ASGI-scope.

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

Lifespan-ASGI-scope.

ASGI Events#

class starlite.types.HTTPRequestEvent#

Bases: TypedDict

ASGI http.request event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.HTTPResponseStartEvent#

Bases: HeaderScope

ASGI http.response.start event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.HTTPResponseBodyEvent#

Bases: TypedDict

ASGI http.response.body event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.HTTPServerPushEvent#

Bases: HeaderScope

ASGI http.response.push event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.HTTPDisconnectEvent#

Bases: TypedDict

ASGI http.disconnect event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketConnectEvent#

Bases: TypedDict

ASGI websocket.connect event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketAcceptEvent#

Bases: HeaderScope

ASGI websocket.accept event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketReceiveEvent#

Bases: TypedDict

ASGI websocket.receive event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketSendEvent#

Bases: TypedDict

ASGI websocket.send event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketResponseStartEvent#

Bases: HeaderScope

ASGI websocket.http.response.start event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketResponseBodyEvent#

Bases: TypedDict

ASGI websocket.http.response.body event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketDisconnectEvent#

Bases: TypedDict

ASGI websocket.disconnect event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.WebSocketCloseEvent#

Bases: TypedDict

ASGI websocket.close event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanStartupEvent#

Bases: TypedDict

ASGI lifespan.startup event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanShutdownEvent#

Bases: TypedDict

ASGI lifespan.shutdown event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanStartupCompleteEvent#

Bases: TypedDict

ASGI lifespan.startup.complete event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanStartupFailedEvent#

Bases: TypedDict

ASGI lifespan.startup.failed event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanShutdownCompleteEvent#

Bases: TypedDict

ASGI lifespan.shutdown.complete event.

__init__(*args, **kwargs)#
__new__(**kwargs)#
class starlite.types.LifeSpanShutdownFailedEvent#

Bases: TypedDict

ASGI lifespan.shutdown.failed event.

__init__(*args, **kwargs)#
__new__(**kwargs)#

Event Groupings#

starlite.types.HTTPReceiveMessage#

alias of Union[HTTPRequestEvent, HTTPDisconnectEvent]

starlite.types.WebSocketReceiveMessage#

alias of Union[WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]

starlite.types.LifeSpanReceiveMessage#

alias of Union[LifeSpanStartupEvent, LifeSpanShutdownEvent]

starlite.types.HTTPSendMessage#

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

starlite.types.WebSocketSendMessage#

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

starlite.types.LifeSpanSendMessage#

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

starlite.types.LifeSpanReceive#

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

starlite.types.LifeSpanSend#

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

Send / Receive Parameter Types#

starlite.types.Message#

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

starlite.types.ReceiveMessage#

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

Helper Types#

Helper types are useful generic types that can be used.

starlite.types.SyncOrAsyncUnion#

alias of Union[T, Awaitable[T]]

starlite.types.SingleOrList#

alias of Union[T, List[T]]

Protocols#

class starlite.types.Logger#

Bases: Protocol

Logger protocol.

__init__(*args, **kwargs)#
__new__(**kwargs)#

Composite Types#

starlite.types.Dependencies#

alias of Dict[str, Any]

starlite.types.ExceptionHandlersMap#

alias of Dict[Union[int, Type[Exception]], Callable[[Any, _ExceptionT], Any]]

starlite.types.Middleware#

alias of Union[Callable[[…], 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]]], Any, Iterator[Tuple[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]], Dict[str, Any]]], Type[Any]]

starlite.types.ResponseCookies#

alias of List[Any]

starlite.types.ResponseHeadersMap#

alias of Dict[str, Any]

starlite.types.PathType#

alias of Union[Path, PathLike, str]

Partial types#

class starlite.types.Partial#

Bases: Generic[T]

Type generation for PATCH routes.

Partial is a special typing helper that takes a generic T, which must be a TypedDict, dataclass or pydantic model class, and returns to static type checkers a version of this T in which all fields - and nested fields - are optional.

classmethod __class_getitem__(item: Type[T]) Type[T]#

Take a pydantic model class, TypedDict or a dataclass and return an all optional version of that class.

Parameters:

item – A pydantic model, TypedDict or dataclass class.

Returns:

A pydantic model, TypedDict, or dataclass.

File types#

class starlite.types.FileInfo#

Bases: TypedDict

File information gathered from a file system.

created: float#

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

destination: Optional[bytes]#

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 starlite.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) Union[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) Union[IO[bytes], Awaitable['AsyncFile[bytes]']]#
open(file: PathType, mode: OpenTextMode, buffering: int = -1) Union[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.