package documentation

Undocumented

Module api No module docstring; 0/1 variable, 2/5 functions documented
Module auth No module docstring; 2/2 functions, 2/2 classes documented
Module client No module docstring; 0/1 constant, 4/9 functions, 0/3 class documented
Module multipart No module docstring; 0/1 constant, 3/4 functions, 3/3 classes documented
Module response No module docstring; 1/1 class documented
Package test No package docstring; 1/10 module, 0/1 package documented
Module testing In-memory version of treq for testing.
Module _agentspy No module docstring; 1/1 function, 2/2 classes documented
Module _version Provides treq version information.

From __init__.py:

Function collect Incrementally collect the body of the response.
Function content Read the contents of an HTTP response.
Function delete Make a ``DELETE`` request.
Function get Make a ``GET`` request.
Function head Make a ``HEAD`` request.
Function json_content Read the contents of an HTTP response and attempt to decode it as JSON.
Function patch Make a ``PATCH`` request.
Function post Make a ``POST`` request.
Function put Make a ``PUT`` request.
Function request Make an HTTP request.
Function text_content Read the contents of an HTTP response and decode it with an appropriate charset, which may be guessed from the ``Content-Type`` header.
Variable __version__ Undocumented
def content(response): (source)

Read the contents of an HTTP response. This function may be called multiple times for a response, it uses a ``WeakKeyDictionary`` to cache the contents of the response. :param IResponse response: The HTTP Response to get the contents of. :rtype: Deferred that fires with the content as a str.

def head(url, **kwargs): (source)

Make a ``HEAD`` request. See :py:func:`treq.request`

def get(url, headers=None, **kwargs): (source)

Make a ``GET`` request. See :py:func:`treq.request`

def post(url, data=None, **kwargs): (source)

Make a ``POST`` request. See :py:func:`treq.request`

def put(url, data=None, **kwargs): (source)

Make a ``PUT`` request. See :py:func:`treq.request`

def patch(url, data=None, **kwargs): (source)

Make a ``PATCH`` request. See :py:func:`treq.request`

def delete(url, **kwargs): (source)

Make a ``DELETE`` request. See :py:func:`treq.request`

def request(method, url, **kwargs): (source)

Make an HTTP request. :param str method: HTTP method. Example: ``'GET'``, ``'HEAD'``. ``'PUT'``, ``'POST'``. :param url: http or https URL, which may include query arguments. :type url: :class:`hyperlink.DecodedURL`, `str`, `bytes`, or :class:`hyperlink.EncodedURL` :param headers: Optional HTTP Headers to send with this request. :type headers: :class:`~twisted.web.http_headers.Headers` or None :param params: Optional parameters to be append to the URL query string. Any query string parameters in the *url* will be preserved. :type params: dict w/ str or list/tuple of str values, list of 2-tuples, or None. :param data: Arbitrary request body data. If *files* is also passed this must be a :class:`dict`, a :class:`tuple` or :class:`list` of field tuples as accepted by :class:`MultiPartProducer`. The request is assigned a Content-Type of ``multipart/form-data``. If a :class:`dict`, :class:`list`, or :class:`tuple` it is URL-encoded and the request assigned a Content-Type of ``application/x-www-form-urlencoded``. Otherwise, any non-``None`` value is passed to the client's *data_to_body_producer* callable (by default, :class:`IBodyProducer`), which accepts :class:`bytes` and binary files like returned by ``open(..., "rb")``. :type data: `bytes`, `typing.BinaryIO`, `IBodyProducer`, or `None` :param files: Files to include in the request body, in any of the several formats: - ``[("fieldname", binary_file)]`` - ``[("fieldname", "filename", binary_file)]`` - ``[("fieldname, "filename', "content-type", binary_file)]`` Or a mapping: - ``{"fieldname": binary_file}`` - ``{"fieldname": ("filename", binary_file)}`` - ``{"fieldname": ("filename", "content-type", binary_file)}`` Each ``binary_file`` is a file-like object open in binary mode (like returned by ``open("filename", "rb")``). The filename is taken from the file's ``name`` attribute if not specified. The Content-Type is guessed based on the filename using :func:`mimetypes.guess_type()` if not specified, falling back to ``application/octet-stream``. While uploading Treq will measure the length of seekable files to populate the Content-Length header of the file part. If *files* is given the request is assigned a Content-Type of ``multipart/form-data``. Additional fields may be given in the *data* argument. :param json: Optional JSON-serializable content for the request body. Mutually exclusive with *data* and *files*. :type json: `dict`, `list`, `tuple`, `int`, `str`, `bool`, or `None` :param auth: HTTP Basic Authentication information --- see :func:`treq.auth.add_auth`. :type auth: tuple of ``('username', 'password')`` :param cookies: Cookies to send with this request. The HTTP kind, not the tasty kind. :type cookies: ``dict`` or ``cookielib.CookieJar`` :param int timeout: Request timeout seconds. If a response is not received within this timeframe, a connection is aborted with ``CancelledError``. :param bool allow_redirects: Follow HTTP redirects. Default: ``True`` :param bool browser_like_redirects: Follow redirects like a web browser: When a 301 or 302 redirect is received in response to a POST request convert the method to GET. See :rfc:`7231 <7231#section-6.4.3>` and :class:`~twisted.web.client.BrowserLikeRedirectAgent`). Default: ``False`` :param bool unbuffered: Pass ``True`` to to disable response buffering. By default treq buffers the entire response body in memory. :param reactor: Optional Twisted reactor. :param bool persistent: Use persistent HTTP connections. Default: ``True`` :param agent: Provide your own custom agent. Use this to override things like ``connectTimeout`` or ``BrowserLikePolicyForHTTPS``. By default, treq will create its own Agent with reasonable defaults. :type agent: twisted.web.iweb.IAgent :rtype: Deferred that fires with an :class:`IResponse` .. versionchanged:: treq 20.9.0 The *url* param now accepts :class:`hyperlink.DecodedURL` and :class:`hyperlink.EncodedURL` objects.

def collect(response, collector): (source)

Incrementally collect the body of the response. This function may only be called **once** for a given response. :param IResponse response: The HTTP response to collect the body from. :param collector: A callable to be called each time data is available from the response body. :type collector: single argument callable :rtype: Deferred that fires with None when the entire body has been read.

def text_content(response, encoding='ISO-8859-1'): (source)

Read the contents of an HTTP response and decode it with an appropriate charset, which may be guessed from the ``Content-Type`` header. :param IResponse response: The HTTP Response to get the contents of. :param str encoding: A charset, such as ``UTF-8`` or ``ISO-8859-1``, used if the response does not specify an encoding. :rtype: Deferred that fires with a unicode string.

def json_content(response, **kwargs): (source)

Read the contents of an HTTP response and attempt to decode it as JSON. This function relies on :py:func:`content` and so may be called more than once for a given response. :param IResponse response: The HTTP Response to get the contents of. :param kwargs: Any keyword arguments accepted by :py:func:`json.loads` :rtype: Deferred that fires with the decoded JSON.

__version__ = (source)

Undocumented