Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.vscode/
.vscode/

hack.py
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ Several HTTP errors are often transient, and might succeed if retried:

This project aims to simplify retrying these, by extending [`tenacity`](https://tenacity.readthedocs.io/) with custom retry and wait strategies, as well as a custom decorator. Defaults are sensible for most use cases, but are fully customizable.

Supports exceptions raised by both [`requests`](https://docs.python-requests.org/en/latest/index.html) and [`httpx`](https://python-httpx.org/).
Supports both [`requests`](https://docs.python-requests.org/en/latest/index.html) and [`httpx`](https://python-httpx.org/) natively, but could be customized to use with any library that raises exceptions for the conditions listed above.

## Install

Install from PyPI:

```sh
# Supports both HTTPX and requests
pip install retryhttp
pip install retryhttp # Supports both HTTPX and requests
```

You can also install support for only HTTPX or requests:
You can also install support for only HTTPX or requests, if you would rather not install unnecessary dependencies:

```sh
pip install retryhttp[httpx] # Supports only HTTPX
pip install retryhttp[requests] # Supports only requests
pip install retryhttp[httpx] # Supports only HTTPX
pip install retryhttp[requests] # Supports only requests
```

Or, install the latest development snapshot from git:
Expand All @@ -49,8 +48,8 @@ pip install git+https://github.com/austind/retryhttp.git@develop
import httpx
from retryhttp import retry

# Retries retryable status codes (429, 500, 502, 503, 504), network errors,
# and timeouts, up to 3 times, with appropriate wait strategies for each
# Retries safely retryable status codes (429, 500, 502, 503, 504), network errors,
# and timeouts, up to a total of 3 times, with appropriate wait strategies for each
# type of error. All of these behaviors are customizable.
@retry
def example():
Expand All @@ -62,4 +61,4 @@ def example():

## Contributing

Contributions welcome! Open a discussion and let's chat about your idea. Looking forward to working with you!
Contributions welcome! Bug fixes and minor tweaks can jump straight to a [pull request](https://github.com/austind/retryhttp/compare). For more involved changes, [open an issue](https://github.com/austind/retryhttp/issues/new/choose) and let's chat about your idea. Thanks for your contribution!
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.3.2

* Bugfix: Don't pass `stop`, `wait`, and `retry` keyword arguments from [`retryhttp.retry`][] on to `tenacity.retry()` ([#23](https://github.com/austind/retryhttp/issues/23))

## v1.3.1

* Fixed all outstanding mypy errors. ([#20](https://github.com/austind/retryhttp/issues/20)
Expand Down
3 changes: 3 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def get_example():
response.raise_for_status()
```

!!! note
`retryhttp` works by catching exceptions, so your code must raise those exceptions. Most of the time, all you need is to call `response.raise_for_status()`. Be sure not to catch those exceptions in your own `try..except` block.

## Advanced Usage

You don't have to use the [`retryhttp.retry`][] decorator, which is provided purely for convenience. If you prefer, you can use [`tenacity.retry`](https://tenacity.readthedocs.io/en/latest/api.html#tenacity.retry) and roll your own approach.
Expand Down
23 changes: 12 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
[build-system]
# Minimum requirements for the build system to execute.
# PEP 508 specifications for PEP 518.
# Banned setuptools versions have well-known issues
requires = [
"setuptools >= 21.0.0,!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0", # PSF/ZPL
"setuptools_scm[toml]>=3.4",
]
build-backend="setuptools.build_meta"

[project]
name = "retryhttp"
version = "1.3.1"
version = "1.3.2"
description = "Retry potentially transient HTTP errors in Python."
license = {file = "LICENSE"}
readme = "README.md"
Expand Down Expand Up @@ -75,11 +66,21 @@ Homepage = "https://github.com/austind/retryhttp"
Repository = "https://github.com/austind/retryhttp.git"
Issues = "https://github.com/austind/retryhttp/issues"

[build-system]
# Minimum requirements for the build system to execute.
# PEP 508 specifications for PEP 518.
# Banned setuptools versions have well-known issues
requires = [
"setuptools >= 21.0.0,!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0", # PSF/ZPL
"setuptools_scm[toml]>=3.4",
]
build-backend="setuptools.build_meta"

[tool.setuptools]
packages = ["retryhttp"]

[tool.ruff]
line-length = 88
line-length = 100
indent-width = 4
target-version = "py38"

Expand Down