|
1 | | -# python-wrap |
| 1 | +--- |
| 2 | +title: python-wrap |
| 3 | +hide: |
| 4 | + - navigation |
| 5 | + - toc |
| 6 | +--- |
2 | 7 |
|
3 | | -**The resilience and concurrency toolkit you add to every project.** Retry (with `Retry-After`), circuit breaker, timeout, cache, rate limit, bulkhead, batching, async helpers, metrics and test helpers, in one typed, async-aware package with no dependencies. |
| 8 | +<div class="pw-hero" markdown> |
| 9 | + |
| 10 | +<img class="pw-logo" src="assets/logo-mark.svg" alt=""> |
| 11 | + |
| 12 | +# The toolkit you add to every Python project |
| 13 | + |
| 14 | +<p class="pw-tagline">Retry (with <code>Retry-After</code>), circuit breaker, timeout, cache, rate limit, |
| 15 | +bulkhead, batching, async helpers, metrics and test helpers. One import, sync and async, |
| 16 | +fully typed, zero dependencies.</p> |
| 17 | + |
| 18 | +[Get started](#install){ .md-button .md-button--primary } |
| 19 | +[Choose a decorator](choosing.md){ .md-button } |
| 20 | +[View on GitHub](https://github.com/LitePy/PythonWrap){ .md-button } |
| 21 | + |
| 22 | +</div> |
| 23 | + |
| 24 | +## One decorator, the whole policy |
4 | 25 |
|
5 | 26 | ```python |
6 | 27 | from python_wrap import CircuitBreaker, memoize, policy, retry, retry_after_header, timeout |
@@ -168,25 +189,86 @@ Not sure which decorator you need? Start with [Choose a decorator](choosing.md). |
168 | 189 |
|
169 | 190 | ## Principles |
170 | 191 |
|
171 | | -**Zero dependencies.** `dependencies = []` is a feature: python-wrap is safe to add to any project, including libraries. |
| 192 | +<div class="grid cards" markdown> |
| 193 | + |
| 194 | +- :material-package-variant-closed:{ .lg .middle } __Zero dependencies__ |
| 195 | + |
| 196 | + --- |
| 197 | + |
| 198 | + `dependencies = []` is a feature: python-wrap is safe to add to any project, including libraries. |
| 199 | + |
| 200 | +- :material-language-python:{ .lg .middle } __Typed__ |
| 201 | + |
| 202 | + --- |
| 203 | + |
| 204 | + Ships `py.typed`, passes `mypy --strict`, and preserves signatures with `ParamSpec`, so your editor still knows what the decorated function takes and returns. |
| 205 | + |
| 206 | +- :material-lightning-bolt:{ .lg .middle } __Async is first class__ |
| 207 | + |
| 208 | + --- |
| 209 | + |
| 210 | + Async functions get `async def` wrappers, waits use `asyncio` instead of blocking the loop, and caches share concurrent awaits. See [Async support](async.md). |
| 211 | + |
| 212 | +- :material-text-box-search-outline:{ .lg .middle } __Never configures logging__ |
| 213 | + |
| 214 | + --- |
| 215 | + |
| 216 | + Importing python-wrap does not touch the root logger. Decorators log to the `python_wrap` logger, which has a `NullHandler`. See [Observability](guides/observability.md#configuring-logging). |
| 217 | + |
| 218 | +- :material-chart-line:{ .lg .middle } __Observable and testable__ |
| 219 | + |
| 220 | + --- |
172 | 221 |
|
173 | | -**Typed.** The package ships `py.typed`, passes `mypy --strict`, and preserves signatures with `ParamSpec`, so your editor still knows what the decorated function takes and returns. |
| 222 | + `count_calls` and one [event hook](guides/metrics.md) cover retries, caches, circuits and limiters; [`python_wrap.testing`](testing.md) makes tests instant. Overhead numbers: [Performance](performance.md). |
174 | 223 |
|
175 | | -**Async is first class.** Async functions get `async def` wrappers (so `inspect.iscoroutinefunction` stays true), retries and rate limits wait with `asyncio` instead of blocking the loop, and caches de-duplicate concurrent awaits. See [Async support](async.md). |
| 224 | +- :material-alert-octagon-outline:{ .lg .middle } __Failures are explicit__ |
176 | 225 |
|
177 | | -**It never configures logging.** Importing python-wrap does not touch the root logger. Decorators log to the `python_wrap` logger (or the `logger=` you give them), which carries a `NullHandler`, so nothing is printed until your application configures logging. See [Observability](guides/observability.md#configuring-logging). |
| 226 | + --- |
178 | 227 |
|
179 | | -**Observable and testable.** `count_calls` and one [event hook](guides/metrics.md) cover retries, caches, circuits and limiters, and [`python_wrap.testing`](testing.md) makes tests instant and deterministic. See [Performance](performance.md) for overhead numbers. |
| 228 | + Its own exceptions (`TimeoutExpired`, `RateLimitExceeded`, `CircuitOpenError`, `BulkheadFull`, ...) also subclass the closest built-in, so `except TimeoutError` keeps working. |
180 | 229 |
|
181 | | -**Failures are explicit.** The package raises its own exceptions (`TimeoutExpired`, `RateLimitExceeded`, `CircuitOpenError`, `BulkheadFull`, `BatchError`, `ValidationError`, `ArgumentTypeError`), each also a subclass of the closest built-in, so `except TimeoutError` and `except ValueError` keep working. |
| 230 | +</div> |
182 | 231 |
|
183 | | -**Honest about limits.** Some of these tools cannot do everything (a thread timeout cannot stop the work, for example). They are documented on one page: [Limitations](limitations.md). |
| 232 | +Some of these tools cannot do everything (a thread timeout cannot stop the work, for example). Every such limit is on one page: [Limitations](limitations.md). |
184 | 233 |
|
185 | 234 | ## Where to go next |
186 | 235 |
|
187 | | -- [Choose a decorator](choosing.md): a table by problem. |
188 | | -- Guides: [Resilience](guides/resilience.md), [Caching](guides/caching.md), [Concurrency](guides/concurrency.md), [Async toolkit](guides/async-toolkit.md), [Batching and hedging](guides/batching.md), [Observability](guides/observability.md), [Metrics and events](guides/metrics.md), [Validation](guides/validation.md), [State safety](guides/state.md), [Policies](guides/policies.md), [Developer tools](guides/devtools.md), [Configuration](guides/configuration.md). |
189 | | -- [Cookbook](cookbook/index.md): complete recipes for HTTP clients, crawlers, FastAPI, Django, CLIs and tests. |
190 | | -- [Testing](testing.md) and [Performance](performance.md). |
191 | | -- [Stacking decorators](stacking.md): order matters. |
192 | | -- [Migrating from 0.1](migration.md): every breaking change, with before and after code. |
| 236 | +<div class="grid cards" markdown> |
| 237 | + |
| 238 | +- :material-compass-outline:{ .lg .middle } __[Choose a decorator](choosing.md)__ |
| 239 | + |
| 240 | + --- |
| 241 | + |
| 242 | + A table by problem: what to reach for, and what to combine it with. |
| 243 | + |
| 244 | +- :material-book-open-variant:{ .lg .middle } __Guides__ |
| 245 | + |
| 246 | + --- |
| 247 | + |
| 248 | + [Resilience](guides/resilience.md), [Caching](guides/caching.md), [Concurrency](guides/concurrency.md), [Async toolkit](guides/async-toolkit.md), [Batching](guides/batching.md), [Observability](guides/observability.md), [Metrics](guides/metrics.md), [Validation](guides/validation.md), [State](guides/state.md), [Policies](guides/policies.md), [Dev tools](guides/devtools.md), [Configuration](guides/configuration.md). |
| 249 | + |
| 250 | +- :material-chef-hat:{ .lg .middle } __[Cookbook](cookbook/index.md)__ |
| 251 | + |
| 252 | + --- |
| 253 | + |
| 254 | + Complete recipes for HTTP clients, crawlers, FastAPI, Django, CLIs and tests. |
| 255 | + |
| 256 | +- :material-test-tube:{ .lg .middle } __[Testing](testing.md)__ |
| 257 | + |
| 258 | + --- |
| 259 | + |
| 260 | + `fast_mode`, a fake clock, spies and `eventually`: instant, deterministic tests. |
| 261 | + |
| 262 | +- :material-layers-triple-outline:{ .lg .middle } __[Stacking decorators](stacking.md)__ |
| 263 | + |
| 264 | + --- |
| 265 | + |
| 266 | + Order matters. The recommended order, and why `policy(...)` applies it for you. |
| 267 | + |
| 268 | +- :material-swap-horizontal:{ .lg .middle } __[Migrating from 0.1](migration.md)__ |
| 269 | + |
| 270 | + --- |
| 271 | + |
| 272 | + Every breaking change, with before and after code. |
| 273 | + |
| 274 | +</div> |
0 commit comments