OdyDocs

Python SDK

Use the ody Python package: setup, pagination, errors, idempotency and webhook verification. Standard library only.

#Setup

Shell
pip install ody-sdk

Published on PyPI as ody-sdk (MIT, standard library only, Python 3.9+); the import name is ody. Releases are built from the public source tree by GitHub Actions with PyPI attestations.

Python
import os
from ody import Ody

client = Ody(os.environ["ODY_API_KEY"])
# Options: Ody(api_key, base_url="https://api.ody.co", timeout=30.0)

Python 3.9+, no third-party dependencies (it uses urllib). The client is synchronous. In async code, run calls in a thread (await asyncio.to_thread(client.messages.send, ...)).

#Usage

Python
# Contacts
contact = client.contacts.create(first_name="Ada", phone="+15125550123", tags=["vip"])
for c in client.contacts.list_all(q="ada"):
    print(c["id"])

# Conversations
page = client.conversations.list(status="open", limit=25)
thread = client.conversations.get(page["conversations"][0]["id"])
client.conversations.set_status(thread["conversation"]["id"], "done")

# Messages
sent = client.messages.send(to="+15125550123", body="Hi!", idempotency_key="welcome-ada")
hits = client.messages.search("refund", limit=10)

# Calls
calls = client.calls.list(limit=20)
client.calls.place(to="+15125550123")

# Numbers, 10DLC, agent
available = client.numbers.search_available(starts_with="512")
client.numbers.buy(phone_number=available[0]["phone_number"], idempotency_key="main-line")
status = client.messaging.status()
client.agent.update(greeting="Thanks for calling!")
client.agent.publish()

# Several AI agents (Growth 3 · Enterprise 10): a second receptionist on a menu key of the only line
sales = client.agents.create(name="Sales", voice="luna")
client.agents.attach(sales["id"], "+15125550188", "menu")  # "Press 1 for Astra, press 2 for Sales"
client.agents.publish(sales["id"])
res = client.agents.list()  # res["agents"] each with reach, res["limit"]

# Business AI Texting: the agent answers the line's texts from the knowledge base
client.numbers.set_texting_agent("+15125550188", sales["id"])
client.agents.set_texting(sales["id"], True)                 # no publish needed
t = client.agents.texting(sales["id"])                       # {"live", "links", "textingReady", "runs", ...}
client.conversations.set_ai_texting(conversation_id, True)   # a human takes this thread over

# Link tracking: every URL your team, your AI or this SDK texts becomes link.ody.co/<code>
client.link_tracking.update(enabled=True)                    # clicks → thread, Analytics, link.clicked webhook
settings = client.link_tracking.get()["settings"]

# Hosted files: every photo, video or PDF goes out as a branded link.ody.co/m/... page (on by default, no per-send flag)
client.hosted_media.update(display_name="Glow Salon", accent="#1c6bff", website_url="https://glowsalon.com")
sent = client.messages.send("Your new colour", conversation_id=conversation_id, media_urls=[p1, p2, p3])
print(sent["message"].get("hostedMedia", [{}])[0].get("title"))   # "3 photos"
runs = client.conversations.ai_texting_runs(conversation_id) # why it did / didn't reply

# Knowledge base (shared by every AI agent + suggested replies)
tree = client.knowledge.get()
folder = client.knowledge.create_folder("Policies")
client.knowledge.create_article(
    title="Cancellation policy",
    content="Free up to 24 hours before; $25 after that.",
    folder_id=folder["id"],
    audience="selected",
    consumers=[c["key"] for c in tree["consumers"] if c["kind"] == "agent"],
)
hits = client.knowledge.search("cancellation fee", consumer="texting")

Responses are plain dicts with the API's camelCase keys (conversationId, nextCursor). Python argument names are snake_case (first_name, idempotency_key, from_ for the reserved word from).

#Errors

Python
import time
from ody import OdyError

try:
    client.messages.send(to="+15125550123", body="Hi")
except OdyError as err:
    if err.code == "resource_exhausted":
        time.sleep(err.retry_after or 1)
    elif err.code == "failed_precondition":
        print("Not allowed yet:", err.message)  # e.g. 10DLC pending
    print(err.status, err.code, err.request_id)

The codes are listed in Errors.

#Webhook verification

Python
from ody import verify_webhook_signature

ok = verify_webhook_signature(secret, request.headers, request.get_data())  # raw bytes

Header lookup is case-insensitive, the comparison is constant-time, and timestamps more than 5 minutes off are rejected. Flask and standardwebhooks examples are in Verifying signatures.

#Webhooks

parse_webhook_event verifies and parses in one step and returns the envelope dict (id, apiVersion, createdAt, type, data). It raises WebhookVerificationError on a bad or stale signature:

Python
from flask import Flask, request
from ody import parse_webhook_event, WebhookVerificationError, is_known_webhook_event_type

@app.post("/ody-webhook")
def ody_webhook():
    try:
        event = parse_webhook_event(os.environ["ODY_WEBHOOK_SECRET"], request.headers, request.get_data())
    except WebhookVerificationError:
        return "", 401

    if event["type"] == "call.ringing":
        screen_pop(event["data"]["from"], event["data"]["callerName"])
    elif event["type"] == "call.answered" and event["data"]["answeredBy"] == "member":
        assign(event["data"]["memberUid"])
    elif event["type"] in ("contact.updated", "contact.deleted"):
        sync_contact(event["data"]["contactId"])
    elif not is_known_webhook_event_type(event["type"]):
        log.info("new Ody event type %s", event["type"])   # a "*" subscription may see types newer than this SDK
    return "", 200

WEBHOOK_EVENT_TYPES is the catalog as a tuple. Each event's data fields are described in Event types.

Last updated Sat Nov 07 2026 00:00:00 GMT+0000 (Coordinated Universal Time)Something wrong on this page? Tell us