mloda-pii 0.2.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.

Potentially problematic release.


This version of mloda-pii might be problematic. Click here for more details.

Files changed (43) hide show
  1. mloda_pii-0.2.1/LICENSE +201 -0
  2. mloda_pii-0.2.1/PKG-INFO +29 -0
  3. mloda_pii-0.2.1/README.md +136 -0
  4. mloda_pii-0.2.1/mloda_pii/__init__.py +0 -0
  5. mloda_pii-0.2.1/mloda_pii/feature_groups/__init__.py +1 -0
  6. mloda_pii-0.2.1/mloda_pii/feature_groups/anonymizer_rs/__init__.py +13 -0
  7. mloda_pii-0.2.1/mloda_pii/feature_groups/anonymizer_rs/base.py +68 -0
  8. mloda_pii-0.2.1/mloda_pii/feature_groups/anonymizer_rs/binary.py +124 -0
  9. mloda_pii-0.2.1/mloda_pii/feature_groups/anonymizer_rs/pyarrow_anonymizer_rs.py +36 -0
  10. mloda_pii-0.2.1/mloda_pii/feature_groups/manifest.py +8 -0
  11. mloda_pii-0.2.1/mloda_pii/user_interface/__init__.py +0 -0
  12. mloda_pii-0.2.1/mloda_pii/user_interface/cli.py +53 -0
  13. mloda_pii-0.2.1/mloda_pii/user_interface/hook/__init__.py +4 -0
  14. mloda_pii-0.2.1/mloda_pii/user_interface/hook/blocking.py +46 -0
  15. mloda_pii-0.2.1/mloda_pii/user_interface/hook/claude_hook.py +63 -0
  16. mloda_pii-0.2.1/mloda_pii/user_interface/hook/cli_request.py +138 -0
  17. mloda_pii-0.2.1/mloda_pii/user_interface/hook/config.py +73 -0
  18. mloda_pii-0.2.1/mloda_pii/user_interface/hook/detect.py +164 -0
  19. mloda_pii-0.2.1/mloda_pii/user_interface/hook/handlers.py +290 -0
  20. mloda_pii-0.2.1/mloda_pii/user_interface/hook/onboarding.py +401 -0
  21. mloda_pii-0.2.1/mloda_pii/user_interface/hook/pipeline.py +148 -0
  22. mloda_pii-0.2.1/mloda_pii/user_interface/hook/server.py +114 -0
  23. mloda_pii-0.2.1/mloda_pii/user_interface/hook/settings_file.py +145 -0
  24. mloda_pii-0.2.1/mloda_pii/user_interface/hook/tokens.py +45 -0
  25. mloda_pii-0.2.1/mloda_pii/user_interface/hook/vault.py +92 -0
  26. mloda_pii-0.2.1/mloda_pii/user_interface/invitation_code/__init__.py +0 -0
  27. mloda_pii-0.2.1/mloda_pii/user_interface/invitation_code/license.py +223 -0
  28. mloda_pii-0.2.1/mloda_pii/user_interface/invitation_code/licensed_group.py +22 -0
  29. mloda_pii-0.2.1/mloda_pii/user_interface/invitation_code/store.py +99 -0
  30. mloda_pii-0.2.1/mloda_pii/user_interface/stats/__init__.py +0 -0
  31. mloda_pii-0.2.1/mloda_pii/user_interface/stats/stats.py +68 -0
  32. mloda_pii-0.2.1/mloda_pii.egg-info/PKG-INFO +29 -0
  33. mloda_pii-0.2.1/mloda_pii.egg-info/SOURCES.txt +41 -0
  34. mloda_pii-0.2.1/mloda_pii.egg-info/dependency_links.txt +1 -0
  35. mloda_pii-0.2.1/mloda_pii.egg-info/entry_points.txt +5 -0
  36. mloda_pii-0.2.1/mloda_pii.egg-info/requires.txt +18 -0
  37. mloda_pii-0.2.1/mloda_pii.egg-info/top_level.txt +1 -0
  38. mloda_pii-0.2.1/pyproject.toml +80 -0
  39. mloda_pii-0.2.1/setup.cfg +4 -0
  40. mloda_pii-0.2.1/tests/test_entry_points.py +35 -0
  41. mloda_pii-0.2.1/tests/test_mloda_imports.py +23 -0
  42. mloda_pii-0.2.1/tests/test_package_config.py +39 -0
  43. mloda_pii-0.2.1/tests/test_reserved_namespace.py +103 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: mloda-pii
3
+ Version: 0.2.1
4
+ Summary: PII detection and redaction plugins for mloda
5
+ Author-email: Tom Kaltofen <info@mloda.ai>
6
+ License-Expression: Apache-2.0
7
+ Keywords: mloda,mloda-plugin,pii,privacy,redaction,anonymization
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Python: >=3.10
14
+ License-File: LICENSE
15
+ Requires-Dist: mloda[pyarrow]<0.18.0,>=0.17.0
16
+ Requires-Dist: tomli>=1.0.0; python_version < "3.11"
17
+ Provides-Extra: hook
18
+ Requires-Dist: mloda-enterprise[anonymizer]>=0.11.0; extra == "hook"
19
+ Provides-Extra: dev
20
+ Requires-Dist: mloda-testing[binary-model]>=0.11.0; extra == "dev"
21
+ Requires-Dist: mloda-enterprise>=0.11.0; extra == "dev"
22
+ Requires-Dist: tox; extra == "dev"
23
+ Requires-Dist: tox-uv; extra == "dev"
24
+ Requires-Dist: uv>=0.13.4; extra == "dev"
25
+ Requires-Dist: pytest; extra == "dev"
26
+ Requires-Dist: ruff; extra == "dev"
27
+ Requires-Dist: mypy; extra == "dev"
28
+ Requires-Dist: bandit; extra == "dev"
29
+ Dynamic: license-file
@@ -0,0 +1,136 @@
1
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mloda-ai/mloda-plugin-template/blob/main/LICENSE)
2
+ [![mloda](https://img.shields.io/badge/built%20with-mloda-blue.svg)](https://github.com/mloda-ai/mloda)
3
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
4
+ [![Tests](https://github.com/mloda-ai/mloda-plugin-template/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/mloda-ai/mloda-plugin-template/actions/workflows/test.yml?query=branch%3Amain)
5
+ [![Scaffold](https://github.com/mloda-ai/mloda-plugin-template/actions/workflows/scaffold-test.yml/badge.svg?branch=main)](https://github.com/mloda-ai/mloda-plugin-template/actions/workflows/scaffold-test.yml?query=branch%3Amain)
6
+
7
+ # mloda-plugin-template
8
+
9
+ > **A GitHub template for creating standalone mloda plugins.** Part of the [mloda](https://github.com/mloda-ai/mloda) ecosystem for open data access. Visit [mloda.ai](https://mloda.ai) for an overview and business context, the [GitHub repository](https://github.com/mloda-ai/mloda) for technical context, or the [documentation](https://mloda-ai.github.io/mloda/) for detailed guides.
10
+
11
+ Create your own FeatureGroups, ComputeFrameworks, and Extenders as standalone packages. This repository serves two audiences:
12
+
13
+ - **Plugin authors**: click *Use this template* on GitHub to scaffold a new plugin repository, then follow the [Use this template](#use-this-template) section below.
14
+ - **Template contributors**: improving the scaffold itself? See [CONTRIBUTING.md](CONTRIBUTING.md) and the [Contribute to this template](#contribute-to-this-template) section.
15
+
16
+ ## mloda-pii
17
+
18
+ - **`<col>__pii_anonymized`**: a license-free FeatureGroup that tokenizes a string column with the anonymizer-rs binary (keyed HMAC-SHA256). Build the binary with `bin/build-anonymizer-rs.sh`.
19
+ - **Claude Code PII hook**: pseudonymizes identifiers in tool traffic through the `mloda run` CLI, licensed (default) or local. Setup, license and limits: [mloda_pii/user_interface/hook/README.md](mloda_pii/user_interface/hook/README.md); install with `uv tool install "mloda-pii[hook]"`, then `mloda-pii init <invite>` in your project. Design: [docs/pii-hook-mvp-spec.md](docs/pii-hook-mvp-spec.md).
20
+ - The hook needs mloda 0.17.0 or later, the first release with the `mloda run` CLI.
21
+
22
+ ## Related Repositories
23
+
24
+ - **[mloda](https://github.com/mloda-ai/mloda)**: The core library for open data access. Declaratively define what data you need, not how to get it. mloda handles feature resolution, dependency management, and compute framework abstraction automatically.
25
+
26
+ - **[mloda-registry](https://github.com/mloda-ai/mloda-registry)**: The central hub for discovering and sharing mloda plugins. Browse community-contributed FeatureGroups, find integration guides, and publish your own plugins for others to use.
27
+
28
+ ## Use this template
29
+
30
+ Click *Use this template* on GitHub to scaffold a new plugin repository. See [docs/getting-started.md](docs/getting-started.md) for the GitHub template-creation walkthrough; once your repository is in place, follow the steps below to customize the scaffold for your organization.
31
+
32
+ ### Structure
33
+
34
+ ```
35
+ placeholder/
36
+ ├── feature_groups/
37
+ │ ├── manifest.py # Entry-point manifest: FEATURE_GROUPS list
38
+ │ └── anonymizer_rs/ # <col>__pii_anonymized via the anonymizer-rs binary, no license
39
+ │ ├── __init__.py # Package exports
40
+ │ ├── base.py # Public API: name pattern, options
41
+ │ ├── binary.py # Binary resolution and Arrow IPC, no mloda imports
42
+ │ ├── pyarrow_anonymizer_rs.py
43
+ │ └── tests/
44
+ └── user_interface/ # mloda-pii command: hook, license, stats
45
+ ```
46
+
47
+ Each plugin kind ships an example test next to its implementation, put yours in the same
48
+ place.
49
+
50
+ ### Plugin discovery
51
+
52
+ mloda auto-discovers installed plugins via `PluginLoader.all()`, no manual import needed. Each
53
+ `manifest.py` lists its concrete classes (`FEATURE_GROUPS`, `COMPUTE_FRAMEWORKS`, `EXTENDERS`) and
54
+ `pyproject.toml` wires them up under `[project.entry-points."mloda.*"]`. Add a plugin by appending
55
+ it to the relevant list.
56
+
57
+ For an optional backend, do not wrap manifest imports in try/except. Give each optional extra its own
58
+ manifest and entry point, keep the base manifest free of optional imports, and add a
59
+ `mloda.optional_dependencies` marker entry named like the entry it protects (needed unless the backend
60
+ is one of core's built-in roots, such as pandas or polars). The marker module must import without the
61
+ backend. mloda then skips the entry when the backend is missing, lists it in
62
+ `PluginLoader.skipped_plugins()`, and still raises on your plugin's own import errors. See
63
+ [guide 04: Optional Backends](https://github.com/mloda-ai/mloda-registry/blob/main/docs/guides/04-create-plugin-package.md#optional-backends).
64
+
65
+ ### Key files
66
+
67
+ - `placeholder/` - Root namespace (rename to your organization's name)
68
+ - `pyproject.toml` - Package config (edit directly, not auto-generated)
69
+ - `.github/workflows/test.yml` - CI workflow running pytest
70
+
71
+ ### Setup Your Plugin
72
+
73
+ #### 1. Run the customization script
74
+
75
+ ```bash
76
+ ./bin/customize.sh <your-package-name> \
77
+ --author "Your Name" \
78
+ --email you@example.com \
79
+ --description "Your plugin description" \
80
+ --repository-url https://github.com/<your-org>/<your-repo>
81
+ ```
82
+
83
+ This renames `placeholder/` to `<your-package-name>/`, updates `pyproject.toml` (`name`, `authors`, `description`, `keywords`, `packages.find.include`, `pytest.testpaths`), updates `.releaserc.yaml` (`message`, `repositoryUrl`), rewrites the `[project.entry-points."mloda.*"]` manifest paths, and rewrites `from placeholder.` imports across the package. Then add your plugin's domain terms to `keywords` so it shows up in PyPI search.
84
+
85
+ The package name must be a valid Python identifier (lowercase letters, digits, underscores; must start with a letter). The names `mloda` and `mloda_plugins` are reserved: the core `mloda` package is a shared PEP 420 namespace, so a plugin that shipped `mloda/__init__.py` would make mloda unimportable for everyone who installs it. Both `bin/customize.sh` and a `tox`/CI check reject these names. All option flags are optional; if you omit them you can edit the corresponding fields by hand later.
86
+
87
+ #### 2. Verify setup
88
+
89
+ ```bash
90
+ uv venv && source .venv/bin/activate && uv sync --all-extras && tox
91
+ ```
92
+
93
+ After `tox` passes, confirm `pyproject.toml` no longer contains the template's placeholder strings:
94
+
95
+ ```bash
96
+ tox -e placeholders
97
+ ```
98
+
99
+ This is also enforced in CI: the `test.yml` workflow fails on scaffolded plugins until the template's placeholder strings are removed from `pyproject.toml`. The check covers the placeholder-bearing fields from step 1: `name`, `authors` (name and email), `description`, `tool.setuptools.packages.find.include`, and `tool.pytest.ini_options.testpaths`. It is skipped on the `mloda-ai/mloda-plugin-template` repository itself, where the placeholders are intentional.
100
+
101
+ #### 3. Remove template-only files
102
+
103
+ After `tox` passes, remove the files that only exist to support the template itself:
104
+
105
+ ```bash
106
+ rm CONTRIBUTING.md bin/customize.sh tests/test_customize_script.py
107
+ ```
108
+
109
+ `CONTRIBUTING.md` describes how to contribute to the template repo; `bin/customize.sh` is a one-shot scaffold script that has nothing left to do. `tests/test_customize_script.py` tests that script and copies it into a scratch scaffold, so it must go with it — leaving it behind fails `tox` with a `FileNotFoundError` on every subsequent run. The other test files (`test_entry_points.py`, `test_mloda_imports.py`, `test_reserved_namespace.py`) are rename-safe and should stay.
110
+
111
+ Also delete the `## First-time setup` section from `CLAUDE.md` and `AGENTS.md`. Those instructions only apply to fresh-template repos.
112
+
113
+ The remaining baseline files apply to your plugin out of the box and can be edited to match your conventions:
114
+
115
+ - `AGENTS.md` and `CLAUDE.md`: toolchain and project practices for the same `tox`/ruff/mypy/bandit pipeline you inherit. Tune the bullets if you change the toolchain.
116
+ - `CODE_OF_CONDUCT.md`: short, plain-English baseline. Update the contact (`conduct@mloda.ai` → your address) if you want enforcement to come to you.
117
+ - `.github/ISSUE_TEMPLATE/issue.yml`: unified issue form. `bin/customize.sh` already repoints its example file paths at your renamed package; edit the field wording if you want examples drawn from your own plugin.
118
+
119
+ You may also want to replace this `README.md` with one that describes your plugin.
120
+
121
+ ### Where to next
122
+
123
+ - **[mloda-registry/docs/guides/](https://github.com/mloda-ai/mloda-registry/tree/main/docs/guides/)**: full plugin development walkthrough (FeatureGroups, ComputeFrameworks, Extenders, packaging, publishing).
124
+ - **[mloda](https://github.com/mloda-ai/mloda)**: core framework reference.
125
+ - **[Claude Code skills](https://github.com/mloda-ai/mloda-registry/tree/main/.claude/skills/)**: pattern guidance and best practices for AI-assisted plugin development.
126
+ - **[docs/github-workflows.md](docs/github-workflows.md)**: CI/CD setup and required secrets for the included workflows.
127
+ - **[docs/github-repository-settings.md](docs/github-repository-settings.md)**: repository-side settings (secrets, branch protection, required checks, dependabot reviewer) you should configure after scaffolding.
128
+ - **[docs/pulling-template-updates.md](docs/pulling-template-updates.md)**: how to pull a later template fix into an already-scaffolded repo, and how to resolve the conflicts scaffolding causes.
129
+
130
+ ## Contribute to this template
131
+
132
+ This section is for people improving the scaffold itself (CI workflows, dev tooling, docs, examples). See [CONTRIBUTING.md](CONTRIBUTING.md) for the full contributor guide. Quick pointers:
133
+
134
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
135
+ - [AGENTS.md](AGENTS.md): agent guidance, project practices, issue creation
136
+ - [Issue template](.github/ISSUE_TEMPLATE/issue.yml)
File without changes
@@ -0,0 +1 @@
1
+ """Feature groups namespace package."""
@@ -0,0 +1,13 @@
1
+ """Local, license-free FeatureGroup over the anonymizer-rs binary."""
2
+
3
+ from mloda_pii.feature_groups.anonymizer_rs.base import PII_KEY_FILE_ENV, LocalAnonymizerFeatureGroup
4
+ from mloda_pii.feature_groups.anonymizer_rs.binary import AnonymizerRsError, derive_anon_key
5
+ from mloda_pii.feature_groups.anonymizer_rs.pyarrow_anonymizer_rs import PyArrowLocalAnonymizerFeatureGroup
6
+
7
+ __all__ = [
8
+ "PII_KEY_FILE_ENV",
9
+ "AnonymizerRsError",
10
+ "LocalAnonymizerFeatureGroup",
11
+ "PyArrowLocalAnonymizerFeatureGroup",
12
+ "derive_anon_key",
13
+ ]
@@ -0,0 +1,68 @@
1
+ """Framework-independent API of the local, license-free anonymizer-rs FeatureGroup."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from abc import abstractmethod
7
+ from typing import Any, ClassVar
8
+
9
+ from mloda.provider import DefaultOptionKeys, FeatureChainParserMixin, FeatureGroup, FeatureSet, property_spec
10
+ from mloda.user import DataType, Feature
11
+
12
+ from mloda_pii.feature_groups.anonymizer_rs.binary import AnonymizerRsError
13
+
14
+ PII_KEY_FILE_ENV = "pii_key_file_env"
15
+
16
+
17
+ class LocalAnonymizerFeatureGroup(FeatureChainParserMixin, FeatureGroup):
18
+ """Keyed HMAC-SHA256 token (64 hex) of one string column by the anonymizer-rs binary; no license check.
19
+
20
+ String form: ``Feature("email__pii_anonymized", Options(context={"pii_key_file_env": "KEY_FILE"}))``.
21
+ ``pii_key_file_env`` names the env var holding the path to the master key file (at least 32 bytes).
22
+ Same tokens as the licensed ``__hmac_sha256_pseudonymized`` group under the key derived by ``derive_anon_key``.
23
+ """
24
+
25
+ PREFIX_PATTERN = r".+__pii_anonymized$"
26
+ RECOGNITION_ONLY_PATTERN = True
27
+ MIN_IN_FEATURES = 1
28
+ MAX_IN_FEATURES = 1
29
+ BINARY_COMMAND_OVERRIDE: ClassVar[list[str] | None] = None
30
+ BINARY_TIMEOUT_SECONDS: ClassVar[float | None] = 60.0
31
+
32
+ PROPERTY_MAPPING: ClassVar = {
33
+ # Required and not strict, so no validator can echo it.
34
+ PII_KEY_FILE_ENV: property_spec("Name of the env var holding the path to the master key file"),
35
+ DefaultOptionKeys.in_features: property_spec("Source column to anonymize"),
36
+ }
37
+
38
+ @classmethod
39
+ def _validate_string_match(cls, _feature_name: str, _operation_config: str, _in_feature: str) -> bool:
40
+ return cls.IN_FEATURE_SEPARATOR not in _in_feature
41
+
42
+ @classmethod
43
+ def return_data_type_rule(cls, feature: Feature) -> DataType | None:
44
+ return DataType.STRING
45
+
46
+ @classmethod
47
+ def calculate_feature(cls, data: Any, features: FeatureSet) -> Any:
48
+ by_key_file: dict[str, list[tuple[str, str]]] = {}
49
+ for feature in features.features:
50
+ key_file = cls._key_file(feature.options.get(PII_KEY_FILE_ENV))
51
+ source = cls._extract_single_source_feature(feature)
52
+ by_key_file.setdefault(key_file, []).append((source, str(feature.name)))
53
+ for key_file, mappings in by_key_file.items():
54
+ data = cls._anonymize(data, mappings, key_file)
55
+ return data
56
+
57
+ @classmethod
58
+ def _key_file(cls, env_name: object) -> str:
59
+ """The key file path from the named variable; errors never echo the name's value."""
60
+ path = os.environ.get(env_name, "").strip() if isinstance(env_name, str) and env_name else ""
61
+ if not path:
62
+ raise AnonymizerRsError(f"{PII_KEY_FILE_ENV} must name a set env var holding the master key file path")
63
+ return path
64
+
65
+ @classmethod
66
+ @abstractmethod
67
+ def _anonymize(cls, data: Any, mappings: list[tuple[str, str]], key_file: str) -> Any:
68
+ """Append one token column per (source, output) pair; abstract so mloda never selects the base."""
@@ -0,0 +1,124 @@
1
+ """Runs the anonymizer-rs ``anonymizer`` binary over Arrow IPC; no mloda imports and no license check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import hmac
7
+ import json
8
+ import os
9
+ import shutil
10
+ import subprocess # nosec B404
11
+ import sys
12
+ from collections.abc import Sequence
13
+ from pathlib import Path
14
+
15
+ import pyarrow as pa
16
+
17
+ BINARY_ENV = "ANONYMIZER_BINARY"
18
+ BINARY_NAME = "anonymizer"
19
+ MIN_MASTER_KEY_BYTES = 32
20
+ _ANON_INFO = b"anonymizer-rs-anon"
21
+ _MESSAGE_LIMIT = 1024
22
+
23
+
24
+ class AnonymizerRsError(ValueError):
25
+ """The binary was missing, failed, or broke its output contract; never carries cell values."""
26
+
27
+ def __init__(self, message: str, code: int | None = None) -> None:
28
+ super().__init__(message)
29
+ self.code = code
30
+
31
+
32
+ def derive_anon_key(master_key: bytes) -> str:
33
+ """The 64-hex HMAC key anonymizer-rs derives from a master key (HKDF-SHA256, no salt)."""
34
+ if len(master_key) < MIN_MASTER_KEY_BYTES:
35
+ raise AnonymizerRsError(f"the master key must be at least {MIN_MASTER_KEY_BYTES} bytes, got {len(master_key)}")
36
+ prk = hmac.new(bytes(32), master_key, hashlib.sha256).digest()
37
+ return hmac.new(prk, _ANON_INFO + b"\x01", hashlib.sha256).hexdigest()
38
+
39
+
40
+ def find_binary(override: Sequence[str] | None = None) -> list[str]:
41
+ """argv prefix: ``override``, else ``$ANONYMIZER_BINARY``, else ``anonymizer`` on PATH."""
42
+ if override:
43
+ return list(override)
44
+ configured = os.environ.get(BINARY_ENV, "")
45
+ if configured:
46
+ path = Path(configured)
47
+ if not (path.is_absolute() and path.is_file() and os.access(path, os.X_OK)):
48
+ raise AnonymizerRsError(f"{BINARY_ENV} must be an absolute path to an executable file")
49
+ return [configured]
50
+ found = shutil.which(BINARY_NAME)
51
+ if found is None:
52
+ raise AnonymizerRsError(
53
+ f"anonymizer-rs binary not found: set {BINARY_ENV} or put '{BINARY_NAME}' on PATH "
54
+ "(bin/build-anonymizer-rs.sh builds it)"
55
+ )
56
+ return [found]
57
+
58
+
59
+ def _environment(key_file: str, columns: str) -> dict[str, str]:
60
+ env = {"PATH": os.environ.get("PATH", ""), "ANONYMIZER_KEY_FILE": key_file, "ANONYMIZER_COLUMNS": columns}
61
+ if sys.platform == "win32" and "SYSTEMROOT" in os.environ:
62
+ env["SYSTEMROOT"] = os.environ["SYSTEMROOT"]
63
+ return env
64
+
65
+
66
+ def _ipc_bytes(table: pa.Table) -> bytes:
67
+ sink = pa.BufferOutputStream()
68
+ with pa.ipc.new_stream(sink, table.schema) as writer:
69
+ writer.write_table(table)
70
+ return bytes(sink.getvalue())
71
+
72
+
73
+ def _binary_message(stderr: bytes) -> str:
74
+ """The ``error`` field of the binary's JSON stderr line, bounded; raw stderr is never echoed."""
75
+ for line in reversed(stderr.decode("utf-8", errors="replace").strip().splitlines()):
76
+ try:
77
+ parsed = json.loads(line)
78
+ except ValueError:
79
+ continue
80
+ error = parsed.get("error") if isinstance(parsed, dict) else None
81
+ if isinstance(error, str):
82
+ return error[:_MESSAGE_LIMIT]
83
+ return "no error message"
84
+
85
+
86
+ def anonymize_columns(
87
+ argv: Sequence[str], columns: Sequence[pa.ChunkedArray], key_file: str, timeout: float | None
88
+ ) -> list[pa.ChunkedArray]:
89
+ """One token column per input column, in one binary call; columns travel under positional names."""
90
+ if not columns:
91
+ return []
92
+ rows = len(columns[0])
93
+ if rows == 0:
94
+ return [pa.chunked_array([], pa.string()) for _ in columns]
95
+ inputs = [f"c{i}" for i in range(len(columns))]
96
+ outputs = [f"o{i}" for i in range(len(columns))]
97
+ table = pa.table(dict(zip(inputs, columns, strict=True)))
98
+ spec = ",".join(f"{i}:{o}" for i, o in zip(inputs, outputs, strict=True))
99
+ try:
100
+ proc = subprocess.run( # nosec B603
101
+ list(argv),
102
+ input=_ipc_bytes(table),
103
+ capture_output=True,
104
+ env=_environment(key_file, spec),
105
+ timeout=timeout,
106
+ check=False,
107
+ )
108
+ except subprocess.TimeoutExpired:
109
+ raise AnonymizerRsError(f"anonymizer-rs binary timed out after {timeout} s") from None
110
+ except OSError as exc:
111
+ raise AnonymizerRsError(f"anonymizer-rs binary could not start: {exc.strerror}") from None
112
+ if proc.returncode != 0:
113
+ message = _binary_message(proc.stderr)
114
+ raise AnonymizerRsError(f"anonymizer-rs binary exited {proc.returncode}: {message}", proc.returncode)
115
+ try:
116
+ result = pa.ipc.open_stream(proc.stdout).read_all()
117
+ except (pa.ArrowException, OSError) as exc:
118
+ raise AnonymizerRsError(f"anonymizer-rs output is not an Arrow IPC stream: {type(exc).__name__}") from None
119
+ if sorted(result.column_names) != sorted(outputs) or result.num_rows != rows:
120
+ raise AnonymizerRsError(
121
+ f"anonymizer-rs output has columns {sorted(result.column_names)} and {result.num_rows} rows, "
122
+ f"expected {sorted(outputs)} and {rows}"
123
+ )
124
+ return [result.column(name).cast(pa.string()) for name in outputs]
@@ -0,0 +1,36 @@
1
+ """PyArrow implementation of the local anonymizer-rs FeatureGroup."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import pyarrow as pa
8
+ from mloda.provider import ComputeFramework
9
+ from mloda_plugins.compute_framework.base_implementations.pyarrow.table import PyArrowTable
10
+
11
+ from mloda_pii.feature_groups.anonymizer_rs.base import LocalAnonymizerFeatureGroup
12
+ from mloda_pii.feature_groups.anonymizer_rs.binary import AnonymizerRsError, anonymize_columns, find_binary
13
+
14
+
15
+ class PyArrowLocalAnonymizerFeatureGroup(LocalAnonymizerFeatureGroup):
16
+ @classmethod
17
+ def compute_framework_rule(cls) -> set[type[ComputeFramework]]:
18
+ return {PyArrowTable}
19
+
20
+ @classmethod
21
+ def _anonymize(cls, data: Any, mappings: list[tuple[str, str]], key_file: str) -> Any:
22
+ columns = []
23
+ for source, output in mappings:
24
+ if source not in data.column_names:
25
+ raise AnonymizerRsError(f"Source column {source!r} not found; available: {sorted(data.column_names)}.")
26
+ if output in data.column_names:
27
+ raise AnonymizerRsError(f"Output column {output!r} already exists.")
28
+ column = data.column(source)
29
+ if not (pa.types.is_string(column.type) or pa.types.is_large_string(column.type)):
30
+ raise AnonymizerRsError(f"Source column {source!r} must be a string column, got {column.type}.")
31
+ columns.append(column.cast(pa.string()))
32
+ argv = find_binary(cls.BINARY_COMMAND_OVERRIDE)
33
+ tokens = anonymize_columns(argv, columns, key_file, cls.BINARY_TIMEOUT_SECONDS)
34
+ for (_, output), token_column in zip(mappings, tokens, strict=True):
35
+ data = data.append_column(output, token_column)
36
+ return data
@@ -0,0 +1,8 @@
1
+ """Entry-point manifest: concrete FeatureGroup classes this package exports to mloda discovery."""
2
+
3
+ from mloda.provider import FeatureGroup
4
+
5
+ from mloda_pii.feature_groups.anonymizer_rs import PyArrowLocalAnonymizerFeatureGroup
6
+
7
+ # Referenced by the "mloda.feature_groups" entry point in pyproject.toml. Concrete classes only.
8
+ FEATURE_GROUPS: list[type[FeatureGroup]] = [PyArrowLocalAnonymizerFeatureGroup]
File without changes