REST Client¶
Sync vs Async¶
from jambonz import JambonzClient, AsyncJambonzClient
# Sync
with JambonzClient() as client:
carriers = client.carriers.list()
# Async
async with AsyncJambonzClient() as client:
carriers = await client.carriers.list()
Resources¶
All resources support CRUD operations: list(), get(sid), create(**data), update(sid, **data), delete(sid).
Carriers¶
# List
carriers = await client.carriers.list()
# Get
carrier = await client.carriers.get("carrier-sid")
# Create
carrier = await client.carriers.create(
name="my-carrier",
trunk_type="static_ip",
)
# Update
carrier = await client.carriers.update("carrier-sid", name="new-name")
# Delete
await client.carriers.delete("carrier-sid")
Phone Numbers¶
numbers = await client.phone_numbers.list()
number = await client.phone_numbers.create(
number="34931228497",
voip_carrier_sid="carrier-sid",
application_sid="app-sid",
)
Applications¶
apps = await client.applications.list()
app = await client.applications.create(
name="my-app",
call_hook="https://example.com/call",
call_status_hook="https://example.com/status",
)
Speech Services¶
SIP Gateways¶
# List gateways for a carrier
gateways = await client.gateways.list(
voip_carrier_sid="carrier-sid"
)
Recent Calls¶
# Paginated — days, page, count are required
calls = await client.calls.list(days=7, page=1, count=25)
for call in calls:
print(f"{call.direction}: {call.from_} → {call.to} ({call.duration}s)")
Error Handling¶
from jambonz.exceptions import (
JambonzAuthError,
JambonzNotFoundError,
JambonzRateLimitError,
JambonzValidationError,
JambonzAPIError,
)
try:
carrier = await client.carriers.get("bad-sid")
except JambonzNotFoundError:
print("Carrier not found")
except JambonzAuthError:
print("Invalid API key")
except JambonzRateLimitError:
print("Too many requests — SDK retries automatically")
except JambonzAPIError as e:
print(f"API error {e.status_code}: {e}")
Info
The SDK automatically retries on 429 (rate limit) and 5xx (server error) with exponential backoff. Configure with max_retries.