{"id":41780793,"url":"https://github.com/aponysus/redress","last_synced_at":"2026-03-06T05:12:35.913Z","repository":{"id":325828966,"uuid":"1102548592","full_name":"aponysus/redress","owner":"aponysus","description":"Composable, low-overhead retry policies with pluggable classification, per-class backoff strategies, and structured observability hooks. Designed for services that need predictable retry behavior and clean integration with metrics/logging.","archived":false,"fork":false,"pushed_at":"2026-01-23T13:40:34.000Z","size":195,"stargazers_count":4,"open_issues_count":27,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-24T05:32:13.533Z","etag":null,"topics":["backoff","backoff-library","exponential-backoff","fault-tolerance","observability","python","reliability","resilience","resilient-system","retry","retry-library"],"latest_commit_sha":null,"homepage":"https://aponysus.github.io/redress/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aponysus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":"docs/roadmap-public.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-23T16:55:18.000Z","updated_at":"2026-01-23T13:40:41.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/aponysus/redress","commit_stats":null,"previous_names":["aponysus/reflexio","aponysus/redress"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/aponysus/redress","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aponysus%2Fredress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aponysus%2Fredress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aponysus%2Fredress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aponysus%2Fredress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aponysus","download_url":"https://codeload.github.com/aponysus/redress/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aponysus%2Fredress/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28742983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backoff","backoff-library","exponential-backoff","fault-tolerance","observability","python","reliability","resilience","resilient-system","retry","retry-library"],"created_at":"2026-01-25T04:00:57.663Z","updated_at":"2026-01-25T04:00:58.306Z","avatar_url":"https://github.com/aponysus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redress\n\n![CI](https://github.com/aponysus/redress/actions/workflows/ci.yml/badge.svg)\n[![codecov](https://codecov.io/gh/aponysus/redress/branch/main/graph/badge.svg?token=OaQIP7hzAE)](https://codecov.io/gh/aponysus/redress)\n[![PyPI Version](https://img.shields.io/pypi/v/redress.svg)](https://pypi.org/project/redress/)\n[![Docs](https://img.shields.io/github/actions/workflow/status/aponysus/redress/docs.yml?label=docs)](https://aponysus.github.io/redress/)\n[![Bench](https://img.shields.io/github/actions/workflow/status/aponysus/redress/ci.yml?label=bench)](https://github.com/aponysus/redress/actions/workflows/ci.yml)\n\n\n\u003e redress (v.): to remedy or to set right.\n\nClassifier-driven retries with per-class backoff and structured hooks for Python services.\n\nComposable, low-overhead retry policies with **sync/async symmetry**, **deterministic envelopes**, and **lightweight composition**.  \nDesigned for services that need predictable retry behavior and clean integration with metrics/logging.\n\n## Documentation\n\n- Site: https://aponysus.github.io/redress/\n- Getting started: https://aponysus.github.io/redress/getting-started/\n\n## Installation\n\nFrom PyPI:\n\n```bash\nuv pip install redress\n# or\npip install redress\n```\n\n## Quick Start\n\n```python\nfrom redress.policy import RetryPolicy\nfrom redress.classify import default_classifier\nfrom redress.strategies import decorrelated_jitter\n\npolicy = RetryPolicy(\n    classifier=default_classifier,\n    strategy=decorrelated_jitter(max_s=10.0),\n)\n\ndef flaky():\n    # your operation that may fail\n    ...\n\nresult = policy.call(flaky)\n```\n\n### Decorator quick start\n\n```python\nfrom redress import retry, default_classifier\nfrom redress.strategies import decorrelated_jitter\n\n@retry  # defaults to default_classifier + decorrelated_jitter(max_s=5.0)\ndef fetch_user():\n    ...\n\n# Or customize classifier/strategies\n@retry(\n    classifier=default_classifier,\n    strategy=decorrelated_jitter(max_s=3.0),\n)\ndef fetch_user_custom():\n    ...\n\nIf you provide `strategies` without `strategy`, the decorator will not add a default\nstrategy.\n\n# Context manager for repeated calls with shared hooks/operation\npolicy = RetryPolicy(classifier=default_classifier, strategy=decorrelated_jitter(max_s=3.0))\nwith policy.context(operation=\"batch\") as retry:\n    retry(fetch_user)\n```\n\n### Async quick start\n\n```python\nimport asyncio\nfrom redress import AsyncRetryPolicy, default_classifier\nfrom redress.strategies import decorrelated_jitter\n\nasync_policy = AsyncRetryPolicy(\n    classifier=default_classifier,\n    strategy=decorrelated_jitter(max_s=5.0),\n)\n\nasync def flaky_async():\n    ...\n\nasyncio.run(async_policy.call(flaky_async))\n```\n\n## Why redress?\n\nMost retry libraries give you either:\n\n- decorators with a fixed backoff model, or  \n- one global strategy for all errors.\n\n**redress** gives you something different:\n\n### ✔ Exception → coarse error class mapping  \nProvided via `default_classifier`.\n\n### ✔ Per-class strategy dispatch  \nEach `ErrorClass` can use its own backoff logic.\n\n### ✔ Dependency-free strategies with jitter  \n`decorrelated_jitter`, `equal_jitter`, `token_backoff`.\n\n### ✔ Deadlines, max attempts, and separate caps for UNKNOWN  \nDeterministic retry envelopes.\n\n### ✔ Clean observability hook  \n\nSingle callback for:  \n`success`, `retry`, `permanent_fail`, `deadline_exceeded`, `max_attempts_exceeded`, `max_unknown_attempts_exceeded`.\n\n## Error Classes \u0026 Classification\n\n```\nPERMANENT\nCONCURRENCY\nRATE_LIMIT\nSERVER_ERROR\nTRANSIENT\nUNKNOWN\n```\n\nRedress intentionally keeps `ErrorClass` small and fixed. The goal is semantic\nclassification (\"rate limit\" vs. \"server error\") rather than mechanical mapping to\nevery exception type. If you need finer-grained behavior, use separate policies per\nuse case. Optional classification context can carry hints (for example, Retry-After)\nwithout expanding the class set.\n\nClassification rules:\n\n- Explicit redress error types  \n- Numeric codes (`err.status` or `err.code`)  \n- Name heuristics  \n- Fallback to UNKNOWN  \n\nName heuristics are a convenience for quick starts; for production, prefer a domain-specific\nclassifier (HTTP/DB/etc.) or `strict_classifier` to avoid surprises.\n\nClassifiers can return `Classification(klass=..., retry_after_s=..., details=...)` to pass\nstructured hints to strategies. Returning `ErrorClass` is shorthand for\n`Classification(klass=klass)`.\n\n## Metrics \u0026 Observability\n\n```python\ndef metric_hook(event, attempt, sleep_s, tags):\n    print(event, attempt, sleep_s, tags)\n\npolicy.call(my_op, on_metric=metric_hook)\n```\n\n## Backoff Strategies\n\nStrategy signature (context-aware):\n\n```\n(ctx: BackoffContext) -\u003e float\n```\n\nLegacy signature (still supported):\n\n```\n(attempt: int, klass: ErrorClass, prev_sleep: Optional[float]) -\u003e float\n```\n\nBuilt‑ins:\n\n- `decorrelated_jitter()`\n- `equal_jitter()`\n- `token_backoff()`\n- `retry_after_or(...)`\n\n## Per-Class Example\n\n```python\npolicy = RetryPolicy(\n    classifier=default_classifier,\n    strategy=decorrelated_jitter(max_s=10.0),  # default\n    strategies={\n        ErrorClass.CONCURRENCY: decorrelated_jitter(max_s=1.0),\n        ErrorClass.RATE_LIMIT: decorrelated_jitter(max_s=60.0),\n        ErrorClass.SERVER_ERROR: equal_jitter(max_s=30.0),\n    },\n)\n```\n\n## Deadline \u0026 Attempt Controls\n\n```python\npolicy = RetryPolicy(\n    classifier=default_classifier,\n    strategy=decorrelated_jitter(),\n    deadline_s=60,\n    max_attempts=8,\n    max_unknown_attempts=2,\n)\n```\n\n## Development\n\n```bash\nuv run pytest\n```\n\n## CLI\n\n- Lint a retry config or policy to catch obvious misconfigurations:\n\n```python\n# app_retry.py\nfrom redress import RetryConfig\nfrom redress.strategies import decorrelated_jitter\n\ncfg = RetryConfig(\n    default_strategy=decorrelated_jitter(max_s=1.5),\n    max_attempts=5,\n)\n```\n\nThen from the repo root or any env where app_retry is on PYTHONPATH:\n```bash\nredress doctor app_retry:cfg\n# Show a normalized snapshot of active values:\nredress doctor app_retry:cfg --show\n```\n\n`doctor` accepts `module:attribute` pointing to a `RetryConfig`, `RetryPolicy`, or `AsyncRetryPolicy`. The attribute defaults to `config` if omitted (e.g., `myapp.settings` will look for `settings:config`).\n\nExample `--show` output:\n\n```\nConfig snapshot:\n  source: app_retry:cfg\n  deadline_s: 60.0\n  max_attempts: 5\n  max_unknown_attempts: 2\n  default_strategy: redress.strategies.decorrelated_jitter.\u003clocals\u003e.f\n  class_strategies:\n    (none)\n  per_class_max_attempts:\n    (none)\nOK: 'app_retry:cfg' passed config checks.\n```\n\n## Examples (in `docs/snippets/`)\n\n- Sync httpx demo: `uv pip install httpx` then `uv run python docs/snippets/httpx_sync_retry.py`\n- Async httpx demo using `AsyncRetryPolicy`: `uv pip install httpx` then `uv run python docs/snippets/httpx_async_retry.py`\n- Async worker loop with retries: `uv run python docs/snippets/async_worker_retry.py`\n- Decorator usage (sync + async): `uv run python docs/snippets/decorator_retry.py`\n- FastAPI proxy with metrics counter: `uv pip install \"fastapi[standard]\" httpx` then `uv run uvicorn docs.snippets.fastapi_downstream:app --reload`\n- FastAPI middleware with per-endpoint policies: `uv pip install \"fastapi[standard]\" httpx` then `uv run uvicorn docs.snippets.fastapi_middleware:app --reload`\n- PyODBC + SQLSTATE classification example: `uv pip install pyodbc` then `uv run python docs/snippets/pyodbc_retry.py`\n- requests example: `uv pip install requests` then `uv run python docs/snippets/requests_retry.py`\n- asyncpg example: `uv pip install asyncpg` and set `ASYNC_PG_DSN`, then `uv run python docs/snippets/asyncpg_retry.py`\n- Pyperf microbenchmarks: `uv pip install .[dev]` then `uv run python docs/snippets/bench_retry.py`\n\n## Docs site\n\n- Build/serve locally: `uv pip install .[docs]` then `uv run mkdocs serve`\n- Pages: `docs/index.md`, `docs/usage.md`, `docs/observability.md`, `docs/recipes.md` with runnable snippets in `docs/snippets/`.\n\n## Versioning\n\nSemantic Versioning.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faponysus%2Fredress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faponysus%2Fredress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faponysus%2Fredress/lists"}