Registry / http-networking / httsleep

httsleep

JSON →
library0.3.1pypypi✓ verified 82d ago

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 httsleep
INSTALL
IMPORT
SIG · HTTSLEEP
H
httsleep
http-networkingpythonv0.3.1
Install
3.3s avg
Import
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.3s · import 0.000s · 24MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttSleeper
from httsleep import HttSleeper
from httsleep import HTTSleep

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.

import time from httsleep import HTTSleep import requests # To create a mock response for the example import json # Simulate a remote service that eventually returns 'completed' # In a real scenario, this would be your actual API endpoint. mock_response_count = 0 def simulate_api_call(url=None, **kwargs): nonlocal mock_response_count mock_response_count += 1 mock_resp = requests.Response() if mock_response_count < 3: mock_resp.status_code = 202 # Accepted (still processing) mock_resp._content = b'{"status": "pending", "detail": "processing..."}' mock_resp.request = requests.Request('GET', url or 'http://mock.api/status').prepare() else: mock_resp.status_code = 200 # OK mock_resp._content = b'{"status": "completed", "result": "success!"}' mock_resp.request = requests.Request('GET', url or 'http://mock.api/status').prepare() # Monkey-patch json method for simplicity def json_method(): return json.loads(mock_resp._content.decode('utf-8')) mock_resp.json = json_method return mock_resp # Create an HTTSleep instance poller = HTTSleep( http_get_func=simulate_api_call, # Pass the mock function that makes HTTP calls check_func=lambda resp: resp.json().get("status") == "completed", timeout=20, # Total timeout for polling in seconds interval=1, # Initial interval in seconds max_interval=5, # Max interval between retries factor=2, # Exponential backoff factor logger=None # Suppress default logging for clean quickstart output ) print("Starting polling for a 'completed' status...") try: final_response = poller.poll() print(f"Polling successful! Final status: {final_response.json().get('status')}") print(f"Total attempts: {mock_response_count}") except Exception as e: print(f"Polling failed after timeout: {e}") # Reset count for potential re-runs in an interactive environment mock_response_count = 0
Debug
Known issues
gotchaHTTSleep has not been actively maintained or updated since January 2021. This means it may not be compatible with newer Python versions (beyond 3.8/3.9, which were current at the time of its last update), or its dependencies might become outdated, potentially leading to security vulnerabilities or runtime errors.
fix
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.
affects: <=0.3.1
gotchaThe `http_get_func` passed to `HTTSleep` must return an object that mimics `requests.Response`, specifically having a `.json()` method and a `status_code` attribute, if these are used by your `check_func` or the default status checkers. Returning a non-compatible object (e.g., `None` or a plain dictionary) will lead to `AttributeError` or `TypeError`.
fix
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`.
affects: <=0.3.1
gotchaHTTSleep uses `python-json-logger` for its internal logging. If you don't configure the logger, it may log to the console with JSON formatting by default, which might be unexpected in non-JSON logging setups. You can explicitly pass `logger=None` or configure a custom logger.
fix
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')`.
affects: <=0.3.1
gotchaHTTSleep provides default status checking logic based on HTTP status codes (e.g., 200 for success, 2xx for continuation). If you define a `check_func`, it completely overrides these defaults. Ensure your `check_func` handles all conditions, including what constitutes a success and what should trigger a retry or failure.
fix
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.
affects: <=0.3.1
Upgrade
Version history
0.3.1latest on PyPI · released Nov 4, 2018
Audit
Dependencies
requestsrequiredProvides the underlying HTTP client functionality for polling.
backoffrequiredPowers the exponential backoff and retry mechanisms within the poller.
python-json-loggerrequiredUsed for structured JSON logging within the library.
Agent activity
10 hits · last 30 days
node
8
Resources