- Installierbares Package mit pyproject.toml - Client-Klasse mit Sync, Async (mit Polling), Webhook, Verify, Download - Typisierte Exception-Hierarchie - Webhook-Signatur-Verifikation (HMAC-SHA-256) - Pytest-Suite + Quickstart und Webhook-Receiver-Beispiel
56 lines
3 KiB
Python
56 lines
3 KiB
Python
"""hightrusted CAPTURE — Quickstart.
|
|
|
|
Voraussetzung:
|
|
pip install hightrusted-capture
|
|
|
|
API-Key holen:
|
|
https://capture.hightrusted.net/dashboard/api-keys
|
|
"""
|
|
|
|
import os
|
|
|
|
from hightrusted_capture import Client, RateLimitedError
|
|
|
|
API_KEY = os.environ.get("HIGHTRUSTED_API_KEY", "ht_live_REPLACE_ME")
|
|
|
|
client = Client(api_key=API_KEY)
|
|
|
|
# ───────────────────────────────────────────────────────────────────
|
|
# 1. Synchrone Capture
|
|
# ───────────────────────────────────────────────────────────────────
|
|
print("→ Erstelle Capture (synchron)...")
|
|
capture = client.capture(
|
|
"https://example.com",
|
|
reference="quickstart-demo",
|
|
viewport={"width": 1920, "height": 1080},
|
|
)
|
|
print(f" ID: {capture['id']}")
|
|
print(f" Status: {capture['status']}")
|
|
print(f" Verify-URL: {capture['verify_url']}")
|
|
print(f" Zeitstempel: {capture['timestamp']['issued_at']}")
|
|
|
|
# ───────────────────────────────────────────────────────────────────
|
|
# 2. Verifikation (kostenlos)
|
|
# ───────────────────────────────────────────────────────────────────
|
|
print("\n→ Verifiziere die Capture...")
|
|
result = client.verify(source=capture["id"])
|
|
print(f" Gültig: {result['valid']}")
|
|
print(f" Audit-Log: {result['audit_log']['chain_valid']}")
|
|
|
|
# ───────────────────────────────────────────────────────────────────
|
|
# 3. PDF herunterladen
|
|
# ───────────────────────────────────────────────────────────────────
|
|
print("\n→ Lade PDF herunter...")
|
|
pdf_path = client.download_pdf(capture["id"], f"./capture_{capture['id'][:8]}.pdf")
|
|
print(f" Gespeichert: {pdf_path}")
|
|
|
|
# ───────────────────────────────────────────────────────────────────
|
|
# 4. Quota prüfen
|
|
# ───────────────────────────────────────────────────────────────────
|
|
print("\n→ Quota-Status...")
|
|
try:
|
|
usage = client.usage()
|
|
print(f" Plan: {usage['plan']}")
|
|
print(f" Verbraucht: {usage['used_calls']}/{usage['included_calls']}")
|
|
except RateLimitedError as e:
|
|
print(f" Rate-limited, retry in {e.retry_after_seconds}s")
|