pycraftbox-dataframe 4.0.0__tar.gz → 4.0.1__tar.gz

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.
@@ -10,6 +10,7 @@ __pycache__/
10
10
 
11
11
  # Distribution / packaging
12
12
  .Python
13
+ packages/*/README.md
13
14
  build/
14
15
  develop-eggs/
15
16
  dist/
@@ -0,0 +1,541 @@
1
+ Metadata-Version: 2.5
2
+ Name: pycraftbox-dataframe
3
+ Version: 4.0.1
4
+ Summary: Pandas, CSV and tabular conversion utilities for pycraftbox
5
+ Project-URL: Homepage, https://gitlab.com/erch/pycraftbox
6
+ Project-URL: Repository, https://gitlab.com/erch/pycraftbox
7
+ Project-URL: Issues, https://gitlab.com/erch/pycraftbox/-/issues
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: numpy>=2.2.1
10
+ Requires-Dist: pandas>=3.0.3
11
+ Description-Content-Type: text/markdown
12
+
13
+ <div align="center">
14
+
15
+ # 🧰 PyCraftBox
16
+
17
+ **Independent Python utilities, installed only when you need them.**
18
+
19
+ [![Pipeline status](https://gitlab.com/erch/pycraftbox/badges/main/pipeline.svg?ignore_skipped=true)](https://gitlab.com/erch/pycraftbox/-/pipelines?ref=main)
20
+ [![PyPI](https://img.shields.io/pypi/v/pycraftbox?logo=pypi&logoColor=white)](https://pypi.org/project/pycraftbox/)
21
+ [![Latest release](https://gitlab.com/erch/pycraftbox/-/badges/release.svg)](https://gitlab.com/erch/pycraftbox/-/releases)
22
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB?logo=python&logoColor=white)](https://www.python.org/)
23
+ [![Built with uv](https://img.shields.io/badge/Built%20with-uv-DE5FE8?logo=astral&logoColor=white)](https://docs.astral.sh/uv/)
24
+ [![GitLab](https://img.shields.io/badge/Hosted%20on-GitLab-FC6D26?logo=gitlab&logoColor=white)](https://gitlab.com/erch/pycraftbox)
25
+
26
+ [📦 PyPI](https://pypi.org/project/pycraftbox/)
27
+ · [🚀 Pipelines](https://gitlab.com/erch/pycraftbox/-/pipelines)
28
+ · [🐛 Issues](https://gitlab.com/erch/pycraftbox/-/issues)
29
+ · [🔀 Merge requests](https://gitlab.com/erch/pycraftbox/-/merge_requests)
30
+ · [🏷️ Releases](https://gitlab.com/erch/pycraftbox/-/releases)
31
+
32
+ </div>
33
+
34
+ PyCraftBox is a collection of independently installable Python distributions
35
+ sharing the `pycraftbox` namespace. Each distribution declares and installs
36
+ only the dependencies required by its own public API.
37
+
38
+ ## 🧭 Contents
39
+
40
+ - [Distributions](#-distributions)
41
+ - [Installation](#-installation)
42
+ - [Public API](#-public-api)
43
+ - [Usage](#-usage)
44
+ - [Development](#-development)
45
+ - [PyPI publication](#-pypi-publication)
46
+
47
+ ## 📦 Distributions
48
+
49
+ | 📌 Distribution | Namespace | Main API | Dependencies |
50
+ |---|---|---|---|
51
+ | 🧱 `pycraftbox-core` | `pycraftbox.core` | `AttrDict`, `Utils`, `SysUtil`, `OSType` | None |
52
+ | 🔄 `pycraftbox-serialization` | `pycraftbox.serialization` | `BaseDataClass`, `JsonField`, `SerializableField`, `serialize` and helpers | `pycraftbox-core`, NumPy |
53
+ | 🔐 `pycraftbox-secrets` | `pycraftbox.secrets` | `SecretManager`, `SecretCredentials` | System GPG at runtime |
54
+ | 📊 `pycraftbox-dataframe` | `pycraftbox.dataframe` | `DFFileMapper`, `ColDefinition`, `ColMapping`, `Converters`, `Cleaners`, `PandasHelpers` | NumPy, pandas |
55
+ | 📗 `pycraftbox-excel` | `pycraftbox.excel` | `ExcelFileMapper`, `ColumnFormatter`, `ExcelCurrency` | `pycraftbox-dataframe`, openpyxl, XlsxWriter |
56
+ | ☁️ `pycraftbox-aws` | `pycraftbox.aws` | `AwsHelper`, `Role`, `SessionDescriptor` | boto3, JMESPath |
57
+ | 🛠️ `pycraftbox-tools` | `pycraftbox.tools` | `prepare-commit`, `PrepareCommitRunner` | Black, pytest, uv |
58
+ | 🎁 `pycraftbox` | `pycraftbox` | Convenience meta-package | `pycraftbox-core` |
59
+
60
+ > **💡 Dependency rule:** all distributions use the same major version and
61
+ > keep their dependency graph explicit. Dependencies are shared only when a
62
+ > domain builds directly on another one.
63
+
64
+ ### 🧱 `pycraftbox-core`
65
+
66
+ A dependency-free foundation for everyday Python utilities:
67
+
68
+ - `AttrDict` combines dictionary access and attribute access, including
69
+ dotted paths, nested updates and plain-dictionary conversion.
70
+ - `Utils` provides reusable helpers for values, nested mappings, dates and
71
+ object inspection.
72
+ - `SysUtil` exposes normalized operating-system and architecture detection.
73
+ - A small runtime footprint makes it suitable for configuration, scripts,
74
+ services and other domain packages.
75
+
76
+ **Value:** consistent, tested primitives with a focused API for common
77
+ application concerns.
78
+
79
+ ```bash
80
+ uv add pycraftbox-core
81
+ ```
82
+
83
+ ### 🔄 `pycraftbox-serialization`
84
+
85
+ Typed serialization for plain objects and dataclasses:
86
+
87
+ - `serialize()` recursively converts primitives, enums, dates, mappings,
88
+ sequences and objects into JSON-compatible values.
89
+ - NumPy scalar values are normalized for JSON and storage integrations.
90
+ - Recursive references are detected to keep object graphs safe.
91
+ - `SerializableField` and `JsonField` provide explicit field selection and
92
+ stable output ordering.
93
+ - `BaseDataClass` adds dictionary conversion, JSON output and reconstruction
94
+ from mappings to dataclass-oriented models.
95
+ - `build_json_key_order()` derives the stable field list from `JsonField`
96
+ annotations.
97
+ - `is_primitive()`, `is_sequence()`, `is_dict()` and `serialize_leaf()`
98
+ expose the focused serialization building blocks.
99
+
100
+ **Value:** a predictable serialization layer that preserves field order and
101
+ supports custom behavior without requiring a schema framework.
102
+
103
+ ```bash
104
+ uv add pycraftbox-serialization
105
+ ```
106
+
107
+ ### 🔐 `pycraftbox-secrets`
108
+
109
+ Credential loading from GPG-encrypted JSON files:
110
+
111
+ - `SecretManager` decrypts credentials into memory.
112
+ - `SecretCredentials` provides a typed username/password result.
113
+ - Missing files and providers are represented explicitly.
114
+ - The implementation delegates cryptography and passphrase handling to the
115
+ system GPG installation.
116
+
117
+ **Value:** a compact integration for local or server-side secret files while
118
+ keeping decrypted JSON away from disk.
119
+
120
+ ```bash
121
+ uv add pycraftbox-secrets
122
+ ```
123
+
124
+ ### 📊 `pycraftbox-dataframe`
125
+
126
+ Reusable pandas pipelines for tabular data and CSV files:
127
+
128
+ - `DFFileMapper` reads and writes DataFrames through a declarative mapping.
129
+ - `ColDefinition` controls source names, target names, types, defaults,
130
+ indexes, missing values and converters.
131
+ - `CompiledMapping` prepares mapping rules once for efficient reuse.
132
+ - `Converters` provides boolean, date, regular-expression, number, sign and
133
+ composed value conversions.
134
+ - `Cleaners` repairs malformed CSV rows for pandas' Python engine.
135
+ - `PandasHelpers` offers reusable `DataFrame.pipe()` operations.
136
+
137
+ **Value:** repeatable file ingestion and transformation rules expressed as
138
+ data rather than duplicated pandas code.
139
+
140
+ ```bash
141
+ uv add pycraftbox-dataframe
142
+ ```
143
+
144
+ ### 📗 `pycraftbox-excel`
145
+
146
+ Excel-oriented mapping built on the DataFrame package:
147
+
148
+ - `ExcelFileMapper` reads individual sheets and writes formatted workbooks.
149
+ - SpreadsheetML 2003 content is converted in memory when required.
150
+ - `ColumnFormatter` provides number, currency, date and wrapped-text
151
+ formatting.
152
+ - `ExcelCurrency` supplies reusable currency formats.
153
+ - New workbooks use XlsxWriter and existing workbooks are updated with
154
+ openpyxl.
155
+ - The same `ColDefinition` and `ColMapping` model is shared with CSV flows.
156
+
157
+ **Value:** declarative Excel I/O with formatting and append behavior, with
158
+ engine-specific details contained in the Excel distribution.
159
+
160
+ ```bash
161
+ uv add pycraftbox-excel
162
+ ```
163
+
164
+ ### ☁️ `pycraftbox-aws`
165
+
166
+ High-level helpers for recurring AWS integration tasks:
167
+
168
+ - `AwsHelper` resolves boto3 sessions from profiles, explicit credentials,
169
+ environment configuration or an existing session.
170
+ - `Role` supports sequential cross-account IAM role assumptions.
171
+ - `SessionDescriptor` groups the session, STS client, credentials and
172
+ resolved account identifier.
173
+ - Pagination and JMESPath-based extraction are available for AWS responses.
174
+ - S3 helpers upload and download UTF-8 strings and list objects or prefixes.
175
+
176
+ **Value:** less repeated credential, role-chain, pagination and S3 plumbing in
177
+ applications and automation scripts.
178
+
179
+ ```bash
180
+ uv add pycraftbox-aws
181
+ ```
182
+
183
+ ### 🛠️ `pycraftbox-tools`
184
+
185
+ Reusable development commands for uv-based Git repositories:
186
+
187
+ - The `prepare-commit` command runs Black and pytest from the repository
188
+ root.
189
+ - Optional `major`, `minor` and `patch` arguments synchronize uv workspace
190
+ package versions.
191
+ - Workspace members are discovered from `tool.uv.workspace.members`.
192
+ - Updated manifests and `uv.lock` are staged automatically.
193
+ - `PrepareCommitRunner` exposes the same workflow for Python integrations.
194
+
195
+ **Value:** one installable preparation workflow that can be reused across
196
+ single-package and workspace repositories.
197
+
198
+ ```bash
199
+ uv add --dev pycraftbox-tools
200
+ ```
201
+
202
+ ### 🎁 `pycraftbox`
203
+
204
+ A convenience meta-package for projects that prefer extras:
205
+
206
+ - `pycraftbox` installs the core distribution by default.
207
+ - Extras select `serialization`, `secrets`, `dataframe`, `excel`, `aws` or
208
+ `tools`.
209
+ - The `all` extra selects the complete functional set.
210
+ - Domain behavior remains owned by the focused distributions.
211
+
212
+ **Value:** concise dependency declarations with the same focused packages
213
+ underneath.
214
+
215
+ ## 📥 Installation
216
+
217
+ Install the distribution matching the required capability:
218
+
219
+ ```bash
220
+ uv add pycraftbox-core
221
+ uv add pycraftbox-serialization
222
+ uv add pycraftbox-secrets
223
+ uv add pycraftbox-dataframe
224
+ uv add pycraftbox-excel
225
+ uv add pycraftbox-aws
226
+ uv add --dev pycraftbox-tools
227
+ ```
228
+
229
+ For example, add the DataFrame and CSV API directly:
230
+
231
+ ```bash
232
+ uv add pycraftbox-dataframe
233
+ ```
234
+
235
+ The convenience meta-package exposes the same choices as extras:
236
+
237
+ ```bash
238
+ uv add "pycraftbox[serialization]"
239
+ uv add "pycraftbox[secrets]"
240
+ uv add "pycraftbox[dataframe]"
241
+ uv add "pycraftbox[excel]"
242
+ uv add "pycraftbox[aws]"
243
+ uv add "pycraftbox[tools]"
244
+ uv add "pycraftbox[all]"
245
+ ```
246
+
247
+ ## 🔌 Public API
248
+
249
+ ```python
250
+ from pycraftbox.core import AttrDict, OSType, SysUtil, Utils
251
+ from pycraftbox.serialization import (
252
+ BaseDataClass,
253
+ JsonField,
254
+ SerializableField,
255
+ build_json_key_order,
256
+ is_dict,
257
+ is_primitive,
258
+ is_sequence,
259
+ serialize,
260
+ serialize_leaf,
261
+ )
262
+ from pycraftbox.secrets import SecretCredentials, SecretManager
263
+ from pycraftbox.dataframe import (
264
+ Cleaners,
265
+ ColDefinition,
266
+ ColMapping,
267
+ CompiledMapping,
268
+ Converters,
269
+ DFFileMapper,
270
+ PandasHelpers,
271
+ )
272
+ from pycraftbox.excel import ColumnFormatter, ExcelCurrency, ExcelFileMapper
273
+ from pycraftbox.aws import AwsHelper, Role, SessionDescriptor
274
+ from pycraftbox.tools import PrepareCommitError, PrepareCommitRunner
275
+ ```
276
+
277
+ ### Public symbol inventory
278
+
279
+ All previous public classes remain available through the focused namespace
280
+ shown below:
281
+
282
+ | Distribution | Public symbols |
283
+ |---|---|
284
+ | `pycraftbox-core` | `AttrDict`, `Utils`, `OSType`, `SysUtil` |
285
+ | `pycraftbox-serialization` | `JsonField`, `build_json_key_order`, `BaseDataClass`, `SerializableField`, `serialize`, `is_primitive`, `is_sequence`, `is_dict`, `serialize_leaf` |
286
+ | `pycraftbox-secrets` | `SecretCredentials`, `SecretManager` |
287
+ | `pycraftbox-dataframe` | `Cleaners`, `Converters`, `PandasHelpers`, `ColDefinition`, `ColMapping`, `CompiledMapping`, `DFFileMapper` |
288
+ | `pycraftbox-excel` | `ExcelCurrency`, `ColumnFormatter`, `ExcelFileMapper` |
289
+ | `pycraftbox-aws` | `SessionDescriptor`, `Role`, `AwsHelper` |
290
+ | `pycraftbox-tools` | `PrepareCommitError`, `PrepareCommitRunner` |
291
+
292
+ ## 🧪 Usage
293
+
294
+ ### 🧱 Core utilities
295
+
296
+ `AttrDict` supports dictionary and attribute access to the same values.
297
+ `Utils` groups date, type and nested-mapping helpers. `SysUtil` reports the
298
+ current operating-system family and architecture.
299
+
300
+ ```python
301
+ from pycraftbox.core import AttrDict
302
+
303
+ config = AttrDict({"database.host": "db.internal"})
304
+ assert config.database.host == "db.internal"
305
+ assert config["database"]["host"] == "db.internal"
306
+ ```
307
+
308
+ ### 🔄 Serialization
309
+
310
+ `serialize()` handles Python object graphs. `BaseDataClass` provides dictionary
311
+ and JSON-like conversion for regular Python classes and does not require the
312
+ `dataclasses` module. It can also be inherited by a dataclass when generated
313
+ constructors and field introspection are useful.
314
+
315
+ ```python
316
+ from typing import Annotated
317
+
318
+ from pycraftbox.serialization import BaseDataClass, JsonField
319
+
320
+
321
+ class Customer(BaseDataClass):
322
+ identifier: Annotated[int, JsonField(order=0)]
323
+ name: Annotated[str, JsonField(order=1)]
324
+
325
+ def __init__(self, identifier: int, name: str) -> None:
326
+ self.identifier = identifier
327
+ self.name = name
328
+ ```
329
+
330
+ The same class can optionally use `@dataclass`:
331
+
332
+ ```python
333
+ from dataclasses import dataclass
334
+ from typing import Annotated
335
+
336
+ from pycraftbox.serialization import BaseDataClass, JsonField
337
+
338
+
339
+ @dataclass
340
+ class DataclassCustomer(BaseDataClass):
341
+ identifier: Annotated[int, JsonField(order=0)]
342
+ name: Annotated[str, JsonField(order=1)]
343
+ ```
344
+
345
+ Certain helpers that introspect constructor fields, such as
346
+ `get_dataclasse_attributes()`, specifically require a dataclass; core
347
+ serialization and reconstruction do not.
348
+
349
+ ### 📊 CSV mapping
350
+
351
+ ```python
352
+ from pycraftbox.dataframe import (
353
+ ColDefinition,
354
+ ColMapping,
355
+ CompiledMapping,
356
+ DFFileMapper,
357
+ )
358
+
359
+ mapping = ColMapping(
360
+ col_defs=[
361
+ ColDefinition(
362
+ file_col_name="Transaction ID",
363
+ df_col_name="transaction_id",
364
+ in_index=True,
365
+ )
366
+ ]
367
+ )
368
+
369
+ dataframe = DFFileMapper.read_csv(
370
+ "transactions.csv",
371
+ cpl_mapping=CompiledMapping(mapping),
372
+ sep=";",
373
+ )
374
+ ```
375
+
376
+ ### 📗 Excel mapping
377
+
378
+ `ExcelFileMapper` extends the DataFrame mapping pipeline with workbook I/O and
379
+ column formatting.
380
+
381
+ ```python
382
+ from pathlib import Path
383
+
384
+ from pycraftbox.excel import ColumnFormatter, ExcelCurrency, ExcelFileMapper
385
+
386
+ ExcelFileMapper.add_excel_sheet(
387
+ dataframe.reset_index(),
388
+ file_path=Path("report.xlsx"),
389
+ sheet_name="Transactions",
390
+ column_formatters=[
391
+ ColumnFormatter.currency([1], currency=ExcelCurrency.EUR),
392
+ ],
393
+ )
394
+ ```
395
+
396
+ ### ☁️ AWS helpers
397
+
398
+ ```python
399
+ from pycraftbox.aws import AwsHelper, Role
400
+
401
+ descriptor = AwsHelper.get_session(
402
+ aws_profile="engineering",
403
+ roles_to_assume=[
404
+ Role(role_name="Reporting", account_id="123456789012"),
405
+ ],
406
+ )
407
+ ```
408
+
409
+ ### 🔐 GPG-backed secrets
410
+
411
+ `SecretManager` delegates decryption and passphrase handling to the system
412
+ `gpg` executable.
413
+
414
+ ```python
415
+ from pathlib import Path
416
+
417
+ from pycraftbox.secrets import SecretManager
418
+
419
+ credentials = SecretManager(Path("credentials.json.gpg")).read("service")
420
+ ```
421
+
422
+ ### 🛠️ Repository preparation
423
+
424
+ Install the tools in any uv-based repository as a development dependency:
425
+
426
+ ```bash
427
+ uv add --dev pycraftbox-tools
428
+ ```
429
+
430
+ The `prepare-commit` command runs from the Git repository root. It formats
431
+ the complete repository with Black, runs pytest and can synchronize every
432
+ member of a uv workspace:
433
+
434
+ ```bash
435
+ uv run prepare-commit
436
+ uv run prepare-commit patch
437
+ uv run prepare-commit minor
438
+ uv run prepare-commit major
439
+ ```
440
+
441
+ Without a bump argument, versions remain unchanged. On a bump, all workspace
442
+ member manifests and `uv.lock` are updated and staged.
443
+
444
+ ## 🔧 Development
445
+
446
+ ```text
447
+ packages/
448
+ ├── pycraftbox/
449
+ ├── pycraftbox-core/
450
+ ├── pycraftbox-serialization/
451
+ ├── pycraftbox-secrets/
452
+ ├── pycraftbox-dataframe/
453
+ ├── pycraftbox-excel/
454
+ ├── pycraftbox-aws/
455
+ └── pycraftbox-tools/
456
+ ```
457
+
458
+ Install the workspace and run all checks:
459
+
460
+ ```bash
461
+ uv sync --all-packages
462
+ uv run pytest
463
+ uv run black --check packages python/test
464
+ uv run mypy packages/*/src
465
+ ```
466
+
467
+ Build every distribution:
468
+
469
+ ```bash
470
+ uv build --all-packages --out-dir dist
471
+ ```
472
+
473
+ The same project README is published as the long description of every
474
+ distribution. Hatchling requires that file inside each package directory.
475
+ GitLab CI creates these temporary copies before running the jobs, so only the
476
+ root README is versioned. For a local build, generate the ignored copies first:
477
+
478
+ ```bash
479
+ for package in packages/*; do
480
+ cp README.md "$package/README.md"
481
+ done
482
+ ```
483
+
484
+ Formatting, tests and synchronized version bumps use the public tools package:
485
+
486
+ ```bash
487
+ uv run prepare-commit
488
+ ```
489
+
490
+ ## 🚀 PyPI publication
491
+
492
+ GitLab CI validates, tests and builds all eight distributions on branches and
493
+ merge requests. Tagged pipelines publish every wheel and source archive to
494
+ [PyPI](https://pypi.org/project/pycraftbox/) with PyPI Trusted Publishing. GitLab
495
+ generates a short-lived OIDC token for the environment assigned to each
496
+ distribution, so no long-lived publishing secret is committed to the
497
+ repository.
498
+
499
+ Each PyPI project must have its own GitLab Trusted Publisher configured:
500
+
501
+ - Namespace: `erch`
502
+ - Project: `pycraftbox`
503
+ - Top-level CI file: `.gitlab-ci.yml`
504
+ - GitLab environment: use the corresponding value below
505
+
506
+ All Trusted Publishers must be configured before publishing a new release. Once
507
+ configured, tagged pipelines automatically upload all eight distributions after
508
+ validation, tests and builds succeed.
509
+
510
+ | PyPI Project Name | GitLab environment |
511
+ |---|---|
512
+ | `pycraftbox` | `pypi` |
513
+ | `pycraftbox-core` | `pypi-core` |
514
+ | `pycraftbox-serialization` | `pypi-serialization` |
515
+ | `pycraftbox-secrets` | `pypi-secrets` |
516
+ | `pycraftbox-dataframe` | `pypi-dataframe` |
517
+ | `pycraftbox-excel` | `pypi-excel` |
518
+ | `pycraftbox-aws` | `pypi-aws` |
519
+ | `pycraftbox-tools` | `pypi-tools` |
520
+
521
+ To publish a release:
522
+
523
+ 1. Set the same version in all package manifests with the internal release
524
+ workflow.
525
+ 2. Create and push a Git tag matching that version.
526
+ 3. Wait for the `publish:pypi` matrix jobs to upload every distribution.
527
+ 4. Verify the tagged pipeline and all packages on PyPI.
528
+ 5. Create the associated
529
+ [GitLab release](https://gitlab.com/erch/pycraftbox/-/releases/new).
530
+
531
+ PyPI stores the description in each release's metadata. Once a version exists,
532
+ publish a new version with the updated artifacts to update its description;
533
+ the `README` on the repository alone does not modify an existing release.
534
+
535
+ After publication, consumers use the standard public index:
536
+
537
+ ```bash
538
+ pip install pycraftbox
539
+ pip install pycraftbox-dataframe
540
+ pip install "pycraftbox[aws,excel]"
541
+ ```
@@ -0,0 +1,529 @@
1
+ <div align="center">
2
+
3
+ # 🧰 PyCraftBox
4
+
5
+ **Independent Python utilities, installed only when you need them.**
6
+
7
+ [![Pipeline status](https://gitlab.com/erch/pycraftbox/badges/main/pipeline.svg?ignore_skipped=true)](https://gitlab.com/erch/pycraftbox/-/pipelines?ref=main)
8
+ [![PyPI](https://img.shields.io/pypi/v/pycraftbox?logo=pypi&logoColor=white)](https://pypi.org/project/pycraftbox/)
9
+ [![Latest release](https://gitlab.com/erch/pycraftbox/-/badges/release.svg)](https://gitlab.com/erch/pycraftbox/-/releases)
10
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB?logo=python&logoColor=white)](https://www.python.org/)
11
+ [![Built with uv](https://img.shields.io/badge/Built%20with-uv-DE5FE8?logo=astral&logoColor=white)](https://docs.astral.sh/uv/)
12
+ [![GitLab](https://img.shields.io/badge/Hosted%20on-GitLab-FC6D26?logo=gitlab&logoColor=white)](https://gitlab.com/erch/pycraftbox)
13
+
14
+ [📦 PyPI](https://pypi.org/project/pycraftbox/)
15
+ · [🚀 Pipelines](https://gitlab.com/erch/pycraftbox/-/pipelines)
16
+ · [🐛 Issues](https://gitlab.com/erch/pycraftbox/-/issues)
17
+ · [🔀 Merge requests](https://gitlab.com/erch/pycraftbox/-/merge_requests)
18
+ · [🏷️ Releases](https://gitlab.com/erch/pycraftbox/-/releases)
19
+
20
+ </div>
21
+
22
+ PyCraftBox is a collection of independently installable Python distributions
23
+ sharing the `pycraftbox` namespace. Each distribution declares and installs
24
+ only the dependencies required by its own public API.
25
+
26
+ ## 🧭 Contents
27
+
28
+ - [Distributions](#-distributions)
29
+ - [Installation](#-installation)
30
+ - [Public API](#-public-api)
31
+ - [Usage](#-usage)
32
+ - [Development](#-development)
33
+ - [PyPI publication](#-pypi-publication)
34
+
35
+ ## 📦 Distributions
36
+
37
+ | 📌 Distribution | Namespace | Main API | Dependencies |
38
+ |---|---|---|---|
39
+ | 🧱 `pycraftbox-core` | `pycraftbox.core` | `AttrDict`, `Utils`, `SysUtil`, `OSType` | None |
40
+ | 🔄 `pycraftbox-serialization` | `pycraftbox.serialization` | `BaseDataClass`, `JsonField`, `SerializableField`, `serialize` and helpers | `pycraftbox-core`, NumPy |
41
+ | 🔐 `pycraftbox-secrets` | `pycraftbox.secrets` | `SecretManager`, `SecretCredentials` | System GPG at runtime |
42
+ | 📊 `pycraftbox-dataframe` | `pycraftbox.dataframe` | `DFFileMapper`, `ColDefinition`, `ColMapping`, `Converters`, `Cleaners`, `PandasHelpers` | NumPy, pandas |
43
+ | 📗 `pycraftbox-excel` | `pycraftbox.excel` | `ExcelFileMapper`, `ColumnFormatter`, `ExcelCurrency` | `pycraftbox-dataframe`, openpyxl, XlsxWriter |
44
+ | ☁️ `pycraftbox-aws` | `pycraftbox.aws` | `AwsHelper`, `Role`, `SessionDescriptor` | boto3, JMESPath |
45
+ | 🛠️ `pycraftbox-tools` | `pycraftbox.tools` | `prepare-commit`, `PrepareCommitRunner` | Black, pytest, uv |
46
+ | 🎁 `pycraftbox` | `pycraftbox` | Convenience meta-package | `pycraftbox-core` |
47
+
48
+ > **💡 Dependency rule:** all distributions use the same major version and
49
+ > keep their dependency graph explicit. Dependencies are shared only when a
50
+ > domain builds directly on another one.
51
+
52
+ ### 🧱 `pycraftbox-core`
53
+
54
+ A dependency-free foundation for everyday Python utilities:
55
+
56
+ - `AttrDict` combines dictionary access and attribute access, including
57
+ dotted paths, nested updates and plain-dictionary conversion.
58
+ - `Utils` provides reusable helpers for values, nested mappings, dates and
59
+ object inspection.
60
+ - `SysUtil` exposes normalized operating-system and architecture detection.
61
+ - A small runtime footprint makes it suitable for configuration, scripts,
62
+ services and other domain packages.
63
+
64
+ **Value:** consistent, tested primitives with a focused API for common
65
+ application concerns.
66
+
67
+ ```bash
68
+ uv add pycraftbox-core
69
+ ```
70
+
71
+ ### 🔄 `pycraftbox-serialization`
72
+
73
+ Typed serialization for plain objects and dataclasses:
74
+
75
+ - `serialize()` recursively converts primitives, enums, dates, mappings,
76
+ sequences and objects into JSON-compatible values.
77
+ - NumPy scalar values are normalized for JSON and storage integrations.
78
+ - Recursive references are detected to keep object graphs safe.
79
+ - `SerializableField` and `JsonField` provide explicit field selection and
80
+ stable output ordering.
81
+ - `BaseDataClass` adds dictionary conversion, JSON output and reconstruction
82
+ from mappings to dataclass-oriented models.
83
+ - `build_json_key_order()` derives the stable field list from `JsonField`
84
+ annotations.
85
+ - `is_primitive()`, `is_sequence()`, `is_dict()` and `serialize_leaf()`
86
+ expose the focused serialization building blocks.
87
+
88
+ **Value:** a predictable serialization layer that preserves field order and
89
+ supports custom behavior without requiring a schema framework.
90
+
91
+ ```bash
92
+ uv add pycraftbox-serialization
93
+ ```
94
+
95
+ ### 🔐 `pycraftbox-secrets`
96
+
97
+ Credential loading from GPG-encrypted JSON files:
98
+
99
+ - `SecretManager` decrypts credentials into memory.
100
+ - `SecretCredentials` provides a typed username/password result.
101
+ - Missing files and providers are represented explicitly.
102
+ - The implementation delegates cryptography and passphrase handling to the
103
+ system GPG installation.
104
+
105
+ **Value:** a compact integration for local or server-side secret files while
106
+ keeping decrypted JSON away from disk.
107
+
108
+ ```bash
109
+ uv add pycraftbox-secrets
110
+ ```
111
+
112
+ ### 📊 `pycraftbox-dataframe`
113
+
114
+ Reusable pandas pipelines for tabular data and CSV files:
115
+
116
+ - `DFFileMapper` reads and writes DataFrames through a declarative mapping.
117
+ - `ColDefinition` controls source names, target names, types, defaults,
118
+ indexes, missing values and converters.
119
+ - `CompiledMapping` prepares mapping rules once for efficient reuse.
120
+ - `Converters` provides boolean, date, regular-expression, number, sign and
121
+ composed value conversions.
122
+ - `Cleaners` repairs malformed CSV rows for pandas' Python engine.
123
+ - `PandasHelpers` offers reusable `DataFrame.pipe()` operations.
124
+
125
+ **Value:** repeatable file ingestion and transformation rules expressed as
126
+ data rather than duplicated pandas code.
127
+
128
+ ```bash
129
+ uv add pycraftbox-dataframe
130
+ ```
131
+
132
+ ### 📗 `pycraftbox-excel`
133
+
134
+ Excel-oriented mapping built on the DataFrame package:
135
+
136
+ - `ExcelFileMapper` reads individual sheets and writes formatted workbooks.
137
+ - SpreadsheetML 2003 content is converted in memory when required.
138
+ - `ColumnFormatter` provides number, currency, date and wrapped-text
139
+ formatting.
140
+ - `ExcelCurrency` supplies reusable currency formats.
141
+ - New workbooks use XlsxWriter and existing workbooks are updated with
142
+ openpyxl.
143
+ - The same `ColDefinition` and `ColMapping` model is shared with CSV flows.
144
+
145
+ **Value:** declarative Excel I/O with formatting and append behavior, with
146
+ engine-specific details contained in the Excel distribution.
147
+
148
+ ```bash
149
+ uv add pycraftbox-excel
150
+ ```
151
+
152
+ ### ☁️ `pycraftbox-aws`
153
+
154
+ High-level helpers for recurring AWS integration tasks:
155
+
156
+ - `AwsHelper` resolves boto3 sessions from profiles, explicit credentials,
157
+ environment configuration or an existing session.
158
+ - `Role` supports sequential cross-account IAM role assumptions.
159
+ - `SessionDescriptor` groups the session, STS client, credentials and
160
+ resolved account identifier.
161
+ - Pagination and JMESPath-based extraction are available for AWS responses.
162
+ - S3 helpers upload and download UTF-8 strings and list objects or prefixes.
163
+
164
+ **Value:** less repeated credential, role-chain, pagination and S3 plumbing in
165
+ applications and automation scripts.
166
+
167
+ ```bash
168
+ uv add pycraftbox-aws
169
+ ```
170
+
171
+ ### 🛠️ `pycraftbox-tools`
172
+
173
+ Reusable development commands for uv-based Git repositories:
174
+
175
+ - The `prepare-commit` command runs Black and pytest from the repository
176
+ root.
177
+ - Optional `major`, `minor` and `patch` arguments synchronize uv workspace
178
+ package versions.
179
+ - Workspace members are discovered from `tool.uv.workspace.members`.
180
+ - Updated manifests and `uv.lock` are staged automatically.
181
+ - `PrepareCommitRunner` exposes the same workflow for Python integrations.
182
+
183
+ **Value:** one installable preparation workflow that can be reused across
184
+ single-package and workspace repositories.
185
+
186
+ ```bash
187
+ uv add --dev pycraftbox-tools
188
+ ```
189
+
190
+ ### 🎁 `pycraftbox`
191
+
192
+ A convenience meta-package for projects that prefer extras:
193
+
194
+ - `pycraftbox` installs the core distribution by default.
195
+ - Extras select `serialization`, `secrets`, `dataframe`, `excel`, `aws` or
196
+ `tools`.
197
+ - The `all` extra selects the complete functional set.
198
+ - Domain behavior remains owned by the focused distributions.
199
+
200
+ **Value:** concise dependency declarations with the same focused packages
201
+ underneath.
202
+
203
+ ## 📥 Installation
204
+
205
+ Install the distribution matching the required capability:
206
+
207
+ ```bash
208
+ uv add pycraftbox-core
209
+ uv add pycraftbox-serialization
210
+ uv add pycraftbox-secrets
211
+ uv add pycraftbox-dataframe
212
+ uv add pycraftbox-excel
213
+ uv add pycraftbox-aws
214
+ uv add --dev pycraftbox-tools
215
+ ```
216
+
217
+ For example, add the DataFrame and CSV API directly:
218
+
219
+ ```bash
220
+ uv add pycraftbox-dataframe
221
+ ```
222
+
223
+ The convenience meta-package exposes the same choices as extras:
224
+
225
+ ```bash
226
+ uv add "pycraftbox[serialization]"
227
+ uv add "pycraftbox[secrets]"
228
+ uv add "pycraftbox[dataframe]"
229
+ uv add "pycraftbox[excel]"
230
+ uv add "pycraftbox[aws]"
231
+ uv add "pycraftbox[tools]"
232
+ uv add "pycraftbox[all]"
233
+ ```
234
+
235
+ ## 🔌 Public API
236
+
237
+ ```python
238
+ from pycraftbox.core import AttrDict, OSType, SysUtil, Utils
239
+ from pycraftbox.serialization import (
240
+ BaseDataClass,
241
+ JsonField,
242
+ SerializableField,
243
+ build_json_key_order,
244
+ is_dict,
245
+ is_primitive,
246
+ is_sequence,
247
+ serialize,
248
+ serialize_leaf,
249
+ )
250
+ from pycraftbox.secrets import SecretCredentials, SecretManager
251
+ from pycraftbox.dataframe import (
252
+ Cleaners,
253
+ ColDefinition,
254
+ ColMapping,
255
+ CompiledMapping,
256
+ Converters,
257
+ DFFileMapper,
258
+ PandasHelpers,
259
+ )
260
+ from pycraftbox.excel import ColumnFormatter, ExcelCurrency, ExcelFileMapper
261
+ from pycraftbox.aws import AwsHelper, Role, SessionDescriptor
262
+ from pycraftbox.tools import PrepareCommitError, PrepareCommitRunner
263
+ ```
264
+
265
+ ### Public symbol inventory
266
+
267
+ All previous public classes remain available through the focused namespace
268
+ shown below:
269
+
270
+ | Distribution | Public symbols |
271
+ |---|---|
272
+ | `pycraftbox-core` | `AttrDict`, `Utils`, `OSType`, `SysUtil` |
273
+ | `pycraftbox-serialization` | `JsonField`, `build_json_key_order`, `BaseDataClass`, `SerializableField`, `serialize`, `is_primitive`, `is_sequence`, `is_dict`, `serialize_leaf` |
274
+ | `pycraftbox-secrets` | `SecretCredentials`, `SecretManager` |
275
+ | `pycraftbox-dataframe` | `Cleaners`, `Converters`, `PandasHelpers`, `ColDefinition`, `ColMapping`, `CompiledMapping`, `DFFileMapper` |
276
+ | `pycraftbox-excel` | `ExcelCurrency`, `ColumnFormatter`, `ExcelFileMapper` |
277
+ | `pycraftbox-aws` | `SessionDescriptor`, `Role`, `AwsHelper` |
278
+ | `pycraftbox-tools` | `PrepareCommitError`, `PrepareCommitRunner` |
279
+
280
+ ## 🧪 Usage
281
+
282
+ ### 🧱 Core utilities
283
+
284
+ `AttrDict` supports dictionary and attribute access to the same values.
285
+ `Utils` groups date, type and nested-mapping helpers. `SysUtil` reports the
286
+ current operating-system family and architecture.
287
+
288
+ ```python
289
+ from pycraftbox.core import AttrDict
290
+
291
+ config = AttrDict({"database.host": "db.internal"})
292
+ assert config.database.host == "db.internal"
293
+ assert config["database"]["host"] == "db.internal"
294
+ ```
295
+
296
+ ### 🔄 Serialization
297
+
298
+ `serialize()` handles Python object graphs. `BaseDataClass` provides dictionary
299
+ and JSON-like conversion for regular Python classes and does not require the
300
+ `dataclasses` module. It can also be inherited by a dataclass when generated
301
+ constructors and field introspection are useful.
302
+
303
+ ```python
304
+ from typing import Annotated
305
+
306
+ from pycraftbox.serialization import BaseDataClass, JsonField
307
+
308
+
309
+ class Customer(BaseDataClass):
310
+ identifier: Annotated[int, JsonField(order=0)]
311
+ name: Annotated[str, JsonField(order=1)]
312
+
313
+ def __init__(self, identifier: int, name: str) -> None:
314
+ self.identifier = identifier
315
+ self.name = name
316
+ ```
317
+
318
+ The same class can optionally use `@dataclass`:
319
+
320
+ ```python
321
+ from dataclasses import dataclass
322
+ from typing import Annotated
323
+
324
+ from pycraftbox.serialization import BaseDataClass, JsonField
325
+
326
+
327
+ @dataclass
328
+ class DataclassCustomer(BaseDataClass):
329
+ identifier: Annotated[int, JsonField(order=0)]
330
+ name: Annotated[str, JsonField(order=1)]
331
+ ```
332
+
333
+ Certain helpers that introspect constructor fields, such as
334
+ `get_dataclasse_attributes()`, specifically require a dataclass; core
335
+ serialization and reconstruction do not.
336
+
337
+ ### 📊 CSV mapping
338
+
339
+ ```python
340
+ from pycraftbox.dataframe import (
341
+ ColDefinition,
342
+ ColMapping,
343
+ CompiledMapping,
344
+ DFFileMapper,
345
+ )
346
+
347
+ mapping = ColMapping(
348
+ col_defs=[
349
+ ColDefinition(
350
+ file_col_name="Transaction ID",
351
+ df_col_name="transaction_id",
352
+ in_index=True,
353
+ )
354
+ ]
355
+ )
356
+
357
+ dataframe = DFFileMapper.read_csv(
358
+ "transactions.csv",
359
+ cpl_mapping=CompiledMapping(mapping),
360
+ sep=";",
361
+ )
362
+ ```
363
+
364
+ ### 📗 Excel mapping
365
+
366
+ `ExcelFileMapper` extends the DataFrame mapping pipeline with workbook I/O and
367
+ column formatting.
368
+
369
+ ```python
370
+ from pathlib import Path
371
+
372
+ from pycraftbox.excel import ColumnFormatter, ExcelCurrency, ExcelFileMapper
373
+
374
+ ExcelFileMapper.add_excel_sheet(
375
+ dataframe.reset_index(),
376
+ file_path=Path("report.xlsx"),
377
+ sheet_name="Transactions",
378
+ column_formatters=[
379
+ ColumnFormatter.currency([1], currency=ExcelCurrency.EUR),
380
+ ],
381
+ )
382
+ ```
383
+
384
+ ### ☁️ AWS helpers
385
+
386
+ ```python
387
+ from pycraftbox.aws import AwsHelper, Role
388
+
389
+ descriptor = AwsHelper.get_session(
390
+ aws_profile="engineering",
391
+ roles_to_assume=[
392
+ Role(role_name="Reporting", account_id="123456789012"),
393
+ ],
394
+ )
395
+ ```
396
+
397
+ ### 🔐 GPG-backed secrets
398
+
399
+ `SecretManager` delegates decryption and passphrase handling to the system
400
+ `gpg` executable.
401
+
402
+ ```python
403
+ from pathlib import Path
404
+
405
+ from pycraftbox.secrets import SecretManager
406
+
407
+ credentials = SecretManager(Path("credentials.json.gpg")).read("service")
408
+ ```
409
+
410
+ ### 🛠️ Repository preparation
411
+
412
+ Install the tools in any uv-based repository as a development dependency:
413
+
414
+ ```bash
415
+ uv add --dev pycraftbox-tools
416
+ ```
417
+
418
+ The `prepare-commit` command runs from the Git repository root. It formats
419
+ the complete repository with Black, runs pytest and can synchronize every
420
+ member of a uv workspace:
421
+
422
+ ```bash
423
+ uv run prepare-commit
424
+ uv run prepare-commit patch
425
+ uv run prepare-commit minor
426
+ uv run prepare-commit major
427
+ ```
428
+
429
+ Without a bump argument, versions remain unchanged. On a bump, all workspace
430
+ member manifests and `uv.lock` are updated and staged.
431
+
432
+ ## 🔧 Development
433
+
434
+ ```text
435
+ packages/
436
+ ├── pycraftbox/
437
+ ├── pycraftbox-core/
438
+ ├── pycraftbox-serialization/
439
+ ├── pycraftbox-secrets/
440
+ ├── pycraftbox-dataframe/
441
+ ├── pycraftbox-excel/
442
+ ├── pycraftbox-aws/
443
+ └── pycraftbox-tools/
444
+ ```
445
+
446
+ Install the workspace and run all checks:
447
+
448
+ ```bash
449
+ uv sync --all-packages
450
+ uv run pytest
451
+ uv run black --check packages python/test
452
+ uv run mypy packages/*/src
453
+ ```
454
+
455
+ Build every distribution:
456
+
457
+ ```bash
458
+ uv build --all-packages --out-dir dist
459
+ ```
460
+
461
+ The same project README is published as the long description of every
462
+ distribution. Hatchling requires that file inside each package directory.
463
+ GitLab CI creates these temporary copies before running the jobs, so only the
464
+ root README is versioned. For a local build, generate the ignored copies first:
465
+
466
+ ```bash
467
+ for package in packages/*; do
468
+ cp README.md "$package/README.md"
469
+ done
470
+ ```
471
+
472
+ Formatting, tests and synchronized version bumps use the public tools package:
473
+
474
+ ```bash
475
+ uv run prepare-commit
476
+ ```
477
+
478
+ ## 🚀 PyPI publication
479
+
480
+ GitLab CI validates, tests and builds all eight distributions on branches and
481
+ merge requests. Tagged pipelines publish every wheel and source archive to
482
+ [PyPI](https://pypi.org/project/pycraftbox/) with PyPI Trusted Publishing. GitLab
483
+ generates a short-lived OIDC token for the environment assigned to each
484
+ distribution, so no long-lived publishing secret is committed to the
485
+ repository.
486
+
487
+ Each PyPI project must have its own GitLab Trusted Publisher configured:
488
+
489
+ - Namespace: `erch`
490
+ - Project: `pycraftbox`
491
+ - Top-level CI file: `.gitlab-ci.yml`
492
+ - GitLab environment: use the corresponding value below
493
+
494
+ All Trusted Publishers must be configured before publishing a new release. Once
495
+ configured, tagged pipelines automatically upload all eight distributions after
496
+ validation, tests and builds succeed.
497
+
498
+ | PyPI Project Name | GitLab environment |
499
+ |---|---|
500
+ | `pycraftbox` | `pypi` |
501
+ | `pycraftbox-core` | `pypi-core` |
502
+ | `pycraftbox-serialization` | `pypi-serialization` |
503
+ | `pycraftbox-secrets` | `pypi-secrets` |
504
+ | `pycraftbox-dataframe` | `pypi-dataframe` |
505
+ | `pycraftbox-excel` | `pypi-excel` |
506
+ | `pycraftbox-aws` | `pypi-aws` |
507
+ | `pycraftbox-tools` | `pypi-tools` |
508
+
509
+ To publish a release:
510
+
511
+ 1. Set the same version in all package manifests with the internal release
512
+ workflow.
513
+ 2. Create and push a Git tag matching that version.
514
+ 3. Wait for the `publish:pypi` matrix jobs to upload every distribution.
515
+ 4. Verify the tagged pipeline and all packages on PyPI.
516
+ 5. Create the associated
517
+ [GitLab release](https://gitlab.com/erch/pycraftbox/-/releases/new).
518
+
519
+ PyPI stores the description in each release's metadata. Once a version exists,
520
+ publish a new version with the updated artifacts to update its description;
521
+ the `README` on the repository alone does not modify an existing release.
522
+
523
+ After publication, consumers use the standard public index:
524
+
525
+ ```bash
526
+ pip install pycraftbox
527
+ pip install pycraftbox-dataframe
528
+ pip install "pycraftbox[aws,excel]"
529
+ ```
@@ -1,7 +1,8 @@
1
1
  [project]
2
2
  name = "pycraftbox-dataframe"
3
- version = "4.0.0"
3
+ version = "4.0.1"
4
4
  description = "Pandas, CSV and tabular conversion utilities for pycraftbox"
5
+ readme = "README.md"
5
6
  requires-python = ">=3.12"
6
7
  dependencies = [
7
8
  "numpy>=2.2.1",
@@ -1,10 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: pycraftbox-dataframe
3
- Version: 4.0.0
4
- Summary: Pandas, CSV and tabular conversion utilities for pycraftbox
5
- Project-URL: Homepage, https://gitlab.com/erch/pycraftbox
6
- Project-URL: Repository, https://gitlab.com/erch/pycraftbox
7
- Project-URL: Issues, https://gitlab.com/erch/pycraftbox/-/issues
8
- Requires-Python: >=3.12
9
- Requires-Dist: numpy>=2.2.1
10
- Requires-Dist: pandas>=3.0.3