Back to Tutorials
intermediate
SDK
Complete Python SDK Guide
Comprehensive guide to integrating CredLyr with Python.
15 min read
6 sections
Prerequisites
- Python 3.8+ installed
- pip package manager
- CredLyr API key
In this tutorial
Overview
The CredLyr Python SDK provides both synchronous and asynchronous interfaces for integrating credential verification. It includes full type hints and supports modern Python patterns.
Installation
Install the SDK using pip.
pip install credlyr
# For async support
pip install credlyr[async]Initialize the Client
Create a CredLyr client with your API key.
from credlyr import CredLyr
client = CredLyr(
api_key=os.environ["CREDLYR_API_KEY"],
environment="sandbox" # or "production"
)Create a Verification (Sync)
Create verifications using the synchronous interface.
verification = client.verifications.create(
policy_id="pol_your_policy_id",
return_url="https://yourapp.com/callback",
metadata={"user_id": "user_123"}
)
print(f"Redirect user to: {verification.hosted_url}")Async Support
Use the async client for non-blocking operations.
from credlyr import AsyncCredLyr
import asyncio
async def create_verification():
async with AsyncCredLyr(api_key=os.environ["CREDLYR_API_KEY"]) as client:
verification = await client.verifications.create(
policy_id="pol_your_policy_id",
return_url="https://yourapp.com/callback"
)
return verification
verification = asyncio.run(create_verification())Error Handling
Handle API errors with typed exceptions.
from credlyr.exceptions import CredLyrError, RateLimitError
try:
verification = client.verifications.create(...)
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after} seconds")
except CredLyrError as e:
print(f"API error: {e.code} - {e.message}")