Hook event contract for OrchestKit — Pydantic models, JSON schemas, and a thin validation helper. Zero runtime deps beyond pydantic.
Project description
orchestkit-hook-contract
Pydantic v2 + JSON Schema contract for Claude Code hook events. Python sibling of the npm package @orchestkit/hook-contract. Both packages regenerate from the single source of truth at spec/hook-events.spec.yml in the repo root.
Status
- M141-3: scaffold — Pydantic models, JSON schemas, structural validator, hand-rolled codegen from spec.
- M141-4 (this change): HMAC signing protocol + reference verifier. Spec at
../hook-contract/docs/signing-rfc.md. Shared golden vectors at../hook-contract/test-vectors/signing/. - M141-6: cross-language parity gate CI — diff this output against the npm side field-by-field.
Install
pip install orchestkit-hook-contract
Requires Python 3.11+ and pydantic>=2.5.
Usage
from orchestkit_hook_contract import (
HookEvent,
HOOK_EVENT_NAMES,
PreToolUsePayload,
validate_hook_event,
)
# Structural validation
result = validate_hook_event({"event": "PreToolUse"})
if result.valid:
print("known event:", result.event)
# Typed payload access
p = PreToolUsePayload(tool_name="Bash", tool_input={"cmd": "ls"})
assert p.tool_name == "Bash"
# Pydantic envelope
e = HookEvent(event="PreToolUse", payload={"tool_name": "Bash", "tool_input": {}})
HMAC signing (M141-4)
Sign hook deliveries on the sender and verify on the receiver. Full spec: ../hook-contract/docs/signing-rfc.md.
from orchestkit_hook_contract import sign, verify, HOOK_SIGNATURE_HEADER
# Sender
import json, requests, os
body = json.dumps(event).encode("utf-8")
header = sign(body, os.environ["HOOK_SECRET"])
requests.post(url, headers={HOOK_SIGNATURE_HEADER: header, "Content-Type": "application/json"}, data=body)
# Receiver (Flask / FastAPI / etc. — capture raw body, NOT json.dumps(req.json))
result = verify(
request.headers.get(HOOK_SIGNATURE_HEADER),
request.get_data(), # raw bytes
os.environ["HOOK_SECRET"],
tolerance_sec=300,
)
if not result.valid:
abort(401, result.reason) # "missing_header" | "malformed_header" | "stale" | "signature_mismatch"
Mirrors the npm sibling byte-for-byte against the same 13 golden vectors. Zero deps beyond hmac + hashlib from the stdlib.
Coverage
13 of the 19 hook events have typed payload classes (PreToolUsePayload, NotificationPayload, etc.). The remaining 6 events stay envelope-only — their CC payloads aren't documented enough to lock down: SessionEnd, Setup, InstructionsLoaded, WorktreeCreate, WorktreeRemove, ConfigChange.
Develop
cd packages/hook-contract-py
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest -v
python scripts/codegen-py.py --check # drift gate
python scripts/codegen-py.py # regenerate from spec
mypy src/
ruff check src/ tests/
Why this package exists
The hook event surface is the contract between OrchestKit's TypeScript hook fan-out and any Python receiver (yonatan-hq/platform, custom analytics consumers). When the contracts drift, fields go missing in transit and observability lies. This package + the npm sibling both regenerate from one spec, eliminating that drift class.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orchestkit_hook_contract-0.1.1.tar.gz.
File metadata
- Download URL: orchestkit_hook_contract-0.1.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
261307e68449925ac372c4d97925772346a4327d6cf5e678b63d2dd1436b175e
|
|
| MD5 |
d222c2fe572a8ea9ad34995916ff96c4
|
|
| BLAKE2b-256 |
ebebe17fbe6de02cbfb0a9461342c623633fa17d19734a7b1cbf5cb158d0d8db
|
Provenance
The following attestation bundles were made for orchestkit_hook_contract-0.1.1.tar.gz:
Publisher:
publish-hook-contract-py.yml on yonatangross/orchestkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orchestkit_hook_contract-0.1.1.tar.gz -
Subject digest:
261307e68449925ac372c4d97925772346a4327d6cf5e678b63d2dd1436b175e - Sigstore transparency entry: 1673034785
- Sigstore integration time:
-
Permalink:
yonatangross/orchestkit@5475c1cde3fcdcdcbd5108fb5a8d31b2f4cbc2a8 -
Branch / Tag:
refs/tags/hook-contract-py/v0.1.1 - Owner: https://github.com/yonatangross
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-hook-contract-py.yml@5475c1cde3fcdcdcbd5108fb5a8d31b2f4cbc2a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file orchestkit_hook_contract-0.1.1-py3-none-any.whl.
File metadata
- Download URL: orchestkit_hook_contract-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5057f0da09c0d3913c53e98a960391263a5f9733946af4949f72e7c107eda0e1
|
|
| MD5 |
7681049a631b07c93ae7c54f109a6b75
|
|
| BLAKE2b-256 |
59cd34e06b53dc1a1a68b98becf4d0aa981b824c627ed6d103a2bcbaa302c927
|
Provenance
The following attestation bundles were made for orchestkit_hook_contract-0.1.1-py3-none-any.whl:
Publisher:
publish-hook-contract-py.yml on yonatangross/orchestkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orchestkit_hook_contract-0.1.1-py3-none-any.whl -
Subject digest:
5057f0da09c0d3913c53e98a960391263a5f9733946af4949f72e7c107eda0e1 - Sigstore transparency entry: 1673034788
- Sigstore integration time:
-
Permalink:
yonatangross/orchestkit@5475c1cde3fcdcdcbd5108fb5a8d31b2f4cbc2a8 -
Branch / Tag:
refs/tags/hook-contract-py/v0.1.1 - Owner: https://github.com/yonatangross
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-hook-contract-py.yml@5475c1cde3fcdcdcbd5108fb5a8d31b2f4cbc2a8 -
Trigger Event:
push
-
Statement type: