Skip to content

Commit 3741516

Browse files
Merge pull request #4 from LitePy/docs/brand
Logo and docs design
2 parents 17dbd04 + 91346a0 commit 3741516

8 files changed

Lines changed: 271 additions & 26 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<div align="center">
22

3-
# python-wrap
3+
<a href="https://python-wrap.readthedocs.io">
4+
<picture>
5+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/LitePy/PythonWrap/main/docs/assets/logo-dark.svg">
6+
<img alt="python-wrap" src="https://raw.githubusercontent.com/LitePy/PythonWrap/main/docs/assets/logo-light.svg" height="64">
7+
</picture>
8+
</a>
49

510
**The resilience and concurrency toolkit you add to every Python project.**<br>
611
Retry (with `Retry-After`), circuit breaker, timeout, cache, rate limit, bulkhead, batching, async helpers, metrics and test helpers. One import, sync and async, zero dependencies.

‎docs/assets/logo-dark.svg‎

Lines changed: 17 additions & 0 deletions
Loading

‎docs/assets/logo-light.svg‎

Lines changed: 17 additions & 0 deletions
Loading

‎docs/assets/logo-mark.svg‎

Lines changed: 14 additions & 0 deletions
Loading

‎docs/index.md‎

Lines changed: 97 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
# python-wrap
1+
---
2+
title: python-wrap
3+
hide:
4+
- navigation
5+
- toc
6+
---
27

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
425

526
```python
627
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).
168189

169190
## Principles
170191

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+
---
172221

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).
174223

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__
176225

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+
---
178227

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.
180229

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>
182231

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).
184233

185234
## Where to go next
186235

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>

‎docs/stylesheets/extra.css‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Brand: the teal of the logo. */
2+
:root,
3+
[data-md-color-scheme="default"] {
4+
--md-primary-fg-color: #0f766e;
5+
--md-primary-fg-color--light: #2dd4bf;
6+
--md-primary-fg-color--dark: #115e59;
7+
--md-accent-fg-color: #0d9488;
8+
--md-typeset-a-color: #0f766e;
9+
}
10+
11+
[data-md-color-scheme="slate"] {
12+
--md-primary-fg-color: #0d9488;
13+
--md-primary-fg-color--light: #5eead4;
14+
--md-primary-fg-color--dark: #0f766e;
15+
--md-accent-fg-color: #5eead4;
16+
--md-typeset-a-color: #5eead4;
17+
--md-default-bg-color: #0b1112;
18+
}
19+
20+
.md-header,
21+
.md-tabs {
22+
background: linear-gradient(90deg, #115e59, #0d9488);
23+
}
24+
25+
.md-typeset h1 {
26+
color: var(--md-default-fg-color);
27+
font-weight: 700;
28+
letter-spacing: -0.02em;
29+
}
30+
31+
.md-typeset h2 {
32+
font-weight: 650;
33+
letter-spacing: -0.01em;
34+
}
35+
36+
/* ── home page ──────────────────────────────────────────────────────────── */
37+
38+
.pw-hero {
39+
text-align: center;
40+
padding: 1.5rem 0 0.5rem;
41+
}
42+
43+
.pw-hero .pw-logo {
44+
width: 5rem;
45+
height: 5rem;
46+
margin-bottom: 0.5rem;
47+
}
48+
49+
.pw-hero h1 {
50+
font-size: 2.6rem;
51+
font-weight: 800;
52+
letter-spacing: -0.03em;
53+
line-height: 1.15;
54+
margin: 0 0 0.75rem;
55+
}
56+
57+
.pw-hero .pw-tagline {
58+
font-size: 1.15rem;
59+
color: var(--md-default-fg-color--light);
60+
max-width: 40rem;
61+
margin: 0 auto 1.5rem;
62+
}
63+
64+
.pw-hero .md-button {
65+
margin: 0.25rem;
66+
}
67+
68+
@media screen and (max-width: 44.9375em) {
69+
.pw-hero h1 {
70+
font-size: 1.9rem;
71+
}
72+
73+
.pw-hero .pw-tagline {
74+
font-size: 1rem;
75+
}
76+
}
77+
78+
.md-typeset .grid.cards > ul > li {
79+
border-radius: 0.6rem;
80+
}
81+
82+
.md-typeset .grid.cards > ul > li:hover {
83+
border-color: var(--md-accent-fg-color);
84+
}

‎mkdocs.yml‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,36 @@ validation:
1414

1515
theme:
1616
name: material
17+
logo: assets/logo-mark.svg
18+
favicon: assets/logo-mark.svg
1719
icon:
1820
repo: fontawesome/brands/github
21+
font:
22+
text: Inter
23+
code: JetBrains Mono
1924
palette:
2025
- media: "(prefers-color-scheme)"
2126
toggle:
2227
icon: material/brightness-auto
2328
name: Switch to light mode
2429
- media: "(prefers-color-scheme: light)"
2530
scheme: default
26-
primary: indigo
27-
accent: indigo
31+
primary: custom
32+
accent: custom
2833
toggle:
2934
icon: material/weather-sunny
3035
name: Switch to dark mode
3136
- media: "(prefers-color-scheme: dark)"
3237
scheme: slate
33-
primary: indigo
34-
accent: indigo
38+
primary: custom
39+
accent: custom
3540
toggle:
3641
icon: material/weather-night
3742
name: Follow the system
3843
features:
44+
- navigation.instant
45+
- navigation.instant.progress
46+
- navigation.tracking
3947
- navigation.tabs
4048
- navigation.sections
4149
- navigation.top
@@ -44,8 +52,14 @@ theme:
4452
- toc.follow
4553
- search.suggest
4654
- search.highlight
55+
- search.share
4756
- content.code.copy
57+
- content.code.annotate
4858
- content.tabs.link
59+
- content.action.edit
60+
61+
extra_css:
62+
- stylesheets/extra.css
4963

5064
extra:
5165
social:
@@ -72,15 +86,25 @@ plugins:
7286
merge_init_into_class: true
7387

7488
markdown_extensions:
89+
- abbr
7590
- admonition
7691
- attr_list
92+
- def_list
93+
- footnotes
94+
- md_in_html
7795
- tables
7896
- toc:
7997
permalink: true
8098
- pymdownx.details
99+
- pymdownx.emoji:
100+
emoji_index: !!python/name:material.extensions.emoji.twemoji
101+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
81102
- pymdownx.highlight:
82103
anchor_linenums: true
104+
line_spans: __span
105+
pygments_lang_class: true
83106
- pymdownx.inlinehilite
107+
- pymdownx.keys
84108
- pymdownx.snippets:
85109
base_path: [.]
86110
check_paths: true

‎tests/test_config.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from python_wrap import _core
1010
from python_wrap.config import configure, configured, get_config, reset_config
1111
from python_wrap.deadline import deadline
12-
from python_wrap.logs import audit, log_args
12+
from python_wrap.logs import AuditRecord, audit, log_args
1313
from python_wrap.retry import retry, retry_stats, retrying
1414

1515

@@ -202,8 +202,10 @@ def f(ssn: str, password: str) -> None: ...
202202
def g(ssn: str, password: str) -> None: ...
203203

204204
g("123", "pw")
205-
text = repr(records[0])
206-
assert "123" not in text and "pw" in text
205+
record = records[0]
206+
assert isinstance(record, AuditRecord)
207+
# Only the arguments: the timestamp or duration can contain "123" by chance.
208+
assert record.arguments == {"ssn": "***", "password": "pw"}
207209

208210

209211
def test_redact_extra_adds_to_defaults_everywhere(caplog: pytest.LogCaptureFixture) -> None:
@@ -222,9 +224,9 @@ def f(ssn: str, password: str, name: str) -> None: ...
222224
def g(ssn: str, token: str, name: str, other: str) -> None: ...
223225

224226
g("1", "s3cr3t", "bob", "keep")
225-
text = repr(records[0])
226-
assert "bob" not in text and "s3cr3t" not in text and "'1'" not in text
227-
assert "keep" in text
227+
record = records[0]
228+
assert isinstance(record, AuditRecord)
229+
assert record.arguments == {"ssn": "***", "token": "***", "name": "***", "other": "keep"}
228230

229231

230232
def test_redact_extra_with_explicit_redact(caplog: pytest.LogCaptureFixture) -> None:

0 commit comments

Comments
 (0)