wrapkit 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.5
2
+ Name: wrapkit
3
+ Version: 0.4.0
4
+ Summary: Shared infrastructure for data-API wrappers: logging with secret redaction, a disk cache, retries, tidy frames, incremental CSV updates and python-fire helpers.
5
+ Project-URL: Homepage, https://github.com/hmorao95/wrapkit
6
+ Project-URL: Repository, https://github.com/hmorao95/wrapkit
7
+ Project-URL: Changelog, https://github.com/hmorao95/wrapkit/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/hmorao95/wrapkit/issues
9
+ Author-email: Hugo Morão <132693995+hmorao95@users.noreply.github.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,cache,logging,pandas,retry,wrapper
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.12
24
+ Requires-Dist: colorlog>=6.8
25
+ Requires-Dist: fire>=0.6
26
+ Requires-Dist: httpx>=0.27
27
+ Requires-Dist: openpyxl>=3.1
28
+ Requires-Dist: pandas>=2.2
29
+ Requires-Dist: pyarrow>=15.0
30
+ Requires-Dist: requests>=2.28
31
+ Provides-Extra: polars
32
+ Requires-Dist: polars>=1.0; extra == 'polars'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # wrapkit
36
+
37
+ [![CI](https://github.com/hmorao95/wrapkit/actions/workflows/ci.yml/badge.svg)](https://github.com/hmorao95/wrapkit/actions/workflows/ci.yml)
38
+
39
+ Shared infrastructure for my data-API wrappers (`eia-api`, `entsoe-api`,
40
+ `ine-pt-api` and the rest). Each wrapper used to carry its own copy of the same
41
+ plumbing; `wrapkit` holds it once, so a fix lands in one place.
42
+
43
+ It holds only generic, secret-free code. Endpoints, request building, response
44
+ parsing and each wrapper's public API stay in the wrapper.
45
+
46
+ ## Install
47
+
48
+ From PyPI:
49
+
50
+ ```bash
51
+ pip install wrapkit
52
+ ```
53
+
54
+ In a wrapper's `pyproject.toml`:
55
+
56
+ ```toml
57
+ dependencies = ["wrapkit>=0.4,<0.5"]
58
+ ```
59
+
60
+ Releases before 0.4.0 exist only as git tags; a pinned tag still works:
61
+
62
+ ```toml
63
+ dependencies = ["wrapkit @ git+https://github.com/hmorao95/wrapkit@v0.3.1"]
64
+
65
+ [tool.hatch.metadata]
66
+ allow-direct-references = true
67
+ ```
68
+
69
+ A package that depends on wrapkit by git URL cannot be uploaded to PyPI (PyPI
70
+ rejects direct references); depend on the PyPI release instead.
71
+
72
+ wrapkit requires Python 3.12 or newer. In a clone, `uv sync` uses Python 3.12,
73
+ set in `.python-version` (uv downloads it if needed).
74
+
75
+ ## Modules
76
+
77
+ | Module | What it gives a wrapper |
78
+ |---|---|
79
+ | `wrapkit.log` | `package_logger`, `configure_logging` (colored stderr console, plain DEBUG log file), `PlainFormatter`, `RedactFilter` (masks a key's query parameter and registered secrets on the `urllib3`/`httpcore`/`httpx` loggers), `loggable` |
80
+ | `wrapkit.cache` | the `DEFAULT_CACHE_DIR` sentinel, `resolve_cache_dir` (`None` or `""` = no cache), `cache_path` and `DiskCache` (JSON files named by a digest that leaves secrets out, written through an exclusive temp file) |
81
+ | `wrapkit.http` | `RetryPolicy` (429/5xx and transport errors, doubling backoff with jitter, numeric `Retry-After` honoured in full up to `max_retry_after`, then no early retry; capped backoff), `get_with_retries` (requests), `aget_with_retries` (httpx), `RateLimit` (a provider's published limit and its source), `Throttle` / `AsyncThrottle` (strict: never faster than a `RateLimit`, shared by key across clients and threads, rolling daily quota kept on disk), `RateLimitError`, `QuotaExhausted`, `user_agent` |
82
+ | `wrapkit.frames` | `tidy_frame` / `empty_tidy` (date, dimensions, value, unit), `as_polars`, `snake`, `period_start` / `period_end` (an end at year, quarter or month precision, such as `2024`, `2024-Q2`, `2024-06` or `Jun 2024`, covers the whole period) |
83
+ | `wrapkit.incremental` | `key_strings`, `select_new`, `read_existing`, `upsert`: the pieces of `new_observations` and `update_csv` |
84
+ | `wrapkit.io` | `write_frame` (CSV, Excel, Parquet or JSON by extension) |
85
+ | `wrapkit.cli` | `resolve_out`, `as_text`, `bind_bool_flags`, `literal_keeping_codes`, `set_parse_fns`, and `run` (short `Error: ...` line, masked by the logger's `RedactFilter`, and exit 1 for expected errors) |
86
+
87
+ ## Example
88
+
89
+ ```python
90
+ from wrapkit import cache, http, log
91
+
92
+ _log = log.package_logger("my_api")
93
+ _redact = log.RedactFilter(["api_key"]).install("my_api")
94
+
95
+
96
+ class Client:
97
+ def __init__(self, api_key, cache_dir=cache.DEFAULT_CACHE_DIR):
98
+ _redact.register(api_key)
99
+ self.cache = cache.DiskCache(
100
+ cache.resolve_cache_dir(cache_dir, "my_api"),
101
+ ttl_seconds=86400,
102
+ hidden=["api_key"],
103
+ logger=_log,
104
+ )
105
+ self.throttle = http.Throttle(
106
+ requests_per_second, _log, limit=LIMIT, key="api.example.org"
107
+ )
108
+
109
+
110
+ # The provider's published limit, with where it is stated. A caller may slow
111
+ # down (requests_per_second=0.5) but never go faster: that raises
112
+ # RateLimitError, and None means "as fast as the limit allows". Every client
113
+ # with the same key shares one budget. per_day raises QuotaExhausted once used
114
+ # up, counted over a rolling 24 hours in ~/.cache/wrapkit/rate_limits.
115
+ LIMIT = http.RateLimit(
116
+ per_minute=30, per_day=500, source="https://api.example.org/docs/limits"
117
+ )
118
+ ```
119
+
120
+ ### Request limits
121
+
122
+ Every wrapper defines its provider's limit as a `RateLimit` and passes it to
123
+ its `Throttle`, so the code enforces what its README states. Where a provider
124
+ publishes no number, the wrapper picks a conservative rate and says so in
125
+ `source` ("no published limit"). A robots.txt `Crawl-delay` counts as a limit.
126
+ The ledger of daily quotas is not locked between processes running at the same
127
+ time; within one process the count is exact.
128
+
129
+ ## Versioning
130
+
131
+ Semantic versioning. Wrappers pin a tag, so a new wrapkit release only reaches
132
+ a wrapper when its pin is bumped.
133
+
134
+ ## License
135
+
136
+ MIT
@@ -0,0 +1,13 @@
1
+ wrapkit/__init__.py,sha256=5Piy-zYGGmZqr9S9ww48VPhK1jx4uiQT7ovUfuFIHVw,884
2
+ wrapkit/cache.py,sha256=svVHMrQn2amLih6ACc7OBHqRdl-wo5szqITLXchY3XI,9922
3
+ wrapkit/cli.py,sha256=6e3sErqXiC7QdBYq16vdfKNd_MqJqwX64R-uVKGBBl0,9448
4
+ wrapkit/frames.py,sha256=xmPr5OaKgvXBHan-QHRTT4LsY0Bnp9XbwEj_kpHs9D4,10175
5
+ wrapkit/http.py,sha256=ojimpanXR8xWMyabivQioAStFvNWLdDGsM0YVtHlr_4,28681
6
+ wrapkit/incremental.py,sha256=vR3tfNkKfYAGZbWiQkgzWbSa3aPd4UFC8UZsJF13Cng,11241
7
+ wrapkit/io.py,sha256=XDiY5wc9O2N0ciceoET6zVy5AdEsaxNoc4gPGunSrlY,2255
8
+ wrapkit/log.py,sha256=DMOuflah7Ij1vxX1PhiAPpciAqI5KBn6TLky-lmM5ic,11685
9
+ wrapkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ wrapkit-0.4.0.dist-info/METADATA,sha256=qLB9pg60Hkgm6Wd8HNDn_tdZ-rEGYllXKf5YhfSugmo,5990
11
+ wrapkit-0.4.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
12
+ wrapkit-0.4.0.dist-info/licenses/LICENSE,sha256=guoL63V0bzuv4TfPk4RxkITHpNwM_v3m6_2oAxFlF0k,1068
13
+ wrapkit-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hugo Morão
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.