requests-extra

Drop-in wrapper around the Python Requests library that provides extra features.


Keywords
requests, timeout, retry, exception, brotli, http, performance, requests-library-python, resiliency, wrapper
License
Apache-2.0
Install
pip install requests-extra==1.0.0b8

Documentation

status version release date linter tests

requests-extra

Drop-in replacement for the Requests library that wraps it to provide these extra features:

Improved 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()),

Improved 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?

  1. Replace requests with requests-extra in your dependencies file
  2. 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:

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:

License

Like the wrapped Requests, and the libraries we reused, this library uses the Apache 2.0 license.