REST Client

REST Client

Python API reference for RestClient and resource namespaces
View as MarkdownOpen in Claude

The REST namespace provides a synchronous HTTP client for the SignalWire platform APIs. It organizes every HTTP endpoint into namespaced resource objects with standard CRUD operations, letting you manage phone numbers, fabric resources, call logs, video rooms, datasphere documents, and more from Python.

Example

Search for available phone numbers, purchase one, and assign it to a fabric AI agent resource:

1from signalwire.rest import RestClient, SignalWireRestError
2
3client = RestClient(
4 project="your-project-id",
5 token="your-api-token",
6 host="your-space.signalwire.com",
7)
8
9# Search for available numbers in area code 512
10available = client.phone_numbers.search(area_code="512", quantity=3)
11for number in available.get("data", []):
12 print(f"{number['number']} - {number.get('region')}")
13
14# Purchase the first available number
15purchased = client.phone_numbers.create(number=available["data"][0]["number"])
16print(f"Purchased: {purchased['number']}")
17
18# List your AI agent resources
19response = client.fabric.ai_agents.list()
20for agent in response.get("data", []):
21 print(f"Agent: {agent['name']} ({agent['id']})")
22
23# Query recent voice call logs
24logs = client.logs.voice.list(page_size=5)
25for log in logs.get("data", []):
26 print(f"Call from {log.get('from')} to {log.get('to')}")

All three constructor arguments can also be provided via environment variables: SIGNALWIRE_PROJECT_ID, SIGNALWIRE_API_TOKEN, and SIGNALWIRE_SPACE. When those are set, you can instantiate with RestClient() and no arguments.

Error Handling

REST errors raise SignalWireRestError:

1from signalwire.rest import RestClient, SignalWireRestError
2
3client = RestClient()
4
5try:
6 client.phone_numbers.get("nonexistent-id")
7except SignalWireRestError as e:
8 print(f"HTTP {e.status_code}: {e.body}")
9 print(f"URL: {e.method} {e.url}")

Resources