Drop-in wrapper around the Python Requests library that provides extra features.
Project description
requests-extra
Drop-in replacement for the Requests library that wraps it to provide these ✨extra✨ features:
For resiliency: 🤘
Retry by default (3 times in total) with backoff / respecting Retry-After,
Timeout by default (10 seconds),
Exception on 4xx and 5xx responses by default (automatic raise_for_status()),
For performance: ⏩
Automatic HTTP keep-alive without explicitly using session,
Support for Brotli enabled by default,
When to use it?
This library is highly opinionated and uses a rather simplistic approach so it may or may not fit your project. For us it did help in the following use cases:
improving many small scripts - f.e. used for monitoring,
modernization of a big but simple and well-tested projects - f.e. old tests,
How to use?
Replace requests with requests-extra in your dependencies file
Replace requests. with requests_extra. in your code.
That’s it!
Example:
# instead of 'from requests import get'
from requests_extra import get
get('https://httpbin.org/headers')
For more examples please see the tests.
How to change the defaults?
See defaults.py.
To change some of them for all of your code do this:
import requests_extra.defaults
requests_extra.defaults.timeout = 1
You can also overwrite them for a single request in the usual way:
from requests_extra import get
get('https://httpbin.org', timeout=5)
TODO
More features:
Single line logging of requests and/or responses, with default secrets redaction,
HTTP/2 support (by switching to encode/httpx as a backend),
[STRIKEOUT:Rate limiting support, including respecting the appropriate HTTP headers] - urllib3 supports it since v. 1.19 released on 2016-11-03… 😅
Support for RFC-2782 style DNS SRV entries (for Consul) - see pstiasny/requests-srv,
Service-to-service authentication on GCP - see adrianchifor/requests-gcp,
Built-in support for caching responses? - maybe with reclosedev/requests-cache or bionikspoon/cache_requests
Contributing
ALL kinds of issues & PRs are very welcome! There are no formal rules of contributing yet, please use common sense. ;)
Credits
Firstly big thanks to all the authors of the wrapped library, Requests!
Additionally thank you to the authors of reused code:
The code for timeouts and raise_for_status() is copied from the better-requests/better-requests library.
The code for LFU cache is copied from the luxinger/lfu_cache.
Some concepts from the CarlosAMolina/requests_custom library are used too.
License
Like the wrapped Requests, and the libraries we reused, this library uses the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for requests_extra-1.0.0b6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee595207a0323d54dc5de77a090a9427aca21c6bba45a1917ea749781373bb0a |
|
MD5 | 0ecbdd598e4baab221309ed48442b66a |
|
BLAKE2b-256 | 9a0a90000fc5d64eef04d294e8daccf82c5b3151fc0f9e0961888720b7bf2ecd |