https://github.com/spoqa/requests-backoff
Backoff session for requests
https://github.com/spoqa/requests-backoff
Last synced: over 1 year ago
JSON representation
Backoff session for requests
- Host: GitHub
- URL: https://github.com/spoqa/requests-backoff
- Owner: spoqa
- License: mit
- Created: 2021-03-05T06:22:40.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-02T07:49:30.000Z (over 5 years ago)
- Last Synced: 2025-02-22T19:47:35.012Z (over 1 year ago)
- Language: Python
- Size: 22.5 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spoqa-requests-backoff
[](LICENSE)
[](https://pypi.org/project/spoqa-requests-backoff/)
Backoff session for requests
## Usage
```python
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.
```python
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`](https://github.com/litl/backoff) package.
## License
_spoqa-requests-backoff_ is distributed under the terms of MIT License.
See [LICENSE](LICENSE) for more details.