DOCS · PYTHON

Python Code Examples

UPDATED 22 NOVEMBER 2025
from aiva_sdk import AivaClient

client = AivaClient(
    api_key=os.getenv('AIVA_API_KEY'),
    merchant_id=os.getenv('AIVA_MERCHANT_ID')
)

# Get at-risk customers

at_risk = client.customers.list(segment='At Risk')
print(f"At-risk customers: {at_risk['total']}")

# Calculate total LTV at risk

total_ltv = sum(c['totalSpent'] for c in at_risk['customers'])
print(f"Total LTV at risk: ${total_ltv:,.2f}")

# Send win-back message

for customer in at_risk['customers'][:10]:  # First 10
    client.aiva.send_message(
        customer_email=customer['email'],
        customer_name=f"{customer['firstName']} {customer['lastName']}",
        message="We miss you! Here's 20% off your next order.",
        channel='email'
    )

Install:

pip install aiva-sdk
`"
Building something with the AIVA API or MCP server? We read every developer message.
Talk to us