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.
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:
- basic.py -- Pure Python
- flask_app.py -- Flask
- django_view.py -- Django
- fastapi_app.py -- FastAPI (async)
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
Release history Release notifications | RSS feed
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.1.tar.gz
(23.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
xident-1.0.1-py3-none-any.whl
(16.8 kB
view details)
File details
Details for the file xident-1.0.1.tar.gz.
File metadata
- Download URL: xident-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62aed2be7b0d0e269b84caf0d789c4f0f8a772704489f098ae6b5bab514ed943
|
|
| MD5 |
9f5b44a4150de8b1d5766041a6ec5b2d
|
|
| BLAKE2b-256 |
56b8264cf6dfa9588ccdacf0b245b39794c4d145302afac6c876070ed1f54b45
|
File details
Details for the file xident-1.0.1-py3-none-any.whl.
File metadata
- Download URL: xident-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c50f127de5fecfcb2790ccf9b7c932919ccfc98d1ea60aea43fb7b379b90ad
|
|
| MD5 |
49699fe64e98bd77661fcf282a3f3dbb
|
|
| BLAKE2b-256 |
46f7a3fdd9109e06c17b5e802f301ec55f70b1b1350713f5e53a74b4558f509e
|