Skip to main content

Official Python SDK for the Pollax AI Voice Platform

Project description

Pollax Python SDK

Official Python client library for the Pollax AI Voice Platform.

PyPI version Python Support License

Installation

pip install pollax

Quick Start

from pollax import Pollax

# Initialize client
client = Pollax(api_key="sk_live_your_api_key_here")

# Create an AI agent
agent = client.agents.create(
    name="Customer Support Agent",
    system_prompt="You are a helpful customer support agent for Acme Corp.",
    voice_id="alloy",
    model="gpt-4",
)

# Make a call
call = client.calls.create(
    agent_id=agent.id,
    to_number="+1234567890",
    from_number="+0987654321",
)

print(f"Call initiated: {call.call_sid}")

Features

  • Full type hints with Pydantic models
  • Async/await support
  • Automatic retry logic with exponential backoff
  • Comprehensive error handling
  • Context manager support
  • Python 3.8+ support

Usage

Client Initialization

from pollax import Pollax

# Basic initialization
client = Pollax(api_key="sk_live_...")

# With custom configuration
client = Pollax(
    api_key="sk_live_...",
    base_url="https://api.pollax.ai",
    timeout=30.0,
    max_retries=3,
    tenant_id="org_123",
)

# Using context manager (recommended)
with Pollax(api_key="sk_live_...") as client:
    agents = client.agents.list()

Agents

# Create an agent
agent = client.agents.create(
    name="Support Agent",
    system_prompt="You are a helpful assistant",
    voice_provider="elevenlabs",
    voice_id="voice_abc123",
    model="gpt-4",
    temperature=0.7,
)

# List agents
agents = client.agents.list(is_active=True)

# Get a specific agent
agent = client.agents.retrieve("agent_123")

# Update an agent
agent = client.agents.update(
    "agent_123",
    name="New Name",
    is_active=False,
)

# Delete an agent
client.agents.delete("agent_123")

# Test an agent
response = client.agents.test("agent_123", "Hello, how can you help?")
print(response)

Calls

# Create a call
call = client.calls.create(
    agent_id="agent_123",
    to_number="+1234567890",
    from_number="+0987654321",
    metadata={"customer_id": "cust_456"},
)

# List calls
calls = client.calls.list(
    agent_id="agent_123",
    status="completed",
)

# Get call details
call = client.calls.retrieve("CA123456")

# End a call
client.calls.end("CA123456")

# Transfer a call
client.calls.transfer("CA123456", to_number="+1111111111")

# Get call transcript
transcript = client.calls.get_transcript("CA123456")
print(transcript)

# Get call recording
recording = client.calls.get_recording("CA123456")
print(recording["url"])

Campaigns

# Create a campaign
campaign = client.campaigns.create(
    name="Q1 Outreach Campaign",
    agent_id="agent_123",
    contacts=[
        {"name": "John Doe", "phone": "+1234567890"},
        {"name": "Jane Smith", "phone": "+0987654321"},
    ],
)

# Start campaign
client.campaigns.start("campaign_123")

# Pause campaign
client.campaigns.pause("campaign_123")

# Get campaign stats
stats = client.campaigns.get_stats("campaign_123")
print(f"Success rate: {stats['success_rate']}")

Knowledge Base

# Upload a document
with open("manual.pdf", "rb") as f:
    doc = client.knowledge.upload(
        name="Product Manual",
        file=f,
        doc_type="pdf",
    )

# Upload from text
doc = client.knowledge.upload(
    name="FAQ",
    content="Q: How do I reset my password? A: Click forgot password...",
    doc_type="txt",
)

# Search knowledge base
results = client.knowledge.search(
    query="How do I reset my password?",
    limit=5,
)

for result in results["results"]:
    print(f"Score: {result['score']}")
    print(f"Content: {result['content']}")

# Delete a document
client.knowledge.delete("doc_123")

Analytics

# Get dashboard statistics
stats = client.analytics.get_stats()
print(f"Total calls: {stats.total_calls}")
print(f"Active agents: {stats.active_agents}")
print(f"Success rate: {stats.success_rate}")

# Get call volume over time
volume = client.analytics.get_call_volume(period="7d")

# Get agent performance
performance = client.analytics.get_agent_performance("agent_123")

# Export data
data = client.analytics.export(
    start_date="2024-01-01",
    end_date="2024-01-31",
    format="csv",
)

Integrations

# Create an integration
integration = client.integrations.create(
    name="Salesforce CRM",
    integration_type="salesforce",
    config={
        "client_id": "...",
        "client_secret": "...",
    },
)

# List integrations
integrations = client.integrations.list()

# Delete integration
client.integrations.delete("int_123")

Phone Numbers

# Search available numbers
numbers = client.phone_numbers.search(
    country_code="US",
    area_code="415",
)

# Purchase a number
number = client.phone_numbers.purchase("+14155551234")

# Release a number
client.phone_numbers.release("num_123")

Voice Cloning

# Create a custom voice
with open("sample1.wav", "rb") as f1, open("sample2.wav", "rb") as f2:
    voice = client.voice_cloning.create(
        name="Custom Voice",
        description="My custom voice profile",
        audio_files=[f1, f2],
        provider="elevenlabs",
    )

# List voices
voices = client.voice_cloning.list()

# Delete voice
client.voice_cloning.delete("voice_123")

Error Handling

from pollax import (
    Pollax,
    PollaxError,
    AuthenticationError,
    NotFoundError,
    RateLimitError,
)

client = Pollax(api_key="sk_live_...")

try:
    agent = client.agents.retrieve("agent_123")
except AuthenticationError:
    print("Invalid API key")
except NotFoundError:
    print("Agent not found")
except RateLimitError:
    print("Rate limit exceeded, try again later")
except PollaxError as e:
    print(f"API error: {e.message}")
    print(f"Status code: {e.status_code}")

Type Safety

The SDK uses Pydantic for data validation and type safety:

from pollax import Pollax
from pollax.models import Agent, Call

client = Pollax(api_key="sk_live_...")

# Full type hints
agent: Agent = client.agents.create(
    name="Support Agent",
    system_prompt="You are helpful",
    model="gpt-4",
)

# IDE autocomplete works perfectly
print(agent.id)
print(agent.name)
print(agent.created_at)

Development

# Clone repository
git clone https://github.com/pollax/pollax-python
cd pollax-python

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black pollax tests

# Type checking
mypy pollax

License

MIT

Support

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

pollax-1.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

pollax-1.2.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file pollax-1.2.0.tar.gz.

File metadata

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

File hashes

Hashes for pollax-1.2.0.tar.gz
Algorithm Hash digest
SHA256 59ac30c95e1c6789bf9980e305ec3c93bfd7fbb3198a65a90514712f52c6cff9
MD5 02cbfec65802b503d7c83b7880dbaca3
BLAKE2b-256 d6f875e74890af5479edcc268fe1cf9dce3fc518e7ffc6a27b5d70b18eca03c4

See more details on using hashes here.

File details

Details for the file pollax-1.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pollax-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7178e38105c0b7a4400e721572a80ba4e037c465789597ec4d920996a2b1ae9
MD5 b629d81012bb51c92978f343e73ca632
BLAKE2b-256 751661dab44eca59ca1cfc1052185b06c9893652fff3596648e820b491d68711

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