mdmp-protocol 0.1.0__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.
@@ -0,0 +1,173 @@
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
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or
141
+ agreed to in writing, Licensor provides the Work (and each
142
+ Contributor provides its Contributions) on an "AS IS" BASIS,
143
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
144
+ implied, including, without limitation, any warranties or conditions
145
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
146
+ PARTICULAR PURPOSE. You are solely responsible for determining the
147
+ appropriateness of using or redistributing the Work and assume any
148
+ risks associated with Your exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for damages, including any direct, indirect, special,
155
+ incidental, or consequential damages of any character arising as a
156
+ result of this License or out of the use or inability to use the
157
+ Work (including but not limited to damages for loss of goodwill,
158
+ work stoppage, computer failure or malfunction, or any and all
159
+ other commercial damages or losses), even if such Contributor
160
+ has been advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may choose to offer,
164
+ and charge a fee for, acceptance of support, warranty, indemnity,
165
+ or other liability obligations and/or rights consistent with this
166
+ License. However, in accepting such obligations, You may act only
167
+ on Your own behalf and on Your sole responsibility, not on behalf
168
+ of any other Contributor, and only if You agree to indemnify,
169
+ defend, and hold each Contributor harmless for any liability
170
+ incurred by, or claims asserted against, such Contributor by reason
171
+ of your accepting any such warranty or additional liability.
172
+
173
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdmp-protocol
3
+ Version: 0.1.0
4
+ Summary: MDMP core protocol for dataset contracts, grading, fingerprints, and AI lineage cards
5
+ Author: IINTS / MDMP
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/python35/MDMP
8
+ Project-URL: Documentation, https://python35.github.io/MDMP/
9
+ Project-URL: Repository, https://github.com/python35/MDMP
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: pandas>=2.0
20
+ Requires-Dist: numpy>=1.24
21
+ Requires-Dist: PyYAML>=6.0
22
+ Requires-Dist: typer>=0.12
23
+ Dynamic: license-file
24
+
25
+ # MDMP
26
+
27
+ MDMP is an open protocol and tooling stack for dataset quality and AI training provenance.
28
+
29
+ **Tagline:** _Know what your AI learned from._
30
+
31
+ ## 30-second summary
32
+
33
+ MDMP gives every dataset a contract, a grade, and a fingerprint.
34
+ It gives every model a lineage card that points to exactly which dataset fingerprints were used.
35
+
36
+ - Contract: schema, ranges, consent metadata.
37
+ - Validation: reproducible checks + deterministic grade.
38
+ - Fingerprint: immutable dataset identity (`sha256:...`).
39
+ - Lineage card: model-to-dataset traceability with stale detection.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ python -m venv .venv
45
+ source .venv/bin/activate
46
+ python -m pip install -U pip
47
+ pip install -e .
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ```bash
53
+ mdmp init --flavor health --output contracts/mdmp_contract.yaml
54
+ mdmp validate contracts/mdmp_contract.yaml data/demo_cgm.csv --output-json results/mdmp_report.json
55
+ mdmp report results/mdmp_report.json --output-html results/mdmp_dashboard.html
56
+ ```
57
+
58
+ ## Core Commands
59
+
60
+ ```bash
61
+ # grading + fingerprint
62
+ mdmp grade contracts/mdmp_contract.yaml data/demo_cgm.csv
63
+ mdmp fingerprint data/demo_cgm.csv
64
+
65
+ # stale lineage lifecycle
66
+ mdmp fingerprint-record data/demo_cgm.csv --output-json results/fingerprint.json --expires-days 365
67
+ mdmp fingerprint-check results/fingerprint.json data/demo_cgm.csv
68
+ mdmp lineage-card --model glucose_forecaster_v2 --dataset data/demo_cgm.csv --contract contracts/health_demo.yaml --output results/mdmp_model_card.yaml
69
+ mdmp lineage-card-refresh results/mdmp_model_card.yaml
70
+
71
+ # local registry scaffold
72
+ mdmp registry init --registry registry/mdmp_registry.json
73
+ mdmp registry push --registry registry/mdmp_registry.json --report results/mdmp_report.json --visibility public --model-id glucose_forecaster_v2
74
+ mdmp registry lookup sha256:YOUR_FINGERPRINT --registry registry/mdmp_registry.json
75
+ mdmp registry list --registry registry/mdmp_registry.json
76
+
77
+ # Hugging Face section export
78
+ mdmp hf-export --dataset-id python35/demo-cgm --report-json results/mdmp_report.json --output-md results/mdmp_hf_section.md
79
+ ```
80
+
81
+ ## Documentation
82
+
83
+ - Spec: `MDMP_SPEC.md`
84
+ - Docs index: `docs/index.md`
85
+ - CLI reference: `docs/reference/cli.md`
86
+ - Launch checklist: `docs/launch/launch-checklist.md`
87
+ - Contributing: `CONTRIBUTING.md`
88
+
89
+ ## Release Automation
90
+
91
+ - GitHub release workflow: `.github/workflows/release.yml`
92
+ - PyPI publish workflow: `.github/workflows/publish-pypi.yml`
93
+ - Docs deploy workflow: `.github/workflows/docs-site.yml`
94
+
95
+ ## Design Boundaries
96
+
97
+ - MDMP stores metadata + fingerprints, not raw datasets.
98
+ - Local-first workflow; cloud registry is optional.
99
+ - Complementary to DVC / MLflow / W&B.
100
+
101
+ ## Status
102
+
103
+ - Spec version: `v0.1-draft`
104
+ - Research/provenance utility.
105
+ - Not a medical device and not clinical decision support.
106
+
107
+ ## Integrations
108
+
109
+ - IINTS integration guide: `docs/IINTS_INTEGRATION.md`
@@ -0,0 +1,85 @@
1
+ # MDMP
2
+
3
+ MDMP is an open protocol and tooling stack for dataset quality and AI training provenance.
4
+
5
+ **Tagline:** _Know what your AI learned from._
6
+
7
+ ## 30-second summary
8
+
9
+ MDMP gives every dataset a contract, a grade, and a fingerprint.
10
+ It gives every model a lineage card that points to exactly which dataset fingerprints were used.
11
+
12
+ - Contract: schema, ranges, consent metadata.
13
+ - Validation: reproducible checks + deterministic grade.
14
+ - Fingerprint: immutable dataset identity (`sha256:...`).
15
+ - Lineage card: model-to-dataset traceability with stale detection.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ python -m venv .venv
21
+ source .venv/bin/activate
22
+ python -m pip install -U pip
23
+ pip install -e .
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```bash
29
+ mdmp init --flavor health --output contracts/mdmp_contract.yaml
30
+ mdmp validate contracts/mdmp_contract.yaml data/demo_cgm.csv --output-json results/mdmp_report.json
31
+ mdmp report results/mdmp_report.json --output-html results/mdmp_dashboard.html
32
+ ```
33
+
34
+ ## Core Commands
35
+
36
+ ```bash
37
+ # grading + fingerprint
38
+ mdmp grade contracts/mdmp_contract.yaml data/demo_cgm.csv
39
+ mdmp fingerprint data/demo_cgm.csv
40
+
41
+ # stale lineage lifecycle
42
+ mdmp fingerprint-record data/demo_cgm.csv --output-json results/fingerprint.json --expires-days 365
43
+ mdmp fingerprint-check results/fingerprint.json data/demo_cgm.csv
44
+ mdmp lineage-card --model glucose_forecaster_v2 --dataset data/demo_cgm.csv --contract contracts/health_demo.yaml --output results/mdmp_model_card.yaml
45
+ mdmp lineage-card-refresh results/mdmp_model_card.yaml
46
+
47
+ # local registry scaffold
48
+ mdmp registry init --registry registry/mdmp_registry.json
49
+ mdmp registry push --registry registry/mdmp_registry.json --report results/mdmp_report.json --visibility public --model-id glucose_forecaster_v2
50
+ mdmp registry lookup sha256:YOUR_FINGERPRINT --registry registry/mdmp_registry.json
51
+ mdmp registry list --registry registry/mdmp_registry.json
52
+
53
+ # Hugging Face section export
54
+ mdmp hf-export --dataset-id python35/demo-cgm --report-json results/mdmp_report.json --output-md results/mdmp_hf_section.md
55
+ ```
56
+
57
+ ## Documentation
58
+
59
+ - Spec: `MDMP_SPEC.md`
60
+ - Docs index: `docs/index.md`
61
+ - CLI reference: `docs/reference/cli.md`
62
+ - Launch checklist: `docs/launch/launch-checklist.md`
63
+ - Contributing: `CONTRIBUTING.md`
64
+
65
+ ## Release Automation
66
+
67
+ - GitHub release workflow: `.github/workflows/release.yml`
68
+ - PyPI publish workflow: `.github/workflows/publish-pypi.yml`
69
+ - Docs deploy workflow: `.github/workflows/docs-site.yml`
70
+
71
+ ## Design Boundaries
72
+
73
+ - MDMP stores metadata + fingerprints, not raw datasets.
74
+ - Local-first workflow; cloud registry is optional.
75
+ - Complementary to DVC / MLflow / W&B.
76
+
77
+ ## Status
78
+
79
+ - Spec version: `v0.1-draft`
80
+ - Research/provenance utility.
81
+ - Not a medical device and not clinical decision support.
82
+
83
+ ## Integrations
84
+
85
+ - IINTS integration guide: `docs/IINTS_INTEGRATION.md`
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mdmp-protocol"
7
+ version = "0.1.0"
8
+ description = "MDMP core protocol for dataset contracts, grading, fingerprints, and AI lineage cards"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ authors = [{name = "IINTS / MDMP"}]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Operating System :: OS Independent",
19
+ "Development Status :: 3 - Alpha",
20
+ ]
21
+ dependencies = [
22
+ "pandas>=2.0",
23
+ "numpy>=1.24",
24
+ "PyYAML>=6.0",
25
+ "typer>=0.12",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://github.com/python35/MDMP"
30
+ Documentation = "https://python35.github.io/MDMP/"
31
+ Repository = "https://github.com/python35/MDMP"
32
+
33
+ [project.scripts]
34
+ mdmp = "mdmp_core.cli:app"
35
+
36
+ [tool.setuptools]
37
+ package-dir = {"" = "src"}
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .lineage import DatasetRef, LineageCard, LineageTracker, load_lineage_card
2
+
3
+ __all__ = ["DatasetRef", "LineageCard", "LineageTracker", "load_lineage_card"]
@@ -0,0 +1,198 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from datetime import datetime, timezone
5
+ from pathlib import Path
6
+ from typing import Any, Dict, List, Optional
7
+ import json
8
+
9
+ import pandas as pd
10
+ import yaml
11
+
12
+ from mdmp_core.contracts import load_contract
13
+ from mdmp_core.fingerprint import check_fingerprint, compute_fingerprint
14
+ from mdmp_core.runner import ContractRunner
15
+
16
+
17
+ def _now_iso() -> str:
18
+ return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
19
+
20
+
21
+ @dataclass
22
+ class DatasetRef:
23
+ path: str
24
+ fingerprint: str
25
+ grade: str
26
+ rows_used: int
27
+ date_validated: str
28
+ consent: str
29
+ contract_fingerprint: str
30
+ expires: str
31
+ status: str = "valid"
32
+ stale_reason: Optional[str] = None
33
+
34
+ def to_dict(self) -> Dict[str, Any]:
35
+ return {
36
+ "path": self.path,
37
+ "fingerprint": self.fingerprint,
38
+ "grade": self.grade,
39
+ "rows_used": self.rows_used,
40
+ "date_validated": self.date_validated,
41
+ "consent": self.consent,
42
+ "contract_fingerprint": self.contract_fingerprint,
43
+ "expires": self.expires,
44
+ "status": self.status,
45
+ "stale_reason": self.stale_reason,
46
+ }
47
+
48
+ @classmethod
49
+ def from_dict(cls, payload: Dict[str, Any]) -> "DatasetRef":
50
+ return cls(
51
+ path=str(payload.get("path", "")),
52
+ fingerprint=str(payload.get("fingerprint", "")),
53
+ grade=str(payload.get("grade", "draft")),
54
+ rows_used=int(payload.get("rows_used", 0)),
55
+ date_validated=str(payload.get("date_validated", "")),
56
+ consent=str(payload.get("consent", "not_verified")),
57
+ contract_fingerprint=str(payload.get("contract_fingerprint", "")),
58
+ expires=str(payload.get("expires", "")),
59
+ status=str(payload.get("status", "valid")),
60
+ stale_reason=payload.get("stale_reason"),
61
+ )
62
+
63
+
64
+ @dataclass
65
+ class LineageCard:
66
+ model_name: str
67
+ training_date: str
68
+ datasets: List[DatasetRef] = field(default_factory=list)
69
+
70
+ @property
71
+ def stale_datasets(self) -> List[DatasetRef]:
72
+ return [row for row in self.datasets if row.status == "stale"]
73
+
74
+ @property
75
+ def lineage_status(self) -> str:
76
+ return "stale" if self.stale_datasets else "valid"
77
+
78
+ def to_dict(self) -> Dict[str, Any]:
79
+ return {
80
+ "model": {
81
+ "name": self.model_name,
82
+ "training_date": self.training_date,
83
+ "lineage_status": self.lineage_status,
84
+ "stale_lineage": bool(self.stale_datasets),
85
+ "stale_datasets": [row.fingerprint for row in self.stale_datasets],
86
+ "trained_on": [row.to_dict() for row in self.datasets],
87
+ }
88
+ }
89
+
90
+ @classmethod
91
+ def from_dict(cls, payload: Dict[str, Any]) -> "LineageCard":
92
+ model = payload.get("model", {}) if isinstance(payload, dict) else {}
93
+ trained_on = model.get("trained_on", []) if isinstance(model, dict) else []
94
+ rows: List[DatasetRef] = []
95
+ if isinstance(trained_on, list):
96
+ for entry in trained_on:
97
+ if isinstance(entry, dict):
98
+ rows.append(DatasetRef.from_dict(entry))
99
+ return cls(
100
+ model_name=str(model.get("name", "unknown_model")),
101
+ training_date=str(model.get("training_date", _now_iso())),
102
+ datasets=rows,
103
+ )
104
+
105
+ def export(self, output_path: str | Path) -> Dict[str, Any]:
106
+ payload = self.to_dict()
107
+ output = Path(output_path)
108
+ output.parent.mkdir(parents=True, exist_ok=True)
109
+ if output.suffix.lower() in {".yaml", ".yml"}:
110
+ output.write_text(yaml.safe_dump(payload, sort_keys=False), encoding="utf-8")
111
+ else:
112
+ output.write_text(json.dumps(payload, indent=2), encoding="utf-8")
113
+ return payload
114
+
115
+ def refresh(self, *, data_dir: Optional[Path] = None) -> "LineageCard":
116
+ for dataset in self.datasets:
117
+ resolved_path = Path(dataset.path)
118
+ if not resolved_path.is_file() and data_dir is not None:
119
+ candidate = data_dir / dataset.path
120
+ if candidate.is_file():
121
+ resolved_path = candidate
122
+ if not resolved_path.is_file():
123
+ dataset.status = "stale"
124
+ dataset.stale_reason = "dataset_not_found"
125
+ continue
126
+
127
+ checked = check_fingerprint(
128
+ {
129
+ "fingerprint": dataset.fingerprint,
130
+ "expires": dataset.expires,
131
+ "status": dataset.status,
132
+ "stale_reason": dataset.stale_reason,
133
+ },
134
+ data_path=resolved_path,
135
+ )
136
+ dataset.status = str(checked.get("status", "stale"))
137
+ dataset.stale_reason = checked.get("stale_reason")
138
+ return self
139
+
140
+
141
+ def load_lineage_card(path: str | Path) -> LineageCard:
142
+ card_path = Path(path)
143
+ raw = card_path.read_text(encoding="utf-8")
144
+ if card_path.suffix.lower() in {".yaml", ".yml"}:
145
+ payload = yaml.safe_load(raw) or {}
146
+ else:
147
+ payload = json.loads(raw)
148
+ if not isinstance(payload, dict):
149
+ raise ValueError("Lineage card root must be a mapping")
150
+ return LineageCard.from_dict(payload)
151
+
152
+
153
+ @dataclass
154
+ class LineageTracker:
155
+ datasets: list[DatasetRef] = field(default_factory=list)
156
+ model_name: str | None = None
157
+
158
+ def register_dataset(
159
+ self,
160
+ dataset_path: str | Path,
161
+ *,
162
+ contract: str | Path,
163
+ expires_days: int = 365,
164
+ ) -> Dict[str, Any]:
165
+ dataset_path = Path(dataset_path)
166
+ contract_path = Path(contract)
167
+ df = pd.read_csv(dataset_path)
168
+ contract_obj = load_contract(contract_path)
169
+ validation = ContractRunner(contract_obj).run(df)
170
+ fp_record = compute_fingerprint(dataset_path, expires_days=expires_days)
171
+
172
+ row = DatasetRef(
173
+ path=str(dataset_path),
174
+ fingerprint=str(fp_record["fingerprint"]),
175
+ grade=validation.grade,
176
+ rows_used=validation.row_count,
177
+ date_validated=validation.created_utc,
178
+ consent="verified" if validation.consent_verified else "not_verified",
179
+ contract_fingerprint=f"sha256:{validation.contract_fingerprint_sha256}",
180
+ expires=str(fp_record["expires"]),
181
+ status=str(fp_record["status"]),
182
+ stale_reason=fp_record.get("stale_reason"),
183
+ )
184
+ self.datasets.append(row)
185
+ return row.to_dict()
186
+
187
+ def attach_to_model(self, model_name: str) -> None:
188
+ self.model_name = model_name
189
+
190
+ def export_card(self, output_path: str | Path) -> Dict[str, Any]:
191
+ if not self.model_name:
192
+ raise ValueError("Call attach_to_model() before export_card()")
193
+ card = LineageCard(
194
+ model_name=self.model_name,
195
+ training_date=_now_iso(),
196
+ datasets=self.datasets,
197
+ )
198
+ return card.export(output_path)
@@ -0,0 +1,48 @@
1
+ from .contracts import DataContract, load_contract, parse_contract, save_contract
2
+ from .runner import (
3
+ MDMP_PROTOCOL_VERSION,
4
+ MDMP_GRADE_ORDER,
5
+ ContractRunner,
6
+ ValidationResult,
7
+ dataframe_fingerprint,
8
+ grade_meets_minimum,
9
+ )
10
+ from .fingerprint import compute_fingerprint, check_fingerprint
11
+ from .fingerprint_store import FingerprintStore
12
+ from .registry import (
13
+ REGISTRY_VERSION,
14
+ init_registry,
15
+ load_registry,
16
+ save_registry,
17
+ upsert_record,
18
+ lookup_record,
19
+ list_records,
20
+ )
21
+ from .hf import build_hf_mdmp_section, load_report
22
+ from .visualizer import build_dashboard_html
23
+
24
+ __all__ = [
25
+ "DataContract",
26
+ "load_contract",
27
+ "parse_contract",
28
+ "save_contract",
29
+ "MDMP_PROTOCOL_VERSION",
30
+ "MDMP_GRADE_ORDER",
31
+ "ContractRunner",
32
+ "ValidationResult",
33
+ "dataframe_fingerprint",
34
+ "grade_meets_minimum",
35
+ "compute_fingerprint",
36
+ "check_fingerprint",
37
+ "FingerprintStore",
38
+ "REGISTRY_VERSION",
39
+ "init_registry",
40
+ "load_registry",
41
+ "save_registry",
42
+ "upsert_record",
43
+ "lookup_record",
44
+ "list_records",
45
+ "build_hf_mdmp_section",
46
+ "load_report",
47
+ "build_dashboard_html",
48
+ ]