Skip to main content

capglyph — Python SDK for CapGlyph

Python SDK for CapGlyph — image-native credential + stego payload infrastructure.

Two-type design

SDK type Transport Implementation Use case
Local SDK Pure Python (fallback) + maturin/PyO3 from Rust Core capglyph.local.LocalClient, capglyph.framing Offline seal/open/validate without server; future DCT/DWT image embed
API SDK Typed HTTP client (OpenAPI) capglyph.client.CapglyphClient (httpx or stdlib) Calling capglyphd (/v1/seal, /v1/open, /v1/embed, /v1/verify, …)

Install

pip install capglyph
# with HTTP client extras
pip install "capglyph[client]"

# from source (isolated monorepo)
pip install -e ../capglyph-sdk-python

# with dev harness
pip install -e ".[dev]"

Requires Python 3.9+.

Quickstart

Local (no server) — seal/open

from capglyph import LocalClient, Params, PayloadType
from capglyph.framing import hex_to_bytes, bytes_to_hex

k_mac = bytes.fromhex("42" * 32)  # HKDF-derived K_mac (capglyph_core::keying)
payload = bytes.fromhex("00112233445566778899aabbccddeeff")

local = LocalClient()  # prefers capglyph._core Rust extension when built, else pure Python
sealed = local.seal(payload, k_mac, Params(version=1, payload_type=PayloadType.Credential))
# or hex convenience
sealed_hex = local.seal_hex("0011...", "42"*32)

res = local.open(sealed, k_mac)
print(res.header)   # FrameHeader(version=1, payload_type=Credential, flags=0, payload_len=16)
print(res.payload.hex())

# preflight without key
hdr = local.validate(sealed)

Pure framing without LocalClient:

from capglyph.framing import seal, open_sealed, Params, PayloadType

sealed = seal(b"credential", Params(payload_type=PayloadType.Credential), k_mac)
header, payload = open_sealed(sealed, k_mac).header, open_sealed(sealed, k_mac).payload

API (capglyphd) — typed client

from capglyph import CapglyphClient

client = CapglyphClient("https://capglyph.example.com", api_key="...")

# Framing via server
sealed = client.seal(payload_hex="001122...", k_mac_hex="42"*32, payload_type=1)
payload = client.open(sealed_hex=sealed["sealed_hex"], k_mac_hex="42"*32)

# Image carrier (DCT/DWT)
with open("cover.png", "rb") as f:
    import base64
    b64 = base64.b64encode(f.read()).decode()
out = client.embed_image(b64, mode="dwt", payload_hex="deadbeef", k_mac_hex="42"*32)
present = client.verify_image(b64, mode="dwt")

Error handling is fail-closed with E_* codes (spec §8):

from capglyph import CapglyphApiError
try:
    client.open(tampered_hex, k_mac_hex)
except CapglyphApiError as e:
    print(e.code)  # E_AUTH_FAILED, E_EXPIRED, ...

Conformance

Vectors: CapGlyph/capglyph-test-vectors 1024 fixtures.

# via pytest (no cargo)
pytest
pytest tests/test_conformance.py -v

# standalone harness (mirrors capglyph-test-vectors/tools/conformance.py)
python -m capglyph.conformance --vectors ../capglyph-test-vectors/vectors
python ../capglyph-test-vectors/tools/conformance.py --vectors ../capglyph-test-vectors/vectors

Expected:

valid     256/256 pass ✓
invalid   128/128 pass ✓
malformed 128/128 pass ✓
tampered  256/256 pass ✓
expired   128/128 pass ✓
revoked   128/128 pass ✓
total    1024/1024 vectors passed — conformance ✓

Vectors resolved via CAPGLYPH_VECTORS or sibling ../capglyph-test-vectors/vectors or /mnt/data/Workspace/Projects/capglyph/capglyph-test-vectors/vectors.

Maturin extension (optional)

The Local SDK will prefer a Rust extension when present (future capglyph-core PyO3 bindings for carrier lattice). Build:

# from isolated monorepo /mnt/data/Workspace/Projects/capglyph
maturin develop -m capglyph-sdk-python/Cargo.toml  # when Cargo.toml with pyo3 is added

Current pyproject.toml is pure-Python (no Rust build); adding Cargo.toml with pyo3 is a follow-up without breaking the pure-Python conformance.

API Reference

  • capglyph.framing — seal, open_sealed, validate_frame, cbor_encode/decode/validate, hmac_tag/verify, Params, PayloadType, FrameHeader
  • capglyph.local.LocalClient — seal, seal_hex, open, open_hex, validate, using_core, embed_image (TODO), verify_image, extract_image
  • capglyph.client.CapglyphClient — seal, open, validate, embed_image, verify_image, extract_image, consume, revoke, info, health
  • capglyph.conformance — validate_vector, validate_vectors, find_vectors_root, load_vectors
  • capglyph.errors — ErrorCode, CapglyphError, classify_str

Building

pip install -e ".[dev]"
pytest

License

Apache-2.0 — same as CapGlyph/capglyph-core.

Metadata

Release files for capglyph 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for capglyph 0.1.3
File Size Uploaded Provenance Actions
capglyph-0.1.3.tar.gz 12.5 kB Without provenance Details for capglyph-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for capglyph 0.1.3
File Interpreter ABI Platform Actions
capglyph-0.1.3-py3-none-any.whl Python 3 none any Details for capglyph-0.1.3-py3-none-any.whl

Total release size: 25.9 kB

Release files / capglyph-0.1.3.tar.gz

Download URL capglyph-0.1.3.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
643ffb4be1519b03704932389d7aa31ddb0df4d6a95e7c336554034b0b54ca8f
BLAKE2b-256 checksum
How to use checksums
df523c1536fa8d86d63176ce55352bb6ec430ddbc9fce84445b7f3b87a0994c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / capglyph-0.1.3-py3-none-any.whl

Download URL capglyph-0.1.3-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0b85ad04f6bfd83cdd8c9a24e7e507945a61d9e93f5916cc76891cb3cd4b881
BLAKE2b-256 checksum
How to use checksums
a607ffd3898330b92873a6c41947838f183bf26af8480e47cc5ff4cee75eeb5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for capglyph 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page