contractgate 0.1.0__tar.gz → 0.3.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.
Files changed (31) hide show
  1. contractgate-0.3.0/.gitignore +87 -0
  2. contractgate-0.3.0/CHANGELOG.md +35 -0
  3. {contractgate-0.1.0 → contractgate-0.3.0}/LICENSE +1 -1
  4. {contractgate-0.1.0 → contractgate-0.3.0}/PKG-INFO +29 -8
  5. {contractgate-0.1.0 → contractgate-0.3.0}/README.md +23 -2
  6. {contractgate-0.1.0 → contractgate-0.3.0}/pyproject.toml +5 -5
  7. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/__init__.py +7 -2
  8. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/_transport.py +29 -0
  9. contractgate-0.3.0/src/contractgate/_version.py +1 -0
  10. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/async_client.py +29 -1
  11. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/client.py +29 -1
  12. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/exceptions.py +1 -1
  13. contractgate-0.3.0/src/contractgate/llm.py +675 -0
  14. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/models.py +57 -0
  15. contractgate-0.3.0/tests/test_client_async.py +192 -0
  16. {contractgate-0.1.0 → contractgate-0.3.0}/tests/test_client_sync.py +99 -0
  17. contractgate-0.3.0/tests/test_llm_gate.py +697 -0
  18. contractgate-0.1.0/.gitignore +0 -25
  19. contractgate-0.1.0/CHANGELOG.md +0 -14
  20. contractgate-0.1.0/src/contractgate/_version.py +0 -1
  21. contractgate-0.1.0/tests/__init__.py +0 -0
  22. contractgate-0.1.0/tests/test_client_async.py +0 -93
  23. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/contract.py +0 -0
  24. {contractgate-0.1.0 → contractgate-0.3.0}/src/contractgate/validator.py +0 -0
  25. {contractgate-0.1.0/contractgate → contractgate-0.3.0/tests}/__init__.py +0 -0
  26. {contractgate-0.1.0 → contractgate-0.3.0}/tests/conftest.py +0 -0
  27. {contractgate-0.1.0 → contractgate-0.3.0}/tests/fixtures/contracts/compliance_mode.yaml +0 -0
  28. {contractgate-0.1.0 → contractgate-0.3.0}/tests/fixtures/contracts/user_events.yaml +0 -0
  29. {contractgate-0.1.0 → contractgate-0.3.0}/tests/fixtures/contracts/with_transform.yaml +0 -0
  30. {contractgate-0.1.0 → contractgate-0.3.0}/tests/test_contract_parse.py +0 -0
  31. {contractgate-0.1.0 → contractgate-0.3.0}/tests/test_validator.py +0 -0
@@ -0,0 +1,87 @@
1
+ # Rust
2
+ target/
3
+
4
+ # Kafka Connect SMT build artifacts (built by mvn package; do not commit zips)
5
+ confluent-connector/target/
6
+ confluent-connector/*.zip
7
+ confluent-connector/*.zip.asc
8
+
9
+ # Environment
10
+ .env
11
+ .env.local
12
+
13
+ # Node / Next.js
14
+ mcp/node_modules/
15
+ mcp/dist/
16
+ dashboard/node_modules/
17
+ dashboard/.next/
18
+ dashboard/.next-verify*/
19
+ dashboard/.next-stale*/
20
+ dashboard/out/
21
+ dashboard/.env.local
22
+ dashboard/.env
23
+
24
+ # OS
25
+ .DS_Store
26
+ *.swp
27
+ *.swo
28
+
29
+ # Editor
30
+ .vscode/
31
+ .idea/
32
+ dashboard/tsconfig.tsbuildinfo
33
+
34
+ # RFC-089: build-time copies of docs/llms.txt + docs/llm-integration.md,
35
+ # and the concatenated llms-full.txt bundle generated by sync-llm-docs.mjs.
36
+ # Canonical source is docs/ — never edit these.
37
+ dashboard/public/llms.txt
38
+ dashboard/public/llm-integration.md
39
+ dashboard/public/llms-full.txt
40
+ dashboard/public/mcp-reference.md
41
+ dashboard/public/llm-output-validation.md
42
+ dashboard/public/llm-sdk-reference.md
43
+ # Added by code-review-graph
44
+ .code-review-graph/
45
+
46
+ # Python SDK build artifacts — built fresh by release.yml, never committed
47
+ sdks/python/dist/
48
+
49
+ # RFC-092 Ralph demo local env / LanceDB
50
+ demo/ralph/.venv/
51
+ demo/ralph/downstream/lancedb_data/
52
+ demo/ralph/**/__pycache__/
53
+
54
+ sdks/python/*.egg-info/
55
+ sdks/python/.eggs/
56
+ sdks/python/__pycache__/
57
+ sdks/python/**/__pycache__/
58
+ contractgate_hooks/__pycache__/
59
+ contractgate_hooks/**/__pycache__/
60
+ dashboard/test-results/
61
+ sdks/python/**/*.pyc
62
+ sdks/python/.pytest_cache/
63
+ sdks/python/pytest-cache-files-*/
64
+ sdks/python/.mypy_cache/
65
+ sdks/python/.ruff_cache/
66
+
67
+ # Claude
68
+ .claude/
69
+
70
+ # Supabase CLI local link state (project ref, pooler URL — not secrets, but local-only)
71
+ supabase/.temp/
72
+
73
+ # Marketing drafts — generated by scripts/marketing/rfc_to_content.py.
74
+ # Drafts are noisy and iterated locally; promote finalized posts outside
75
+ # drafts/ (e.g. to the website repo or a public gist) if you want them in git.
76
+ docs/marketing/drafts/
77
+ !docs/marketing/drafts/README.md
78
+
79
+ # ClankerSpanker hunter outbox (drafts, never sent)
80
+ .bot-outbox/
81
+
82
+ # Claude Code screenshot attachments (local scratch folder, never project files)
83
+ .clankerspanker-attachments/
84
+
85
+ # npm auth tokens
86
+ .npmrc
87
+ *.mcpb
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `contractgate` Python SDK.
4
+
5
+ ## 0.3.0 — 2026-10-11
6
+
7
+ RFC-094. Adds the `contractgate.llm` submodule for LLM output
8
+ validation. No breaking changes.
9
+
10
+ - New: `contractgate.llm.LLMGate` and `contractgate.llm.AsyncLLMGate`
11
+ wrap `/egress/{contract_id}` with response-shape extraction and a
12
+ bounded auto-repair re-prompt loop. Caller binds their own LLM
13
+ client (OpenAI / Anthropic / Ollama / vLLM) via `llm=...`; the SDK
14
+ takes no runtime dependency on provider SDKs.
15
+ - New: `contractgate.llm.extract_json(response)` handles OpenAI chat
16
+ JSON mode, OpenAI tool_calls, OpenAI Responses `output_parsed`,
17
+ Anthropic `tool_use` and text-block JSON, raw strings (with
18
+ markdown-fence tolerance), and dict passthrough.
19
+ - New: `contractgate.llm.LLMResponseError` for streaming responses
20
+ (rejected in v1) and unparseable shapes.
21
+ - New: `LLMGate.mask_prompt(payload, prompt_contract_id=...)` returns
22
+ the RFC-004-transformed form of a prompt dict via
23
+ `ingest(dry_run=True)`.
24
+ - Sister alias package `aischemagate` ships at the same cut.
25
+
26
+ ## 0.1.0 — 2026-04-28
27
+
28
+ Initial scaffold per RFC-005.
29
+
30
+ - `Client` (sync) + `AsyncClient` (async) over httpx.
31
+ - `ingest`, `audit`, `get_contract`, `get_version`, `playground`.
32
+ - Local validator (`Contract.from_yaml`, `CompiledContract.validate`).
33
+ - Strict parity with Rust validator: same `ViolationKind`, same field
34
+ paths, same message text. Locked via shared fixture corpus.
35
+ - No PII transforms in the local validator (RFC-004 invariant).
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 ContractGate
3
+ Copyright (c) 2026 DataContractGate
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,10 +1,10 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: contractgate
3
- Version: 0.1.0
4
- Summary: Python SDK for ContractGate — high-performance semantic contract enforcement gateway.
5
- Project-URL: Homepage, https://contractgate.dev
6
- Project-URL: Source, https://github.com/contractgate/contractgate
7
- Author: ContractGate
3
+ Version: 0.3.0
4
+ Summary: Python SDK for DataContractGate — high-performance semantic contract enforcement gateway.
5
+ Project-URL: Homepage, https://datacontractgate.com
6
+ Project-URL: Source, https://github.com/nightmoose/contractgate
7
+ Author: NightMoose, Inc.
8
8
  License: MIT
9
9
  License-File: LICENSE
10
10
  Keywords: contract,data-quality,ingestion,schema,validation
@@ -30,10 +30,10 @@ Description-Content-Type: text/markdown
30
30
 
31
31
  # contractgate (Python SDK)
32
32
 
33
- First-party Python SDK for [ContractGate][gw] — a high-performance
33
+ First-party Python SDK for [DataContractGate][gw] — a high-performance
34
34
  semantic contract enforcement gateway (Patent Pending).
35
35
 
36
- [gw]: https://contractgate.dev
36
+ [gw]: https://datacontractgate.com
37
37
 
38
38
  ## Install
39
39
 
@@ -96,6 +96,27 @@ vr = compiled.validate({
96
96
  assert vr.passed, vr.violations
97
97
  ```
98
98
 
99
+ ## GitHub Action / pre-commit
100
+
101
+ Same compile, no API key:
102
+
103
+ ```yaml
104
+ # GitHub Actions
105
+ - uses: nightmoose/contractgate/actions/validate@main
106
+ ```
107
+
108
+ ```yaml
109
+ # .pre-commit-config.yaml
110
+ repos:
111
+ - repo: https://github.com/nightmoose/contractgate
112
+ rev: main # pin to a git sha
113
+ hooks:
114
+ - id: contractgate-validate
115
+ ```
116
+
117
+ The hook only looks at `contracts/**/*.yaml`. Override `files:` in your
118
+ config if contracts live elsewhere.
119
+
99
120
  ## Caveats
100
121
 
101
122
  - **Local validator does not run RFC-004 PII transforms** (`mask`,
@@ -1,9 +1,9 @@
1
1
  # contractgate (Python SDK)
2
2
 
3
- First-party Python SDK for [ContractGate][gw] — a high-performance
3
+ First-party Python SDK for [DataContractGate][gw] — a high-performance
4
4
  semantic contract enforcement gateway (Patent Pending).
5
5
 
6
- [gw]: https://contractgate.dev
6
+ [gw]: https://datacontractgate.com
7
7
 
8
8
  ## Install
9
9
 
@@ -66,6 +66,27 @@ vr = compiled.validate({
66
66
  assert vr.passed, vr.violations
67
67
  ```
68
68
 
69
+ ## GitHub Action / pre-commit
70
+
71
+ Same compile, no API key:
72
+
73
+ ```yaml
74
+ # GitHub Actions
75
+ - uses: nightmoose/contractgate/actions/validate@main
76
+ ```
77
+
78
+ ```yaml
79
+ # .pre-commit-config.yaml
80
+ repos:
81
+ - repo: https://github.com/nightmoose/contractgate
82
+ rev: main # pin to a git sha
83
+ hooks:
84
+ - id: contractgate-validate
85
+ ```
86
+
87
+ The hook only looks at `contracts/**/*.yaml`. Override `files:` in your
88
+ config if contracts live elsewhere.
89
+
69
90
  ## Caveats
70
91
 
71
92
  - **Local validator does not run RFC-004 PII transforms** (`mask`,
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "contractgate"
7
- version = "0.1.0"
8
- description = "Python SDK for ContractGate — high-performance semantic contract enforcement gateway."
7
+ version = "0.3.0"
8
+ description = "Python SDK for DataContractGate — high-performance semantic contract enforcement gateway."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = { text = "MIT" }
12
- authors = [{ name = "ContractGate" }]
12
+ authors = [{ name = "NightMoose, Inc." }]
13
13
  keywords = ["contract", "validation", "data-quality", "ingestion", "schema"]
14
14
  classifiers = [
15
15
  "Development Status :: 3 - Alpha",
@@ -37,8 +37,8 @@ dev = [
37
37
  ]
38
38
 
39
39
  [project.urls]
40
- Homepage = "https://contractgate.dev"
41
- Source = "https://github.com/contractgate/contractgate"
40
+ Homepage = "https://datacontractgate.com"
41
+ Source = "https://github.com/nightmoose/contractgate"
42
42
 
43
43
  [tool.hatch.build.targets.wheel]
44
44
  packages = ["src/contractgate"]
@@ -1,6 +1,6 @@
1
- """ContractGate Python SDK.
1
+ """DataContractGate Python SDK.
2
2
 
3
- First-party client and pure-Python validator for the ContractGate
3
+ First-party client and pure-Python validator for the DataContractGate
4
4
  semantic contract enforcement gateway.
5
5
 
6
6
  Public surface:
@@ -14,6 +14,7 @@ Public surface:
14
14
  ViolationKind
15
15
  BatchIngestResponse, -- HTTP response shapes
16
16
  IngestEventResult,
17
+ EgressOutcome, EgressResponse,
17
18
  AuditEntry, ContractResponse,
18
19
  VersionResponse, VersionSummary,
19
20
  IngestionStats
@@ -58,6 +59,8 @@ from contractgate.models import (
58
59
  AuditEntry,
59
60
  BatchIngestResponse,
60
61
  ContractResponse,
62
+ EgressOutcome,
63
+ EgressResponse,
61
64
  IngestEventResult,
62
65
  IngestionStats,
63
66
  ValidationResult,
@@ -88,6 +91,8 @@ __all__ = [
88
91
  "ViolationKind",
89
92
  "BatchIngestResponse",
90
93
  "IngestEventResult",
94
+ "EgressOutcome",
95
+ "EgressResponse",
91
96
  "AuditEntry",
92
97
  "ContractResponse",
93
98
  "VersionResponse",
@@ -115,6 +115,35 @@ def build_ingest_request(
115
115
  )
116
116
 
117
117
 
118
+ def build_egress_request(
119
+ cfg: TransportConfig,
120
+ contract_id: str,
121
+ events: Any,
122
+ *,
123
+ version: Optional[str] = None,
124
+ disposition: Optional[str] = None,
125
+ dry_run: bool = False,
126
+ timeout: Optional[float] = None,
127
+ ) -> RequestSpec:
128
+ """Build a POST to ``/egress/{contract_id}``."""
129
+ extra_headers: Dict[str, str] = {}
130
+ if version is not None:
131
+ extra_headers["X-Contract-Version"] = version
132
+ params: Dict[str, Any] = {}
133
+ if dry_run:
134
+ params["dry_run"] = "true"
135
+ if disposition is not None:
136
+ params["disposition"] = disposition
137
+ return RequestSpec(
138
+ method="POST",
139
+ url=cfg.url(f"/egress/{contract_id}"),
140
+ headers=cfg.headers(extra_headers),
141
+ params=params or None,
142
+ json_body=events,
143
+ timeout=timeout if timeout is not None else cfg.timeout,
144
+ )
145
+
146
+
118
147
  def build_audit_request(
119
148
  cfg: TransportConfig,
120
149
  *,
@@ -0,0 +1 @@
1
+ __version__ = "0.3.0"
@@ -23,6 +23,7 @@ from contractgate.models import (
23
23
  AuditEntry,
24
24
  BatchIngestResponse,
25
25
  ContractResponse,
26
+ EgressResponse,
26
27
  IngestionStats,
27
28
  VersionResponse,
28
29
  VersionSummary,
@@ -30,7 +31,7 @@ from contractgate.models import (
30
31
 
31
32
 
32
33
  class AsyncClient:
33
- """Asynchronous client for the ContractGate gateway."""
34
+ """Asynchronous client for the DataContractGate gateway."""
34
35
 
35
36
  def __init__(
36
37
  self,
@@ -88,6 +89,33 @@ class AsyncClient:
88
89
  _, body = await self._dispatch(spec)
89
90
  return BatchIngestResponse.from_dict(body)
90
91
 
92
+ async def egress(
93
+ self,
94
+ *,
95
+ contract_id: str,
96
+ events: Any,
97
+ version: Optional[str] = None,
98
+ disposition: Optional[str] = None,
99
+ dry_run: bool = False,
100
+ timeout: Optional[float] = None,
101
+ ) -> EgressResponse:
102
+ """Validate an outbound payload via ``POST /egress/{contract_id}``.
103
+
104
+ Forward only the returned ``response.payload`` downstream — never the
105
+ original request body after a ``block`` or ``fail`` disposition.
106
+ """
107
+ spec = _t.build_egress_request(
108
+ self._cfg,
109
+ contract_id,
110
+ events,
111
+ version=version,
112
+ disposition=disposition,
113
+ dry_run=dry_run,
114
+ timeout=timeout,
115
+ )
116
+ _, body = await self._dispatch(spec)
117
+ return EgressResponse.from_dict(body)
118
+
91
119
  # ------------------------------------------------------------------
92
120
  # Audit / stats
93
121
  # ------------------------------------------------------------------
@@ -17,6 +17,7 @@ from contractgate.models import (
17
17
  AuditEntry,
18
18
  BatchIngestResponse,
19
19
  ContractResponse,
20
+ EgressResponse,
20
21
  IngestionStats,
21
22
  VersionResponse,
22
23
  VersionSummary,
@@ -24,7 +25,7 @@ from contractgate.models import (
24
25
 
25
26
 
26
27
  class Client:
27
- """Synchronous client for the ContractGate gateway.
28
+ """Synchronous client for the DataContractGate gateway.
28
29
 
29
30
  Construct with the gateway's ``base_url`` and your API key:
30
31
 
@@ -104,6 +105,33 @@ class Client:
104
105
  _, body = self._dispatch(spec)
105
106
  return BatchIngestResponse.from_dict(body)
106
107
 
108
+ def egress(
109
+ self,
110
+ *,
111
+ contract_id: str,
112
+ events: Any,
113
+ version: Optional[str] = None,
114
+ disposition: Optional[str] = None,
115
+ dry_run: bool = False,
116
+ timeout: Optional[float] = None,
117
+ ) -> EgressResponse:
118
+ """Validate an outbound payload via ``POST /egress/{contract_id}``.
119
+
120
+ Forward only the returned ``response.payload`` downstream — never the
121
+ original request body after a ``block`` or ``fail`` disposition.
122
+ """
123
+ spec = _t.build_egress_request(
124
+ self._cfg,
125
+ contract_id,
126
+ events,
127
+ version=version,
128
+ disposition=disposition,
129
+ dry_run=dry_run,
130
+ timeout=timeout,
131
+ )
132
+ _, body = self._dispatch(spec)
133
+ return EgressResponse.from_dict(body)
134
+
107
135
  # ------------------------------------------------------------------
108
136
  # Audit / stats
109
137
  # ------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- """Exception hierarchy for the ContractGate SDK.
1
+ """Exception hierarchy for the DataContractGate SDK.
2
2
 
3
3
  All SDK exceptions inherit from ``ContractGateError`` so users can
4
4
  catch the entire surface with one ``except``. HTTP-shaped errors carry