# quart.wrappers package

## Submodules

- quart.wrappers.base module
  - `BaseRequestWebsocket`
    - `BaseRequestWebsocket.json_module`
    - `BaseRequestWebsocket.routing_exception`
    - `BaseRequestWebsocket.url_rule`
    - `BaseRequestWebsocket.view_args`
    - `BaseRequestWebsocket.json_module`
    - `BaseRequestWebsocket.routing_exception`
    - `BaseRequestWebsocket.url_rule`
    - `BaseRequestWebsocket.view_args`
    - `BaseRequestWebsocket.endpoint`
    - `BaseRequestWebsocket.blueprint`
    - `BaseRequestWebsocket.blueprints`
    - `BaseRequestWebsocket.script_root`
    - `BaseRequestWebsocket.url_root`
- quart.wrappers.request module
  - `Body`
    - `Body.append()`
    - `Body.set_complete()`
    - `Body.set_result()`
    - `Body.clear()`
  - `Request`
    - `Request.body_class`
    - `Request.form_data_parser_class`
    - `Request.body_class`
    - `Request.form_data_parser_class`
    - `Request.lock_class`
    - `Request.max_content_length`
    - `Request.max_form_memory_size`
    - `Request.max_form_parts`
    - `Request.stream`
    - `Request.data`
    - `Request.get_data()`
    - `Request.values`
    - `Request.form`
    - `Request.files`
    - `Request.make_form_data_parser()`
    - `Request.json`
    - `Request.get_json()`
    - `Request.on_json_loading_failed()`
    - `Request.send_push_promise()`
    - `Request.close()`
- quart.wrappers.response module
  - `ResponseBody`
  - `DataBody`
    - `DataBody.make_conditional()`
  - `IterableBody`
  - `FileBody`
    - `FileBody.buffer_size`
    - `FileBody.buffer_size`
    - `FileBody.make_conditional()`
  - `IOBody`
    - `IOBody.buffer_size`
    - `IOBody.buffer_size`
    - `IOBody.make_conditional()`
  - `Response`
    - `Response.automatically_set_content_length`
    - `Response.default_status`
    - `Response.default_mimetype`
    - `Response.implicit_sequence_conversion`
    - `Response.automatically_set_content_length`
    - `Response.default_mimetype`
    - `Response.data_body_class`
    - `Response.file_body_class`
    - `Response.implicit_sequence_conversion`
    - `Response.io_body_class`
    - `Response.iterable_body_class`
    - `Response.json_module`
    - `Response.timeout`
    - `Response.response`
    - `Response.max_cookie_size`
    - `Response.get_data()`
    - `Response.set_data()`
    - `Response.data`
    - `Response.json`
    - `Response.headers`
    - `Response.get_json()`
    - `Response.make_conditional()`
    - `Response.make_sequence()`
    - `Response.iter_encode()`
    - `Response.freeze()`
    - `Response.add_etag()`
- quart.wrappers.websocket module
  - `Websocket`
    - `Websocket.requested_subprotocols`
    - `Websocket.receive()`
    - `Websocket.send()`
    - `Websocket.receive_json()`
    - `Websocket.send_json()`
    - `Websocket.accept()`
    - `Websocket.close()`

## Module contents

class quart.wrappers.BaseRequestWebsocket(method, scheme, path, query_string, headers, root_path, http_version, scope)

  Bases: `Request`

  This class is the basis for Requests and websockets..

  Parameters:

    - method (str)

    - scheme (str)

    - path (str)

    - query_string (bytes)

    - headers (Headers)

    - root_path (str)

    - http_version (str)

    - scope (WWWScope)

  json_module

    A custom json decoding/encoding module, it should have `dump`, `dumps`, `load`, and `loads` methods

    Type:

      json.provider.JSONProvider

  routing_exception

    If an exception is raised during the route matching it will be stored here.

    Type:

      Exception | None

  url_rule

    The rule that this request has been matched too.

    Type:

      QuartRule | None

  view_args

    The keyword arguments for the view from the route matching.

    Type:

      dict[str, Any] | None

  property blueprint: str | None

    Returns the blueprint the matched endpoint belongs to.

    This can be None if the request has not been matched or the endpoint is not in a blueprint.

  property blueprints: list[str]

    Return the names of the current blueprints. The returned list is ordered from the current blueprint, upwards through parent blueprints.

  property endpoint: str | None

    Returns the corresponding endpoint matched for this request.

    This can be None if the request has not been matched with a rule.

  json_module: json.provider.JSONProvider = <module 'quart.json' from '/build/quart-TuyuY7/quart-0.20.0/.pybuild/cpython3_3.14_quart/build/quart/json/__init__.py'>
  routing_exception: Exception | None = None
  property script_root: str
  property url_root: str
  url_rule: QuartRule | None = None
  view_args: dict[str, Any] | None = None

class quart.wrappers.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

  clear()
    Return type:

      None

  set_complete()
    Return type:

      None

  set_result(data)

    Convenience method, mainly for testing.

    Parameters:

      data (bytes)

    Return type:

      None

class quart.wrappers.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`

  async close()
    Return type:

      None

  property data: bytes
  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.

  property form: MultiDict

    The parsed form encoded data.

    Note file data is present in the `files`.

  form_data_parser_class

    alias of `FormDataParser`

  async get_data(cache=True, as_text=False, parse_form_data=False)

    Get the request body data.

    Parameters:

      - cache (bool) – If False the body data will be cleared, resulting in any subsequent calls returning an empty str | bytes and reducing memory usage.

      - as_text (bool) – If True the data is returned as a decoded string, otherwise raw bytes are returned.

      - parse_form_data (bool) – Parse the data as form data first, return any remaining data.

    Return type:

      str | bytes

  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

  property json: Any
  lock_class

    alias of `Lock`

  make_form_data_parser()
    Return type:

      FormDataParser

  property max_content_length: int | None
  property max_form_memory_size: int | None
  property max_form_parts: int | None
  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

  property stream: NoReturn
  property values: CombinedMultiDict

class quart.wrappers.Response(response=None, status=None, headers=None, mimetype=None, content_type=None)

  Bases: `Response`

  This class represents a response.

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

  Parameters:

    - response (ResponseBody | str | bytes | Iterable | AsyncIterable | None)

    - status (int | None)

    - headers (Headers)

    - mimetype (str | None)

    - content_type (str | None)

  automatically_set_content_length

    If False the content length header must be provided.

  default_status

    The status code to use if not provided.

  default_mimetype

    The mimetype to use if not provided.

    Type:

      str | None

  implicit_sequence_conversion

    Implicitly convert the response to a iterable in the get_data method, to allow multiple iterations.

  async add_etag(overwrite=False, weak=False)
    Parameters:

      - overwrite (bool)

      - weak (bool)

    Return type:

      None

  automatically_set_content_length = True
  property data: bytes
  data_body_class

    alias of `DataBody`

  default_mimetype: str | None = 'text/html'

    the default mimetype if none is provided.

  file_body_class

    alias of `FileBody`

  async freeze()

    Freeze this object ready for pickling.

    Return type:

      None

  async get_data(as_text=False)

    Return the body data.

    Parameters:

      as_text (bool)

    Return type:

      str | bytes

  async get_json(force=False, silent=False)

    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.

    Return type:

      Any

  implicit_sequence_conversion = True
  io_body_class

    alias of `IOBody`

  async iter_encode()
    Return type:

      AsyncGenerator[bytes, None]

  iterable_body_class

    alias of `IterableBody`

  property json: Any
  json_module = <module 'quart.json' from '/build/quart-TuyuY7/quart-0.20.0/.pybuild/cpython3_3.14_quart/build/quart/json/__init__.py'>
  async make_conditional(request, accept_ranges=False, complete_length=None)
    Parameters:

      - request (Request)

      - accept_ranges (bool | str)

      - complete_length (int | None)

    Return type:

      Response

  async make_sequence()
    Return type:

      None

  property max_cookie_size: int

    int([x]) -> integer int(x, base=10) -> integer

    Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

    If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

  set_data(data)

    Set the response data.

    This will encode using the `charset`.

    Parameters:

      data (str | bytes)

    Return type:

      None

class quart.wrappers.Websocket(path, query_string, scheme, headers, root_path, http_version, subprotocols, receive, send, accept, close, scope)

  Bases: `BaseRequestWebsocket`

  Parameters:

    - path (str)

    - query_string (bytes)

    - scheme (str)

    - headers (Headers)

    - root_path (str)

    - http_version (str)

    - subprotocols (list[str])

    - receive (Callable)

    - send (Callable)

    - accept (Callable)

    - close (Callable)

    - scope (WebsocketScope)

  async accept(headers=None, subprotocol=None)

    Manually chose to accept the websocket connection.

    Parameters:

      - headers (dict | Headers | None) – Additional headers to send with the acceptance response.

      - subprotocol (str | None) – The chosen subprotocol, optional.

    Return type:

      None

  async close(code, reason='')
    Parameters:

      - code (int)

      - reason (str)

    Return type:

      None

  async receive()
    Return type:

      AnyStr

  async receive_json()
    Return type:

      Any

  property requested_subprotocols: list[str]
  async send(data)
    Parameters:

      data (AnyStr)

    Return type:

      None

  async send_json(*args, **kwargs)
    Parameters:

      - args (Any)

      - kwargs (Any)

    Return type:

      None