Python utility library for timeout/retry polling patterns. Single module (~300 LOC), published on PyPI as timeout-sampler.
Single-file library: timeout_sampler/__init__.py
TimeoutSampler— main class, generator-based polling with configurable exception filtering and sensitive key redactionTimeoutWatch— elapsed time tracking utilityTimeoutExpiredError— raised when timeout expires, carrieslast_expandelapsed_timeretry— decorator wrappingTimeoutSamplerfor function-level retryExceptionFilter,ExceptionsDict— public type aliases for exception filter configuration
Tests: tests/test_timeout_sampler.py (single file, pytest)
- Install:
uv sync - Test:
uv run pytest tests/ - Lint:
uv run ruff check . && uv run ruff format --check . - Type check:
uv run mypy timeout_sampler/ - All checks: run lint, type check, then tests — in that order
- Python >=3.10,
from __future__ import annotationsin all modules - ruff: line-length=120, preview=true, fix=true
- mypy: strict (disallow_untyped_defs, disallow_incomplete_defs, check_untyped_defs)
- Type hints required on all public and private method signatures
- Docstrings: Google style with Args/Returns/Raises sections on all public methods
- Use
LOGGER(frompython-simple-logger) — neverprint() - Broad exception catches must use
# noqa: BLE001comment
- Framework: pytest with IPython debugger (
--pdbcls=IPython.terminal.debugger:TerminalPdb) - Use
pytest.mark.parametrizefor related test cases — avoid boilerplate repetition - Keep
wait_timeoutminimal in unit tests (1-2 seconds max) — tests must be fast - Test both success and failure paths for new features
- Run tests after any code change
- Update docstrings when method signatures change
- Update README.md examples when public API changes
- Maintain backward compatibility — existing callers must not break
- Validate inputs at
__init__time, not at runtime in hot paths
- Add dependencies to
pyproject.tomlwithout explicit approval - Use
print()— useLOGGERfromsimple_logger - Edit files in
docs/manually (see Generated Documentation below) - Modify
__all__without updating corresponding docstrings and README
- Before adding new public API surface (classes, functions, type aliases)
- Before changing exception hierarchy or error message formats
- Before bumping minimum Python version
The docs/ directory contains AI-generated documentation from docsfy.
NEVER edit these files manually. To update documentation, regenerate using docsfy.
- Commit messages: conventional commits (
feat:,fix:,docs:,refactor:) - Backward compatibility is required — breaking changes need explicit approval
- Update README examples when adding or changing public API