Python SDK
The official Python SDK for the Uchara Chat Platform.
Installation
Section titled “Installation”pip install uchara-sdkRequirements
Section titled “Requirements”- Python 3.8+
Visitor SDK
Section titled “Visitor SDK”from uchara import VisitorSDK
visitor = VisitorSDK( api_url="https://api.uchara.com", widget_token="wgt_your_token", contact_metadata={"user_id": "123"},)
# Initialize sessionsession = visitor.init()print(f"Contact ID: {session['contact_id']}")
# Start conversationconv = visitor.start_conversation(message="Hello!")
# Get messagesmessages = visitor.get_messages(conv["id"], limit=50)
# Send messagemessage = visitor.send_message(conv["id"], content="I need help")
# Real-time eventsdef on_event(event): if event["type"] == "message.new": print(f"New message: {event['payload']['content']}")
visitor.connect(on_event=on_event)Agent SDK
Section titled “Agent SDK”from uchara import AgentSDK, ConversationStatus, Priority
agent = AgentSDK(api_url="https://api.uchara.com")
# Loginagent.login(email="agent@company.com", password="...")
# List conversationsconvs = agent.list_conversations( status=ConversationStatus.OPEN, limit=20,)
# Send replyagent.send_message(convs[0]["id"], content="Hi! How can I help?")
# Assign conversationagent.assign_conversation(conv_id, assigned_to=agent_id)
# Update workflowagent.update_workflow( conv_id, status=ConversationStatus.OPEN, priority=Priority.HIGH,)
# Resolveagent.resolve_conversation(conv_id)
# Real-time eventsdef on_event(event): if event["type"] == "conversation.new": print("New conversation!")
agent.connect(on_event=on_event)Server SDK
Section titled “Server SDK”from uchara import ServerSDKimport os
server = ServerSDK( api_url="https://api.uchara.com", api_key=os.getenv("UCHARA_API_KEY"),)
# Send notificationserver.send_message( conversation_id="...", content="Your order has shipped!", sender_type="bot",)
# Upsert contactcontact = server.upsert_contact( external_id="user_123", name="John Doe", email="john@example.com",)
# List conversationsconversations = server.list_conversations( status=ConversationStatus.OPEN,)Error Handling
Section titled “Error Handling”from uchara import APIError
try: agent.send_message(conversation_id, content="Hello")except APIError as e: print(f"HTTP {e.status}: {e.message}")
if e.status == 401: # Token expired agent.login(email="...", password="...") elif e.status == 429: # Rate limited passType Hints
Section titled “Type Hints”The SDK includes full type hints:
from uchara import ( Message, Conversation, Contact, Member, Channel, ConversationStatus, Priority, SenderType, ContentType,)Async Support
Section titled “Async Support”For async applications, run blocking calls in a thread pool:
import asynciofrom uchara import ServerSDK
server = ServerSDK(api_url="...", api_key="...")
async def send_async(conv_id: str, content: str): loop = asyncio.get_event_loop() return await loop.run_in_executor( None, lambda: server.send_message(conv_id, content=content) )