Prelude Python SDK

0.11.0 · active · verified Sat Apr 11

The `prelude-python-sdk` is the official Python library for interacting with the Prelude API. It provides convenient access to Prelude's REST API from any Python 3.9+ application, offering type definitions for all request parameters and response fields. The library supports both synchronous and asynchronous clients, powered by httpx, and is generated with Stainless. Currently at version 0.11.0, it maintains a rapid release cadence with updates typically every 1-3 months.

Warnings

Install

Imports

Quickstart

This quickstart initializes the synchronous Prelude client using an API token from environment variables and demonstrates how to initiate a phone number verification. For asynchronous usage, import `AsyncPrelude` and use `await` with API calls.

import os
from prelude_python_sdk import Prelude

# It's recommended to set API_TOKEN as an environment variable (e.g., export API_TOKEN="your_token")
api_token = os.environ.get("API_TOKEN", "YOUR_DEFAULT_API_TOKEN")

if api_token == "YOUR_DEFAULT_API_TOKEN":
    print("Warning: Please set the API_TOKEN environment variable or replace 'YOUR_DEFAULT_API_TOKEN' with your actual Prelude API token.")

try:
    client = Prelude(api_token=api_token)

    # Example: Create a phone number verification
    verification = client.verification.create(
        target={
            "type": "phone_number",
            "value": "+15551234567", # Replace with a valid test phone number
        },
    )
    print(f"Successfully initiated verification with ID: {verification.id}")

    # Example: Check a verification code (uncomment and replace with actual code/target)
    # check_response = client.verification.check(
    #     target={
    #         "type": "phone_number",
    #         "value": "+15551234567",
    #     },
    #     code="123456", # Replace with the received verification code
    # )
    # print(f"Verification check successful for ID: {check_response.id}, status: {check_response.status}")

except Exception as e:
    print(f"An error occurred during Prelude API interaction: {e}")

view raw JSON →