Installation
Copy
pip install gtateth-sdk
Copy
git clone https://github.com/g-tateth/sdk-python.git
cd sdk-python
pip install -e .
Quick Start
Copy
from gtateth import GtatethClient
client = GtatethClient(
api_key='sk_live_your_api_key_here',
base_url='https://api.g-tateth.com' # Optional, defaults to production
)
# List conversations
conversations = client.conversations.list()
# Get a conversation
conversation = client.conversations.get('conversation_id')
# List customers
customers = client.customers.list()
# Create a customer
new_customer = client.customers.create({
'profile': {
'firstName': 'John',
'lastName': 'Doe',
'email': 'john@example.com'
}
})
Configuration
Options
Copy
client = GtatethClient(
api_key='sk_live_your_api_key',
base_url='https://api.g-tateth.com', # Optional
timeout=30, # Optional, default: 30 seconds
retries=3 # Optional, default: 3
)
Environment Variables
You can also configure the client using environment variables:Copy
export G_TATETH_API_KEY=sk_live_your_api_key
export G_TATETH_BASE_URL=https://api.g-tateth.com
Copy
client = GtatethClient() # Uses environment variables
API Methods
Conversations
Copy
# List conversations
conversations = client.conversations.list(
status='open',
page=1,
limit=50
)
# Get conversation
conversation = client.conversations.get('conversation_id')
# Create conversation
new_conversation = client.conversations.create({
'subject': 'Customer inquiry',
'customerId': 'customer_id',
'channel': 'email'
})
# Update conversation
client.conversations.update('conversation_id', {
'status': 'closed'
})
# Delete conversation
client.conversations.delete('conversation_id')
Customers
Copy
# List customers
customers = client.customers.list(
search='john',
page=1,
limit=50
)
# Get customer
customer = client.customers.get('customer_id')
# Create customer
new_customer = client.customers.create({
'profile': {
'firstName': 'John',
'lastName': 'Doe',
'email': 'john@example.com'
}
})
# Update customer
client.customers.update('customer_id', {
'profile': {
'company': 'Acme Corp'
}
})
# Delete customer
client.customers.delete('customer_id')
Webhooks
Copy
# List webhooks
webhooks = client.webhooks.list()
# Create webhook
webhook = client.webhooks.create({
'name': 'My Webhook',
'url': 'https://myapp.com/webhooks',
'events': ['conversation.created', 'customer.updated']
})
# Get webhook
webhook = client.webhooks.get('webhook_id')
# Update webhook
client.webhooks.update('webhook_id', {
'isActive': False
})
# Delete webhook
client.webhooks.delete('webhook_id')
Analytics
Copy
# Get usage statistics
usage = client.analytics.get_usage(
start_date='2024-01-01',
end_date='2024-01-31'
)
# Get performance metrics
metrics = client.analytics.get_metrics(days=7)
Error Handling
The SDK raises custom exception types:Copy
from gtateth.exceptions import (
GtatethError,
RateLimitError,
AuthenticationError
)
try:
conversations = client.conversations.list()
except RateLimitError as e:
print(f'Rate limit exceeded. Retry after: {e.retry_after}')
except AuthenticationError as e:
print(f'Authentication failed: {e.message}')
except GtatethError as e:
print(f'API error: {e.code} - {e.message}')
Retry Logic
The SDK automatically retries failed requests with exponential backoff:Copy
client = GtatethClient(
api_key='sk_live_your_api_key',
retries=3 # Number of retry attempts
)
Examples
Pagination
Copy
def get_all_conversations():
page = 1
all_conversations = []
while True:
response = client.conversations.list(page=page, limit=50)
all_conversations.extend(response['data'])
if page >= response['pagination']['totalPages']:
break
page += 1
return all_conversations
Error Handling
Copy
def safe_get_conversation(conversation_id):
try:
return client.conversations.get(conversation_id)
except GtatethError as e:
print(f'API Error: {e.code} - {e.message}')
raise