Skip to main content

Official Python SDK for the Credlyr API

Project description

Credlyr Python SDK

Official Python SDK for the Credlyr API - verifiable credentials infrastructure for identity verification.

Installation

pip install credlyr

Quick Start

from credlyr import CredlyrClient

client = CredlyrClient(api_key="sk_live_xxx")

# Create a verification session
verification = client.verifications.create(
    policy_id="pol_abc123",
    return_url="https://yourapp.com/callback",
)

print("Verification URL:", verification["hosted_url"])

Configuration

client = CredlyrClient(
    api_key="your-api-key",           # Required
    base_url="https://api.credlyr.com",  # Optional, defaults to production
    timeout=30.0,                      # Optional, request timeout in seconds
    max_retries=2,                     # Optional, retry failed requests
)

Resources

Verifications

# Create a verification session
verification = client.verifications.create(
    policy_id="pol_abc123",
    return_url="https://yourapp.com/callback",
    metadata={"user_id": "user_123"},
)

# Get verification details
details = client.verifications.retrieve("ver_xyz789")

# List all verifications
result = client.verifications.list(status="completed")

Issuance

# Create an issuance session
session = client.issuance.create_session(
    credential_type="EmploymentCredential",
    claims={
        "employer": "Acme Corp",
        "position": "Software Engineer",
        "start_date": "2024-01-15",
    },
)

Policies

# Create a policy
policy = client.policies.create(
    name="Age Verification",
    rules={"required_claims": ["birthDate"]},
)

# List policies
result = client.policies.list()

Team Management

# List team members
result = client.team.list()

# Invite a new member
member = client.team.invite(
    email="developer@company.com",
    role="developer",
)

Billing

# Get current usage
usage = client.billing.get_usage()

# Open billing portal
portal = client.billing.create_portal_session()

Webhook Verification

from credlyr import verify_webhook_signature

# In your webhook handler
def handle_webhook(request):
    payload = request.body.decode()
    signature = request.headers["X-Credlyr-Signature"]

    try:
        event = verify_webhook_signature(
            payload,
            signature,
            "your_webhook_secret",
        )

        if event["type"] == "verification.completed":
            # Handle completed verification
            pass

    except ValueError as e:
        return {"error": "Invalid signature"}, 400

Error Handling

from credlyr import (
    CredlyrError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    NotFoundError,
)

try:
    verification = client.verifications.create(policy_id="invalid")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except ValidationError as e:
    print(f"Validation error: {e.message}")
except NotFoundError:
    print("Resource not found")
except CredlyrError as e:
    print(f"API error: {e.code} - {e.message}")

Context Manager

with CredlyrClient(api_key="sk_live_xxx") as client:
    verification = client.verifications.create(...)
# Client is automatically closed

Requirements

  • Python 3.8+
  • httpx

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

credlyr-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

credlyr-1.0.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for credlyr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dbf4f1a43fb941e5318b5ebbb9b248df5773156a8f15269ed2e48c04dd2ac751
MD5 125e58591780460ba3dd56978bad430d
BLAKE2b-256 6631b4343e5dddf8d11f7e7f5285c6b91799ae4e4647728243342cf44ec2a4d7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for credlyr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a0ac6492281fd3ed083263d5440ea522c317188bbe352475120850fa1f04398
MD5 d9f62470ce02eb0f8085f3b7a135c2b5
BLAKE2b-256 004ecff994c6faa927502004f8f7bdf7bfbef3c4b232dd8940b14cf2ea6a5a02

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