$npx -y skills add team-telnyx/ai --skill telnyx-numbers-services-pythonConfigure voicemail, voice channels, and emergency (E911) services for your phone numbers. This skill provides Python SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Services - Python |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | pip install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```python |
| 14 | import os |
| 15 | from telnyx import Telnyx |
| 16 | |
| 17 | client = Telnyx( |
| 18 | api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted |
| 19 | ) |
| 20 | ``` |
| 21 | |
| 22 | All examples below assume `client` is already initialized as shown above. |
| 23 | |
| 24 | ## Error Handling |
| 25 | |
| 26 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 27 | or authentication errors (401). Always handle errors in production code: |
| 28 | |
| 29 | ```python |
| 30 | import telnyx |
| 31 | |
| 32 | try: |
| 33 | result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello") |
| 34 | except telnyx.APIConnectionError: |
| 35 | print("Network error — check connectivity and retry") |
| 36 | except telnyx.RateLimitError: |
| 37 | # 429: rate limited — wait and retry with exponential backoff |
| 38 | import time |
| 39 | time.sleep(1) # Check Retry-After header for actual delay |
| 40 | except telnyx.APIStatusError as e: |
| 41 | print(f"API error {e.status_code}: {e.message}") |
| 42 | if e.status_code == 422: |
| 43 | print("Validation error — check required fields and formats") |
| 44 | ``` |
| 45 | |
| 46 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 47 | `404` resource not found, `422` validation error (check field formats), |
| 48 | `429` rate limited (retry with exponential backoff). |
| 49 | |
| 50 | ## Important Notes |
| 51 | |
| 52 | - **Pagination:** List methods return an auto-paginating iterator. Use `for item in page_result:` to iterate through all pages automatically. |
| 53 | |
| 54 | ## List your voice channels for non-US zones |
| 55 | |
| 56 | Returns the non-US voice channels for your account. voice channels allow you to use Channel Billing for calls to your Telnyx phone numbers. Please check the Telnyx Support Articles section for full information and examples of how to utilize Channel Billing. |
| 57 | |
| 58 | `GET /channel_zones` |
| 59 | |
| 60 | ```python |
| 61 | page = client.channel_zones.list() |
| 62 | page = page.data[0] |
| 63 | print(page.id) |
| 64 | ``` |
| 65 | |
| 66 | Returns: `channels` (int64), `countries` (array[string]), `created_at` (string), `id` (string), `name` (string), `record_type` (enum: channel_zone), `updated_at` (string) |
| 67 | |
| 68 | ## Update voice channels for non-US Zones |
| 69 | |
| 70 | Update the number of Voice Channels for the Non-US Zones. This allows your account to handle multiple simultaneous inbound calls to Non-US numbers. Use this endpoint to increase or decrease your capacity based on expected call volume. |
| 71 | |
| 72 | `PUT /channel_zones/{channel_zone_id}` — Required: `channels` |
| 73 | |
| 74 | ```python |
| 75 | channel_zone = client.channel_zones.update( |
| 76 | channel_zone_id="550e8400-e29b-41d4-a716-446655440000", |
| 77 | channels=0, |
| 78 | ) |
| 79 | print(channel_zone.id) |
| 80 | ``` |
| 81 | |
| 82 | Returns: `channels` (int64), `countries` (array[string]), `created_at` (string), `id` (string), `name` (string), `record_type` (enum: channel_zone), `updated_at` (string) |
| 83 | |
| 84 | ## List dynamic emergency addresses |
| 85 | |
| 86 | Returns the dynamic emergency addresses according to filters |
| 87 | |
| 88 | `GET /dynamic_emergency_addresses` |
| 89 | |
| 90 | ```python |
| 91 | page = client.dynamic_emergency_addresses.list() |
| 92 | page = page.data[0] |
| 93 | print(page.id) |
| 94 | ``` |
| 95 | |
| 96 | Returns: `administrative_area` (string), `country_code` (enum: US, CA, PR), `created_at` (string), `extended_address` (string), `house_number` (string), `house_suffix` (string), `id` (string), `locality` (string), `postal_code` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_name` (string), `street_post_directional` (string), `street_pre_directional` (string), `street_suffix` (string), `updated_at` (string) |
| 97 | |
| 98 | ## Create a dynamic emergency address. |
| 99 | |
| 100 | Creates a dynamic emergency address. |
| 101 | |
| 102 | `POST /dynamic_emergency_addresses` — Required: `house_number`, `street_name`, `locality`, `administrative_area`, `postal_code`, `country_code` |
| 103 | |
| 104 | Optional: `created_at` (string), `extended_address` (string), `house_suffix` (string), `id` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_post_directional` (string), `street_pre_directional` (string), `street_suffix` (string), `updated_at` (string) |
| 105 | |
| 106 | ```python |
| 107 | dynamic_emergency_address = client.dynamic_emergency_addresses.create( |
| 108 | administrative_area="TX", |
| 109 | country_code="US", |
| 110 | house_number="600", |
| 111 | locality="Austin", |
| 112 | postal_code="78701", |
| 113 | street_name="Congress", |
| 114 | ) |
| 115 | print(dynamic_emergency_address.data) |
| 116 | ``` |
| 117 | |
| 118 | Returns: `administrative_area` (string), `country_code` (enum: US, CA, PR), `created_at` (string), `extended_address` (string), `house_number` (string), `house_suffix` (string), `id` (string), `locality` (string), `postal_code` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_name` (string), ` |