This page lists all of the interfaces exposed by the treq package.
The :py:mod:`treq` module provides several convenience functions for making requests. These functions all create a default :py:class:`treq.client.HTTPClient` instance and pass their arguments to the appropriate :py:class:`~treq.client.HTTPClient` method.
.. module:: treq
.. autofunction:: request
.. autofunction:: get
.. autofunction:: head
.. autofunction:: post
.. autofunction:: put
.. autofunction:: patch
.. autofunction:: delete
.. autofunction:: collect
.. autofunction:: content
.. autofunction:: text_content
.. autofunction:: json_content
.. module:: treq.client
:class:`treq.client.HTTPClient` has methods that match the signatures of the convenience request functions in the :mod:`treq` module.
.. autoclass:: HTTPClient(agent, cookiejar=None, data_to_body_producer=IBodyProducer) .. automethod:: request .. automethod:: get .. automethod:: head .. automethod:: post .. automethod:: put .. automethod:: patch .. automethod:: delete
:func:`treq.request`, :func:`treq.get`, etc. return an object which provides :class:`twisted.web.iweb.IResponse`, plus a few additional convenience methods:
.. module:: treq.response
.. automethod:: collect
.. automethod:: content
.. automethod:: json
.. automethod:: text
.. automethod:: history
.. automethod:: cookies
Inherited from :class:`twisted.web.iweb.IResponse`:
ivar version: | See :attr:`IResponse.version <twisted.web.iweb.IResponse.version>` |
---|---|
ivar code: | See :attr:`IResponse.code <twisted.web.iweb.IResponse.code>` |
ivar phrase: | See :attr:`IResponse.phrase <twisted.web.iweb.IResponse.phrase>` |
ivar headers: | See :attr:`IResponse.headers <twisted.web.iweb.IResponse.headers>` |
ivar length: | See :attr:`IResponse.length <twisted.web.iweb.IResponse.length>` |
ivar request: | See :attr:`IResponse.request <twisted.web.iweb.IResponse.request>` |
ivar previousResponse: | See :attr:`IResponse.previousResponse <twisted.web.iweb.IResponse.previousResponse>` |
.. method:: deliverBody(protocol) See :meth:`IResponse.deliverBody() <twisted.web.iweb.IResponse.deliverBody>`
.. method:: setPreviousResponse(response) See :meth:`IResponse.setPreviousResponse() <twisted.web.iweb.IResponse.setPreviousResponse>`
.. module:: treq.auth
.. autofunction:: add_auth
.. autofunction:: add_basic_auth
.. autoexception:: UnknownAuthConfig
.. module:: treq.cookies
.. autofunction:: scoped_cookie
.. autofunction:: search
.. module:: treq.testing
The :mod:`treq.testing` module contains tools for in-memory testing of HTTP clients and servers.
:class:`StubTreq` implements the same interface as the :mod:`treq` module
or the :class:`~treq.client.HTTPClient` class, with the limitation that it
does not support the files
argument.
.. method:: flush() Flush all data between pending client/server pairs. This is only necessary if a :obj:`Resource` under test returns :obj:`NOT_DONE_YET` from its ``render`` method, making a response asynchronous. In that case, after each write from the server, :meth:`flush()` must be called so the client can see it.
As the methods on :class:`treq.client.HTTPClient`:
.. method:: request See :func:`treq.request()`.
.. method:: get See :func:`treq.get()`.
.. method:: head See :func:`treq.head()`.
.. method:: post See :func:`treq.post()`.
.. method:: put See :func:`treq.put()`.
.. method:: patch See :func:`treq.patch()`.
.. method:: delete See :func:`treq.delete()`.
.. autoclass:: treq.testing.RequestTraversalAgent :members:
.. autoclass:: treq.testing.RequestSequence :members:
.. autoclass:: treq.testing.StringStubbingResource :members:
.. autoclass:: treq.testing.HasHeaders :members:
:class:`treq.multipart.MultiPartProducer` is used internally when making requests which involve files.
.. automodule:: treq.multipart :members: