quart.wrappers.request module

class quart.wrappers.request.Body(expected_content_length, max_content_length)

Bases: object

A request body container.

The request body can either be iterated over and consumed in parts (without building up memory usage) or awaited.

async for data in body:
    ...
# or simply
complete = await body

Note: It is not possible to iterate over the data and then await it.

Parameters:
  • expected_content_length (int | None)

  • max_content_length (int | None)

append(data)
Parameters:

data (bytes)

Return type:

None

set_complete()
Return type:

None

set_result(data)

Convenience method, mainly for testing.

Parameters:

data (bytes)

Return type:

None

clear()
Return type:

None

class quart.wrappers.request.Request(method, scheme, path, query_string, headers, root_path, http_version, scope, *, max_content_length=None, body_timeout=None, send_push_promise)

Bases: BaseRequestWebsocket

This class represents a request.

It can be subclassed and the subclassed used in preference by replacing the request_class with your subclass.

Parameters:
  • method (str)

  • scheme (str)

  • path (str)

  • query_string (bytes)

  • headers (Headers)

  • root_path (str)

  • http_version (str)

  • scope (HTTPScope)

  • max_content_length (int | None)

  • body_timeout (int | None)

  • send_push_promise (Callable[[str, Headers], Awaitable[None]])

body_class

The class to store the body data within.

form_data_parser_class

Can be overridden to implement a different form data parsing.

body_class

alias of Body

form_data_parser_class

alias of FormDataParser

lock_class

alias of Lock

property max_content_length: int | None
property max_form_memory_size: int | None
property max_form_parts: int | None
property stream: NoReturn
property data: bytes
async get_data(cache: bool, as_text: Literal[False], parse_form_data: bool) bytes
async get_data(cache: bool, as_text: Literal[True], parse_form_data: bool) str
async get_data(cache: bool = True, as_text: bool = False, parse_form_data: bool = False) str | bytes

Get the request body data.

Parameters:
  • cache – If False the body data will be cleared, resulting in any subsequent calls returning an empty str | bytes and reducing memory usage.

  • as_text – If True the data is returned as a decoded string, otherwise raw bytes are returned.

  • parse_form_data – Parse the data as form data first, return any remaining data.

property values: CombinedMultiDict
property form: MultiDict

The parsed form encoded data.

Note file data is present in the files.

property files: MultiDict

The parsed files.

This will return an empty multidict unless the request mimetype was enctype="multipart/form-data" and the method POST, PUT, or PATCH.

make_form_data_parser()
Return type:

FormDataParser

property json: Any
async get_json(force=False, silent=False, cache=True)

Parses the body data as JSON and returns it.

Parameters:
  • force (bool) – Force JSON parsing even if the mimetype is not JSON.

  • silent (bool) – Do not trigger error handling if parsing fails, without this the on_json_loading_failed() will be called on error.

  • cache (bool) – Cache the parsed JSON on this request object.

Return type:

Any

on_json_loading_failed(error)

Handle a JSON parsing error.

Parameters:

error (Exception) – The exception raised during parsing.

Returns:

Any value returned (if overridden) will be used as the default for any get_json calls.

Return type:

Any

async send_push_promise(path)
Parameters:

path (str)

Return type:

None

async close()
Return type:

None