treq: High-level Twisted HTTP Client API¶
Release v20.3.0 (What’s new?).
treq depends on a recent Twisted and functions on Python 2.7 and Python 3.3+ (including PyPy).
requests by Kenneth Reitz is a wonderful library.
I want the same ease of use when writing Twisted applications.
treq is not of course a perfect clone of requests.
I have tried to stay true to the do-what-I-mean spirit of the requests API and also kept the API familiar to users of Twisted and
twisted.web.client.Agent on which treq is based.
$ pip install treq
1 2 3 4
def main(reactor, *args): d = treq.get('https://httpbin.org/get') d.addCallback(print_response) return d
Why not 100% requests-alike?¶
Over time while attempting to mimic the requests API it became clear that not enough code could be shared between requests and treq for it to be worth the effort to translate many of the usage patterns from requests.
With the current version of treq I have tried to keep the API simple, yet remain familiar to users of Twisted and its lower-level HTTP libraries.
Feature Parity with Requests¶
|International Domains and URLs||yes||yes|
|Keep-Alive & Connection Pooling||yes||yes|
|Sessions with Cookie Persistence||yes||yes|
|Browser-style SSL Verification||yes||yes|
|Elegant Key/Value Cookies||yes||yes|
|Unicode Response Bodies||yes||yes|
|Multipart File Uploads||yes||yes|
|HTTP(S) Proxy Suport||yes||no|
Table of Contents¶
- Use Cases
- Testing Helpers
- API Reference