Skip to main content

Official Python SDK for Xident age & identity verification

Project description

Xident Python SDK

Official Python SDK for Xident age and identity verification. Try it live at demo.xident.io.

PyPI version Python versions License: MIT

Installation

pip install xident

Requires Python 3.9+.

Quick Start

from xident import Xident

client = Xident(api_key="sk_live_...")

# Create an init token
result = client.verification.init(
    callback_url="https://example.com/callback",
    min_age=18,
)
print(result.verify_url)  # Redirect user here

# After callback, verify result server-side
session = client.verification.get_result("xtk_abc123")
if session.is_verified():
    print(f"Verified! Age: {session.age_bracket()}+")

Async Support

from xident import AsyncXident

client = AsyncXident(api_key="sk_live_...")

result = await client.verification.init(
    callback_url="https://example.com/callback",
    min_age=18,
)

session = await client.verification.get_result("xtk_abc123")

Configuration

client = Xident(
    api_key="sk_live_...",       # Required: secret API key
    base_url="https://...",      # Override API URL
    timeout=30,                  # Request timeout (seconds)
    max_retries=3,               # Retry on 5xx errors
    headers={"X-Custom": "..."},  # Extra headers
)

Verification

Create Init Token

result = client.verification.init(
    callback_url="https://example.com/callback",  # Required
    min_age=18,              # Age threshold (12, 15, 18, 21, 25)
    success_url="...",       # Override redirect on success
    failed_url="...",        # Override redirect on failure
    user_id="user_42",       # Your user identifier
    theme="dark",            # Widget theme (light, dark, auto)
    locale="de",             # Widget locale
    metadata="custom_data",  # Opaque metadata string
)

print(result.token)       # "xit_abc123"
print(result.verify_url)  # Full URL to redirect user to

Get Verification Result

session = client.verification.get_result("xtk_abc123")

session.is_verified()    # True if completed successfully
session.is_failed()      # True if verification failed
session.is_pending()     # True if still in progress
session.is_terminal()    # True if no more changes possible

session.age_bracket()    # 18 (verified age threshold)
session.method()         # "ml_fast", "ocr", etc.
session.country_code     # "US", "DE", etc.
session.status           # SessionStatus.COMPLETED

Webhooks

# Verify and parse a webhook event
event = client.webhooks.construct_event(
    payload=request_body,        # Raw JSON string or bytes
    signature=x_xident_signature,  # X-Xident-Signature header
    secret="whsec_...",          # Webhook secret from dashboard
    tolerance=300,               # Max age in seconds (default: 5 min)
)

print(event["type"])  # "session.completed"
print(event["data"])  # Event payload dict

# Or verify signature only
client.webhooks.verify_signature(payload, signature, secret)

Error Handling

from xident import (
    XidentError,          # Base for all errors
    AuthenticationError,  # 401/403
    ValidationError,      # 400
    NotFoundError,        # 404
    RateLimitError,       # 429 (has retry_after)
    ServerError,          # 5xx
    NetworkError,         # Connection failed
)

try:
    result = client.verification.init(callback_url="...")
except AuthenticationError as e:
    print(f"Bad API key: {e.error_code}")
except RateLimitError as e:
    print(f"Rate limited, retry in {e.retry_after}s")
except NetworkError as e:
    print(f"Connection failed: {e}")
except XidentError as e:
    print(f"SDK error: {e}")

Context Manager

# Auto-close HTTP client
with Xident(api_key="sk_live_...") as client:
    result = client.verification.init(callback_url="...")

# Async
async with AsyncXident(api_key="sk_live_...") as client:
    result = await client.verification.init(callback_url="...")

Framework Examples

See the examples/ directory for complete integrations:

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=xident

# Type checking
mypy src/xident

# Linting
ruff check src/ tests/

License

MIT

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

xident-1.0.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

xident-1.0.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file xident-1.0.0.tar.gz.

File metadata

  • Download URL: xident-1.0.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for xident-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0efe73117cdbf9790e9cae91e50ada45837831cdc8fd1a2a22d4d71df45e31df
MD5 4a820ce5f45bc3ba0bcd5f860a11baed
BLAKE2b-256 80549441e248c51f69eabe81b080cbd92aa2afdf4432f02ce06d8d7a102b740c

See more details on using hashes here.

File details

Details for the file xident-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: xident-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for xident-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 617413b274e6e42cf9caf9bd5716bd46ea7e9a6498ee92b80c4d890b956832db
MD5 e2f26eb66ea0ba7fa12cdbf5287f5c37
BLAKE2b-256 4effa4bf2a905f446942954bc91a4fc40b0d89c717b3242a9e1e0a1a41f67323

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