Skip to main content

Truthlocks Python SDK

Issue signed records, verify an existing attestation, and retrieve its proof bundle from Python applications and services.

Runtime: Python 3.9+ · Package: truthlock · License: MIT

API reference · Console · Source

Install

python -m pip install truthlock

Verify a record

Set TRUTHLOCKS_API_KEY and TRUTHLOCKS_ATTESTATION_ID before running:

import os
from truthlock import TruthlockClient, Verdict

with TruthlockClient(api_key=os.environ["TRUTHLOCKS_API_KEY"]) as client:
    result = client.verify.verify_online(os.environ["TRUTHLOCKS_ATTESTATION_ID"])
    print(result.verdict.value)
    if result.verdict == Verdict.VALID:
        print("Record verified")

A tl_test_ key selects the sandbox host by default. Use base_url to override it; production and sandbox credentials must match the selected host. The workspace is derived from credentials, not a tenant header. A record-only verdict does not check an unrelated local file: pass payload_b64url or document_hash_hex for content checks.

Mint bytes

Use an existing issuer and signing key that is available for signing in your workspace:

import base64
import os
import uuid
from truthlock import TruthlockClient

payload = base64.urlsafe_b64encode(b"Example record").rstrip(b"=").decode("ascii")
request_key = str(uuid.uuid4())  # retain alongside the body for a retry
with TruthlockClient(api_key=os.environ["TRUTHLOCKS_API_KEY"]) as client:
    record = client.attestations.mint(
        issuer_id=os.environ["TRUTHLOCKS_ISSUER_ID"],
        kid=os.environ["TRUTHLOCKS_KEY_ID"],
        alg=os.environ["TRUTHLOCKS_ALGORITHM"],
        payload_b64url=payload,
        idempotency_key=request_key,
    )
    print(record.attestation_id)

The algorithm must match the signing key. Registering a public key does not upload its private key or enable service-side signing with that private key.

Behavior

  • Resources: issuers, keys, attestations, online verification and receipts.
  • Current proof bundles retain their key, checkpoint, inclusion proof and audit fields. Downloading a bundle does not verify it offline.
  • Verdict parsing accepts uppercase API verdicts while keeping the existing lowercase enum values.
  • Writes are not automatically replayed unless their server route supports idempotency. Retain the same key and body when retrying one mint.
  • HTTP errors and malformed successful JSON responses raise SDK errors.
  • The main client is synchronous. Its separate registration helper is asynchronous; it does not make other resource methods awaitable.

Use a context manager or call close() when finished. Keep credentials out of source control and use the API reference for environment and authorization requirements.

Documentation · Issues

Retrieve a proof bundle

import json
import os
from dataclasses import asdict
from pathlib import Path
from truthlock import TruthlockClient

with TruthlockClient(api_key=os.environ["TRUTHLOCKS_API_KEY"]) as client:
    bundle = client.attestations.proof_bundle(os.environ["TRUTHLOCKS_ATTESTATION_ID"])
    with Path("proof-bundle.json").open("x", encoding="utf-8") as output:
        json.dump(asdict(bundle), output, indent=2)

The file is created without overwriting an existing bundle. Use independently trusted issuer and log keys with the offline CLI to validate downloaded evidence.

Configuration

Argument Purpose
api_key Workspace API key; never commit it to source control.
bearer_token Authorized user token, used instead of an API key.
base_url Explicit API origin; otherwise selected from key/environment.
environment sandbox or production.
timeout HTTP timeout in seconds; default 30.
max_retries Retry count for supported safe requests; default 3.

Handle errors

import os
from truthlock import TruthlockClient
from truthlock.errors import TruthlockError

try:
    with TruthlockClient(api_key=os.environ["TRUTHLOCKS_API_KEY"]) as client:
        record = client.attestations.get(os.environ["TRUTHLOCKS_ATTESTATION_ID"])
        print(record.attestation_id)
except TruthlockError as error:
    print(f"Truthlocks request failed: {error}")

For authentication errors, check the key and host. For mint failures, check that the issuer is available and the selected key can sign with the requested algorithm. A network timeout after a write can leave its outcome uncertain: reuse the same stored idempotency key and identical payload only on supported idempotent operations.

Migration from 0.3

Version 0.4 preserves current proof-bundle fields, handles uppercase wire verdicts, selects sandbox for test keys, and avoids replaying unsupported writes. The client remains synchronous; update examples that previously attempted to await its resource methods.

Metadata

Release files for truthlock 0.4.1

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

Source distribution (sdist)

Source distribution for truthlock 0.4.1
File Size Uploaded
truthlock-0.4.1.tar.gz 13.2 kB Details

Built distribution (wheel)

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

Total release size: 26.3 kB

Release files / truthlock-0.4.1.tar.gz

Download URL truthlock-0.4.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6a84d8aa376197c44fdfeca4a3e008a9b468fadddceb3354dae5bb34f77296a2
BLAKE2b-256 checksum
How to use checksums
937b16e909b43ba20070dc12cb7a033f51b1d8ca663479bee8c0a5720badb52d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / truthlock-0.4.1-py3-none-any.whl

Download URL truthlock-0.4.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
020945fa9555fa9b8e6b0c0d87590df6f187b02e88bf544ee06570f54d20ef1a
BLAKE2b-256 checksum
How to use checksums
06cb5034b24cf48979bb1128ed1ad906b1f1bbc8d1424ab810d8f3d036e5cec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.4.2

2 release files

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

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