Skip to main content

Backoff Session for requests

Project description

spoqa-requests-backoff

MIT License PyPI

Backoff session for requests

Usage

resp = BackoffSession().get('https://...')

By default, BackoffSession tries before giving up until any following condition is met:

  • Tries 10 times
  • Reaches 20 seconds
  • Meets requests.RequestException
  • Meets HTTP client error (4xx)

Behaviors above can be customized with parameters.

BackoffSession(
    exception=(RequestException, ValueError),  # Give up when ValueError occurs, too.
    max_tries=100,  # Tries 100 times before giving up
    max_time=300,  # Wait until maximum 300 seconds before giving up
    giveup=lambda e: e.response.text == 'You're fired!'  # Give up when specific response is met
)

BackoffSession heavily depends on backoff package.

License

spoqa-requests-backoff is distributed under the terms of MIT License.

See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spoqa-requests-backoff-0.1.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

spoqa_requests_backoff-0.1.1-py2.py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page