Dispatched to wire passport-sdk-ts into Menivor; re-confirmed yesterday's finding (dac725f6) that Menivor's only real Context Passport/Identity Lock callers are Python (apps/api/app/services/context_passport.py, apps/api/app/domains/gateway/identity_lock_client.py), not TypeScript, so installing the TS SDK there would be decorative. Built the SDK that ARCHITECTURE.md §3.2.20 already flags as the one that actually unblocks Menivor's real wiring instead: a dependency-free (urllib-only) passport-sdk-python mirroring passport-sdk-ts route-for-route, same PassportApiError stable-error-code shape, same railyard_mint packaging convention (src/ layout, pyproject, unittest + mocked urlopen). 7/7 tests pass. Not yet imported by Menivor's actual codebase -- that wiring (replacing the two hand-rolled requests/httpx clients) is the real next step, tracked in plans/menivor.md and plans/railyard.md.
55 lines
2.1 KiB
Markdown
55 lines
2.1 KiB
Markdown
# Context Passport Python SDK
|
|
|
|
Dependency-free (`urllib` only) client for the Context Passport (Identity
|
|
Lock) API for Python 3.11+. Mirrors `@railyard/context-passport-sdk`
|
|
(`sdks/typescript`) route-for-route and error-shape-for-error-shape.
|
|
|
|
Built per `ARCHITECTURE.md` §3.2.20 (`passport-sdk-python`): the SDK that
|
|
actually unblocks Menivor's real integration, since Menivor's two real
|
|
Context Passport/Identity Lock callers are Python, not TypeScript --
|
|
`apps/api/app/services/context_passport.py` and
|
|
`apps/api/app/domains/gateway/identity_lock_client.py` in the Menivor repo.
|
|
|
|
```python
|
|
from railyard_context_passport import PassportClient, PassportApiError
|
|
|
|
passport = PassportClient(
|
|
base_url="https://context-passport.ereboslab.com",
|
|
api_key=os.environ["PASSPORT_API_KEY"], # operator key, or a PASSPORT_OWNER_KEYS tenant key
|
|
)
|
|
|
|
view = passport.get("pp_123")
|
|
if view["status"] == "locked" and view["head"]["assets"]["kind"] == "brand":
|
|
palette = view["head"]["assets"]["palette"]
|
|
|
|
try:
|
|
passport.update_draft("pp_123", {"kind": "brand", "voice_tone": "warmer"})
|
|
except PassportApiError as error:
|
|
if error.code == "version_locked":
|
|
... # branch a new version instead of editing the locked head
|
|
```
|
|
|
|
Every create/list/get/patch/lock/archive/unarchive/newVersion/versions/
|
|
resolve/generate/attest/artifacts route in `ARCHITECTURE.md`'s API surface
|
|
table is exposed with its real request/response shape. Non-2xx responses
|
|
raise a typed `PassportApiError` carrying the server's stable error `code`
|
|
(`version_locked`, `needs_artifact`, `resolve_unavailable`, ...).
|
|
|
|
Never ship the Passport API key to a browser or mobile binary -- keep
|
|
`PassportClient` behind your own backend, the same rule as every other
|
|
Railyard rail client (Mint, Vend).
|
|
|
|
## Run tests
|
|
|
|
```bash
|
|
cd apps/context-passport/sdks/python
|
|
python3 -m venv .venv && .venv/bin/pip install -e .
|
|
.venv/bin/python -m unittest discover -s tests
|
|
```
|
|
|
|
## Status
|
|
|
|
v0.1.0 -- the Sx0 surface area (create, draft edit, lock, version, resolve,
|
|
generate, attest, provenance, artifacts), ported 1:1 from `passport-sdk-ts`
|
|
v0.1.0. 7/7 tests pass against a mocked `urlopen`.
|