Skip to main content

Python client for the Subzero tokenization vault and LLM proxy

Project description

Subzero Python SDK

Thin Python client for the Subzero tokenization vault and LLM proxy.

Install

cd python-sdk
pip install -e ".[dev,openai,auth]"

The optional auth extra adds pyotp for TOTP code generation during dashboard login.

Two auth planes

Plane Credential Use for
Server integration API key (sz_live_...) tokenize, search, reveal, proxy, tenant admin after bootstrap
Dashboard / human JWT access token auth.*, members.*, admin.create_tenant, admin.get_tenant

Pass an API key, an access token, or both when constructing the client:

from subzero import SubzeroClient

# Vault + proxy (server-side)
vault = SubzeroClient(api_key="sz_live_...", base_url="http://127.0.0.1:8000")

# Dashboard session (platform or tenant admin JWT)
dashboard = SubzeroClient(access_token="eyJ...", base_url="http://127.0.0.1:8000")

Quick start (vault)

from subzero import SubzeroClient

client = SubzeroClient(
    api_key="sz_live_...",
    base_url="http://127.0.0.1:8000",
)
client.ready()

token = client.tokenize("SSN", "123-45-6789").token
value = client.reveal(token).value

Platform admin login (tenant provisioning)

POST /v1/tenants requires a platform-admin JWT. Log in with MFA, then create tenants:

from subzero import SubzeroClient

client = SubzeroClient(base_url="http://127.0.0.1:8000")
client.ready()

client.auth.login_platform(
    email="admin@iceberg.local",
    password="...",
    totp_code="123456",       # or totp_secret="BASE32..." with pip install 'subzero[auth]'
)

tenant = client.admin.create_tenant(name="Acme", slug="acme")
admin_key = tenant.bootstrap_api_key

# Switch to tenant admin API key for day-to-day vault/proxy setup
admin = SubzeroClient(api_key=admin_key, base_url="http://127.0.0.1:8000")
admin.admin.create_entity_type(tenant.id, name="SSN", deterministic=True)

Tenant member invites and management use client.members with a tenant-admin or platform-admin JWT.

API key scopes

Scope Vault methods Notes
tokenize tokenize, search No plaintext return
reveal reveal Server-side plaintext reveal; requires matching policy rule
reveal_grant create_reveal_grant Mint browser reveal grants only; requires matching policy rule
proxy proxy.chat.completions In-flight tokenization
admin All of the above + admin.* + delete_token Bypasses reveal policy

Browser reveal: the iframe calls POST /v1/browser/reveal with a server-minted grant. Your BFF uses a reveal_grant key to call create_reveal_grant(token, client_public_key_jwk=..., allowed_origin=...). Keep reveal keys for server pipelines that need client.reveal(token).value.

grant = client.create_reveal_grant(
    token,
    client_public_key_jwk=jwk_from_iframe,
    allowed_origin="https://app.yourcompany.com",
)

Delete requires admin. There is no delegatable delete-scoped API key at the HTTP layer. delete_token() needs an admin key even though policy rules support a delete action at the service layer.

Proxy vs reveal vs detokenize

  • Vault reveal: client.reveal(token)POST /v1/reveal, reveal-scoped key + policy
  • Proxy chat: client.proxy.chat.completions(...) — tokenizes declared patterns in-flight
  • Proxy detokenize: pass detokenize=True or use OpenAI helper below — governed by reveal policy for the proxy key, not the reveal endpoint
from subzero import create_openai_client

client = create_openai_client(
    api_key="sz_live_...",          # Subzero proxy key
    base_url="http://127.0.0.1:8000/v1",
    detokenize=True,                # X-Subzero-Detokenize: true via default_headers
)
client.chat.completions.create(model="gpt-4o", stream=False, messages=[...])

Examples

With the API running (docker compose up or uvicorn):

export SUBZERO_PLATFORM_EMAIL=admin@iceberg.local
export SUBZERO_PLATFORM_PASSWORD=...
export SUBZERO_TOTP_CODE=123456   # or SUBZERO_TOTP_SECRET / SUBZERO_ACCESS_TOKEN

python examples/hero_demo.py
python examples/vault_loop.py

Set SUBZERO_BASE_URL and OPENAI_API_KEY as needed.

Tests

pytest

PyPI

Local editable install only for now. # TODO: twine upload when ready to publish.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iceberg_subzero-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iceberg_subzero-0.1.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file iceberg_subzero-0.1.0.tar.gz.

File metadata

  • Download URL: iceberg_subzero-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for iceberg_subzero-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59041cfd3510ad3d5926cbbccdd2e4ca39e36a6611061a860ac2c32c48f194c7
MD5 8e738d3e4aad518adb7ebac1b9e1d9b0
BLAKE2b-256 cc57e351e28291e07ef062a14edb25eb5175a47bb9c5f420ec6ee8ffacbf26a2

See more details on using hashes here.

File details

Details for the file iceberg_subzero-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for iceberg_subzero-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e87a46f7c3425d926fb66d1a91139262aa26f74a44075a11713891fb1578847
MD5 b1b6b39822d94780e700c92f06c6bfd6
BLAKE2b-256 c314ffd9af4615d2df738b6beec539585bb0acef4cb261fe48533f728a364aac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page