Derafu: http-ping ("A tank for a fly")
Perform HTTP requests (GET, POST, …) and get status code, response body and timing. Includes automatic retry with exponential backoff. Useful for scheduled triggers, health checks, and smoke tests.
Basic use case: scheduled trigger (e.g. Celery beat)
On AWS Elastic Beanstalk, Celery's built-in beat only runs on the leader instance. With auto-scaling, the leader can change and beat may not run, so scheduled tasks never fire.
Approach: Expose an HTTP endpoint that triggers your tasks. Call that endpoint on a schedule from AWS Lambda (e.g. via EventBridge). This project provides the Lambda code and a small http-ping module that performs the request and returns the result.
You keep responsibility for ensuring each logical task runs only once in your own code when handling the request.
Classes
HttpRequest
Value object holding the request configuration:
from http_ping import HttpRequest
request = HttpRequest(
url="https://example.com/api/beat",
method="POST", # default: "GET"
headers={"Accept": "application/json"},
body={"task": "run"}, # serialized as JSON; default: None
timeout=30.0, # seconds; default: 30.0
auth="Token abc123", # full Authorization header value; default: None
)
HttpAuth
Helpers to build common Authorization header values:
from http_ping import HttpAuth
HttpAuth.token("abc123") # → "Token abc123"
HttpAuth.bearer("abc123") # → "Bearer abc123"
HttpAuth.basic("user", "pass") # → "Basic dXNlcjpwYXNz"
Pass the result to HttpRequest(auth=...).
HttpPing
Executes an HttpRequest with optional retry and exponential backoff:
from http_ping import HttpAuth, HttpPing, HttpRequest
request = HttpRequest(
url="https://example.com/api/beat",
auth=HttpAuth.token("abc123"),
)
result = HttpPing(request, retries=3, backoff=1.0).run()
run() retries on network errors and 5xx responses. Backoff between retries: backoff, backoff*2, backoff*4, …
Returns a dict:
{
"status_code": 200,
"body": { "…": "…" },
"elapsed_seconds": 0.234,
"attempts": 1
}
body is parsed JSON if possible, otherwise a string.
HttpPingBatch
Executes a list of HttpRequest objects sequentially, sharing the same retry config. Individual failures are captured per URL without aborting the rest:
from http_ping import HttpAuth, HttpPingBatch, HttpRequest
requests = [
HttpRequest(url="https://example.com/api/health", auth=HttpAuth.token("abc123")),
HttpRequest(url="https://example.com/api/beat", auth=HttpAuth.token("abc123")),
]
results = HttpPingBatch(requests, retries=3, backoff=1.0).run()
Returns a list of dicts, one per URL. Each dict includes a "url" key. On failure, "error" replaces "status_code"/"body"/"elapsed_seconds":
[
{"url": "https://…/health", "status_code": 200, "body": {}, "elapsed_seconds": 0.1, "attempts": 1},
{"url": "https://…/beat", "error": "Connection timeout", "attempts": 3}
]
Console usage
Install the project first (e.g. python3 -m venv .venv && .venv/bin/pip install .), then:
# GET, no auth.
python -m http_ping "https://example.com/health"
# Multiple URLs (output is a list).
python -m http_ping "https://example.com/health" "https://example.com/api/beat"
# POST with bearer token.
HTTP_PING_METHOD=POST HTTP_PING_BEARER=abc123 python -m http_ping "https://example.com/api/run"
# Token auth via env var.
HTTP_PING_TOKEN=abc123 python -m http_ping "https://example.com/api/beat"
# Full Authorization header value (any scheme).
HTTP_PING_AUTH="Token abc123" python -m http_ping "https://example.com/api/beat"
# All options via env vars (space-separated URLs for multiple).
export HTTP_PING_URL="https://example.com/api/health https://example.com/api/beat"
export HTTP_PING_TOKEN="abc123"
export HTTP_PING_RETRIES=5
export HTTP_PING_BACKOFF=2.0
python -m http_ping
CLI arguments override env vars:
python -m http_ping --help
python -m http_ping "https://example.com/api/beat" --method POST --timeout 10 --retries 2 --backoff 0.5
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
HTTP_PING_URL |
yes | — | Target URL |
HTTP_PING_METHOD |
no | GET |
HTTP method |
HTTP_PING_AUTH |
no | — | Full Authorization header value |
HTTP_PING_TOKEN |
no | — | Shortcut: sets Authorization: Token <value> |
HTTP_PING_BEARER |
no | — | Shortcut: sets Authorization: Bearer <value> |
HTTP_PING_BODY |
no | — | JSON body for POST requests (as JSON string) |
HTTP_PING_TIMEOUT |
no | 30 |
Request timeout in seconds |
HTTP_PING_RETRIES |
no | 3 |
Number of retries on failure |
HTTP_PING_BACKOFF |
no | 1.0 |
Base backoff in seconds (doubles each retry) |
HTTP_PING_AUTH takes precedence over HTTP_PING_TOKEN and HTTP_PING_BEARER.
Makefile
make all– install the project intofunction/and buildhttp-ping-function.zip(for Lambda).make clean– remove the zip and everything infunction/exceptlambda_function.py.make dist– build sdist and wheel (python -m build).make upload– upload with twine (run aftermake dist).
Note on project structure
This project is intentionally over-structured for what it does ("a tank for a fly"). Its real purpose is to serve as a reference for real Python projects, following modern standards and conventions end to end:
- Package (
http_ping/) — proper Python package with__init__.pyexposing the public API,__main__.pyas CLI entry point, and internal modules with clear separation of concerns: data (HttpRequest), helpers (HttpAuth), and logic (HttpPing,HttpPingBatch). - Adapters (
function/lambda_function.py,http_ping/__main__.py) — thin layers that read environment variables and wire up the core classes. The business logic knows nothing about env vars or deployment targets. - Linting (
pyproject.toml→[tool.ruff]) — ruff configured with an explicit rule set, enforcing style, correctness, complexity and docstring conventions. - Tests (
tests/) — pytest with coverage, showing both unit tests (pure functions, no I/O) and integration tests (real HTTP calls). - CI (
.github/workflows/ci.yml) — runs lint and tests on every push across multiple Python versions. - Docs (
docs/,.github/workflows/docs.yml,.readthedocs.yaml) — Sphinx with autodoc, deployed automatically to GitHub Pages and Read the Docs. - Packaging (
pyproject.toml,Makefile) —make lambdabuilds the deployable AWS Lambda zip;make dist/make uploadbuild and publish to PyPI. These targets are kept as reference even though this project is not published.
Metadata
Release files for http-ping 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| http_ping-1.0.0.tar.gz | 9.1 kB | Without provenance | Details for http_ping-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| http_ping-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for http_ping-1.0.0-py3-none-any.whl |
Total release size: 17.4 kB
Release files / http_ping-1.0.0.tar.gz
| Download URL | http_ping-1.0.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2588cbae9d01573eaaf3678d1a04d18eda323b48f0ca8926ec877809c87d815
|
|
BLAKE2b-256 checksum How to use checksums |
320943a91d54e4b66c355c6e0963ec1c8e9abfefdc8bbcebd885dffbcb4949c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / http_ping-1.0.0-py3-none-any.whl
| Download URL | http_ping-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d31653f4c56950c62c8a9c3af711f202e32e58cac6c04b9bf392495d38cc6e4
|
|
BLAKE2b-256 checksum How to use checksums |
e03a297785520652e82783de40a33a7044c7ff69c0247376b8faba4679227815
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for http-ping 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.