HTTSleep is a Python library designed for polling HTTP endpoints with built-in features like exponential backoff and retries. It leverages `requests` for HTTP operations and `backoff` for robust retry logic. The current version is 0.3.1. Development appears to be in maintenance mode, with no new releases or significant commits since early 2021.
pip install httsleepVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `HTTSleep` to poll an endpoint until a specific condition is met. The `simulate_api_call` function acts as a mock HTTP service, returning 'pending' status a few times before eventually returning 'completed'. The `check_func` defines the condition for successful polling. The poller will retry with exponential backoff until the condition is met or the `timeout` is reached.
Thoroughly test `httsleep` in your target Python environment. Consider forking the project or choosing a more actively maintained alternative if long-term support and up-to-date dependencies are critical.
Ensure your custom `http_get_func` uses `requests.get` (or similar `requests` methods) or constructs a `requests.Response`-compatible object. If you're mocking, ensure the mock object has the expected attributes and methods like `.json()` and `status_code`.
To control logging, either pass `logger=None` to the `HTTSleep` constructor to disable it, or provide a pre-configured `logging.Logger` instance: `logger=logging.getLogger('my_logger')`.If you need both custom logic and default HTTP status checks, incorporate the default logic into your `check_func`, or chain it. Alternatively, consider using `status_checker` argument if applicable, but be aware of how they interact.