faust.web.base

Base interface for Web server and views.

class faust.web.base.Response[source]

Web server response and status.

abstract property status

Return the response status code. :rtype: int

abstract property body

Return the response body as bytes. :rtype: bytes

abstract property headers

Return mapping of response HTTP headers. :rtype: MutableMapping[~KT, ~VT]

abstract property content_length

Return the size of the response body. :rtype: Optional[int]

abstract property content_type

Return the response content type. :rtype: str

abstract property charset

Return the response character set. :rtype: Optional[str]

abstract property chunked

Return True if response is chunked. :rtype: bool

abstract property compression

Return True if the response body is compressed. :rtype: bool

abstract property keep_alive

Return True if HTTP keep-alive enabled. :rtype: Optional[bool]

abstract property body_length

Size of HTTP response body. :rtype: int

class faust.web.base.BlueprintManager(initial: Iterable[Tuple[str, Union[_T, str]]] = None) → None[source]

Manager of all blueprints.

add(prefix: str, blueprint: Union[_T, str]) → None[source]

Register blueprint with this app.

Return type

None

apply(web: faust.web.base.Web) → None[source]

Apply all blueprints.

Return type

None

class faust.web.base.Web(app: faust.types.app.AppT, **kwargs: Any) → None[source]

Web server and HTTP interface.

default_blueprints = [('/router', 'faust.web.apps.router:blueprint'), ('/table', 'faust.web.apps.tables.blueprint')]
production_blueprints = [('', 'faust.web.apps.production_index:blueprint')]
debug_blueprints = [('/graph', 'faust.web.apps.graph:blueprint'), ('', 'faust.web.apps.stats:blueprint')]
content_separator = b'\r\n\r\n'
header_separator = b'\r\n'
header_key_value_separator = b': '
abstract text(value: str, *, content_type: str = None, status: int = 200, reason: str = None, headers: MutableMapping = None) → faust.web.base.Response[source]

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

Return type

Response

abstract html(value: str, *, content_type: str = None, status: int = 200, reason: str = None, headers: MutableMapping = None) → faust.web.base.Response[source]

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

Return type

Response

abstract json(value: Any, *, content_type: str = None, status: int = 200, reason: str = None, headers: MutableMapping = None) → faust.web.base.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

abstract bytes(value: bytes, *, content_type: str = None, status: int = 200, reason: str = None, headers: MutableMapping = None) → faust.web.base.Response[source]

Create new bytes response - for binary data.

Return type

Response

abstract bytes_to_response(s: bytes) → faust.web.base.Response[source]

Deserialize HTTP response from byte string.

Return type

Response

abstract response_to_bytes(response: faust.web.base.Response) → bytes[source]

Serialize HTTP response into byte string.

Return type

bytes

abstract route(pattern: str, handler: Callable, cors_options: Mapping[str, faust.types.web.ResourceOptions] = None) → None[source]

Add route for handler.

Return type

None

abstract add_static(prefix: str, path: Union[pathlib.Path, str], **kwargs: Any) → None[source]

Add static route.

Return type

None

abstract async read_request_content(request: faust.web.base.Request) → bytes[source]

Read HTTP body as bytes.

Return type

bytes

abstract async wsgi() → Any[source]

WSGI entry point.

Return type

Any

add_view(view_cls: Type[faust.types.web.View], *, prefix: str = '', cors_options: Mapping[str, faust.types.web.ResourceOptions] = None) → faust.types.web.View[source]

Add route for view.

Return type

View

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

Get URL by view name.

If the provided view name has associated URL parameters, those need to be passed in as kwargs, or a TypeError will be raised.

Return type

str

init_server() → None[source]

Initialize and setup web server.

Return type

None

property url

Return the canonical URL to this worker (including port). :rtype: URL

logger = <Logger faust.web.base (WARNING)>
class faust.web.base.Request(*args, **kwargs)[source]

HTTP Request.

abstract can_read_body() → bool[source]

Return True if the request has a body.

Return type

bool

abstract async read() → bytes[source]

Read post data as bytes.

Return type

bytes

abstract async text() → str[source]

Read post data as text.

Return type

str

abstract async json() → Any[source]

Read post data and deserialize as JSON.

Return type

Any

abstract async post() → Mapping[str, str][source]

Read post data.

Return type

Mapping[str, str]

abstract property match_info

Return match info from URL route as a mapping. :rtype: Mapping[str, str]

abstract property query

Return HTTP query parameters as a mapping. :rtype: Mapping[str, str]

abstract property cookies

Return cookies as a mapping. :rtype: Mapping[str, Any]