faust.web.views

Class-based views.

class faust.web.views.View(app: AppT, web: Web)[source]

Web view (HTTP endpoint).

exception ServerError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

Internal Server Error (500).

code: int = 500
detail: str = 'Internal server error.'
extra_context: Dict
exception ValidationError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

Invalid input in POST data (400).

code: int = 400
detail: str = 'Invalid input.'
extra_context: Dict
exception ParseError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

Malformed request (400).

code: int = 400
detail: str = 'Malformed request.'
extra_context: Dict
exception NotAuthenticated(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

Authentication credentials were not provided (401).

code: int = 401
detail: str = 'Authentication credentials were not provided.'
extra_context: Dict
exception PermissionDenied(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

No permission to perform action (403).

code: int = 403
detail: str = 'You do not have permission to perform this action.'
extra_context: Dict
exception NotFound(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)

Resource not found (404).

code: int = 404
detail: str = 'Not found.'
extra_context: Dict
view_name: str
view_path: str
classmethod from_handler(fun: Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]) Type[View][source]

Decorate async def handler function to create view.

Return type:

_GenericAlias[View]

methods: Mapping[str, Callable[[Request], Awaitable]]
get_methods() Set[source]

Return the supported methods for this view

Return type:

_SpecialGenericAlias

async dispatch(request: Any) Any[source]

Dispatch the request and perform any callbacks/cleanup.

Return type:

Any

async on_request_error(request: Request, exc: WebError) Response[source]

Call when a request raises an exception.

Return type:

Response

path_for(view_name: str, **kwargs: Any) str[source]

Return the URL path for view by name.

Supports match keyword arguments.

Return type:

str

url_for(view_name: str, _base_url: Optional[Union[str, URL]] = None, **kwargs: Any) URL[source]

Return the canonical URL for view by name.

Supports match keyword arguments. Can take optional base name, which if not set will be the canonical URL of the app.

Return type:

URL

async head(request: Request, **kwargs: Any) Any[source]

Override head to define the HTTP HEAD handler.

async get(request: Request, **kwargs: Any) Any[source]

Override get to define the HTTP GET handler.

async post(request: Request, **kwargs: Any) Any[source]

Override post to define the HTTP POST handler.

async put(request: Request, **kwargs: Any) Any[source]

Override put to define the HTTP PUT handler.

async patch(request: Request, **kwargs: Any) Any[source]

Override patch to define the HTTP PATCH handler.

async delete(request: Request, **kwargs: Any) Any[source]

Override delete to define the HTTP DELETE handler.

async options(request: Request, **kwargs: Any) Any[source]

Override options to define the HTTP OPTIONS handler.

async search(request: Request, **kwargs: Any) Any[source]

Override search to define the HTTP SEARCH handler.

text(value: str, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response[source]

Create text response, using “text/plain” content-type.

Return type:

Response

html(value: str, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response[source]

Create HTML response from string, text/html content-type.

Return type:

Response

json(value: Any, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response[source]

Create new JSON response.

Accepts any JSON-serializable value and will automatically serialize it for you.

The content-type is set to “application/json”.

Return type:

Response

bytes(value: bytes, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response[source]

Create new bytes response - for binary data.

Return type:

Response

async read_request_content(request: Request) bytes[source]

Return the request body as bytes.

Return type:

bytes

bytes_to_response(s: bytes) Response[source]

Deserialize byte string back into a response object.

Return type:

Response

response_to_bytes(response: Response) bytes[source]

Convert response to serializable byte string.

The result is a byte string that can be deserialized using bytes_to_response().

Return type:

bytes

route(pattern: str, handler: Callable) Any[source]

Create new route from pattern and handler.

Return type:

Any

notfound(reason: str = 'Not Found', **kwargs: Any) Response[source]

Create not found error response.

Deprecated: Use raise self.NotFound() instead.

Return type:

Response

error(status: int, reason: str, headers: Optional[MutableMapping] = None, **kwargs: Any) Response[source]

Create error JSON response.

Return type:

Response

faust.web.views.gives_model(Model: Type[ModelT]) Callable[[Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]], Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]][source]

Decorate view function to automatically decode POST data.

The POST data is decoded using the model you specify.

Return type:

_CallableGenericAlias[_UnionGenericAlias[_CallableGenericAlias[View, Request, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]], _CallableGenericAlias[View, Request, Any, Any, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]]], _UnionGenericAlias[_CallableGenericAlias[View, Request, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]], _CallableGenericAlias[View, Request, Any, Any, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]]]]

faust.web.views.takes_model(Model: Type[ModelT]) Callable[[Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]], Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]][source]

Decorate view function to return model data.

Return type:

_CallableGenericAlias[_UnionGenericAlias[_CallableGenericAlias[View, Request, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]], _CallableGenericAlias[View, Request, Any, Any, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]]], _UnionGenericAlias[_CallableGenericAlias[View, Request, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]], _CallableGenericAlias[View, Request, Any, Any, _UnionGenericAlias[_GenericAlias[Any, Any, Response], _GenericAlias[Response]]]]]