Python SDK

Coming Soon Python 3.9+ Async support

Coming Soon — The Python SDK is under development. In the meantime, you can use the REST API directly with requests or httpx.

The Python SDK (xident) provides sync and async clients for server-side token verification. Works with Flask, Django, FastAPI, and any Python 3.9+ project.

Installation

pip install xident

Quick Start

from xident import XidentClient

client = XidentClient(secret_key="sk_live_xxx")

# Verify a token from the callback
result = client.verification_tokens.verify("tok_xxx")

if result.verified:
    print(f"Age bracket: {result.age_bracket}")  # 18
    print(f"Session: {result.session_id}")

Async Usage

from xident import AsyncXidentClient

client = AsyncXidentClient(secret_key="sk_live_xxx")

# Async token verification
result = await client.verification_tokens.verify("tok_xxx")

Framework Examples

Flask

from flask import Flask, request, redirect, session
from xident import XidentClient

app = Flask(__name__)
xident = XidentClient(secret_key="sk_live_xxx")

@app.route('/verified')
def handle_verification():
    token = request.args.get('token')
    status = request.args.get('status')

    if status != 'success' or not token:
        return redirect('/verification-cancelled')

    try:
        result = xident.verification_tokens.verify(token)

        if result.verified and result.age_bracket >= 18:
            session['age_verified'] = True
            session['age_bracket'] = result.age_bracket
            return redirect('/content')

        return redirect('/too-young')
    except xident.XidentError as e:
        print(f"Verification failed: {e.code} - {e.message}")
        return redirect('/verification-error')

Django

# views.py
from django.shortcuts import redirect
from django.conf import settings
from xident import XidentClient

xident_client = XidentClient(secret_key=settings.XIDENT_SECRET_KEY)

def verification_callback(request):
    token = request.GET.get('token')
    status = request.GET.get('status')

    if status != 'success' or not token:
        return redirect('/verification-cancelled')

    result = xident_client.verification_tokens.verify(token)

    if result.verified and result.age_bracket >= 18:
        request.session['age_verified'] = True
        return redirect('/content')

    return redirect('/too-young')

FastAPI

from fastapi import FastAPI, Query
from fastapi.responses import RedirectResponse
from xident import AsyncXidentClient

app = FastAPI()
xident = AsyncXidentClient(secret_key="sk_live_xxx")

@app.get("/verified")
async def verification_callback(
    token: str = Query(...),
    status: str = Query(...)
):
    if status != "success":
        return RedirectResponse("/verification-cancelled")

    result = await xident.verification_tokens.verify(token)

    if result.verified and result.age_bracket >= 18:
        return RedirectResponse("/content")

    return RedirectResponse("/too-young")

Planned API Surface

client = XidentClient(secret_key="sk_live_xxx")

# Token verification
result = client.verification_tokens.verify(token)
result = client.verification_tokens.issue(account_id=..., age_bracket=18, tenant_id=...)
client.verification_tokens.revoke(token)

# Usage & billing
usage = client.usage.get(from_date="2026-01-01", to_date="2026-01-31")

# Webhook signature verification
is_valid = client.webhooks.verify_signature(payload, signature, secret)

Error Handling

from xident import XidentClient, XidentError

try:
    result = client.verification_tokens.verify(token)
except XidentError as e:
    print(e.code)     # 'TOKEN_EXPIRED', 'TOKEN_USED', 'INVALID_TOKEN'
    print(e.message)  # Human-readable message
    print(e.status)   # HTTP status code

Using the REST API Directly

import requests
import os

response = requests.post(
    'https://api.xident.io/api/v1/verification-tokens/verify',
    headers={
        'X-API-Key': os.environ['XIDENT_SECRET_KEY'],
        'Content-Type': 'application/json'
    },
    json={'token': token}
)

data = response.json()
# data['success'], data['data']['verified'], data['data']['age_bracket']

Related