phonic 0.30.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. phonic-0.30.0/PKG-INFO +289 -0
  2. phonic-0.30.0/README.md +259 -0
  3. phonic-0.30.0/pyproject.toml +85 -0
  4. phonic-0.30.0/src/phonic/__init__.py +261 -0
  5. phonic-0.30.0/src/phonic/agents/__init__.py +29 -0
  6. phonic-0.30.0/src/phonic/agents/client.py +1195 -0
  7. phonic-0.30.0/src/phonic/agents/raw_client.py +1438 -0
  8. phonic-0.30.0/src/phonic/agents/types/__init__.py +27 -0
  9. phonic-0.30.0/src/phonic/agents/types/agents_create_response.py +27 -0
  10. phonic-0.30.0/src/phonic/agents/types/agents_delete_response.py +22 -0
  11. phonic-0.30.0/src/phonic/agents/types/agents_get_response.py +20 -0
  12. phonic-0.30.0/src/phonic/agents/types/agents_list_response.py +20 -0
  13. phonic-0.30.0/src/phonic/agents/types/agents_update_response.py +22 -0
  14. phonic-0.30.0/src/phonic/agents/types/agents_upsert_response.py +29 -0
  15. phonic-0.30.0/src/phonic/agents/types/update_agent_request_audio_format.py +5 -0
  16. phonic-0.30.0/src/phonic/agents/types/update_agent_request_configuration_endpoint.py +36 -0
  17. phonic-0.30.0/src/phonic/agents/types/update_agent_request_template_variables_value.py +19 -0
  18. phonic-0.30.0/src/phonic/agents/types/update_agent_request_tools_item.py +7 -0
  19. phonic-0.30.0/src/phonic/client.py +154 -0
  20. phonic-0.30.0/src/phonic/conversations/__init__.py +29 -0
  21. phonic-0.30.0/src/phonic/conversations/client.py +922 -0
  22. phonic-0.30.0/src/phonic/conversations/raw_client.py +1421 -0
  23. phonic-0.30.0/src/phonic/conversations/types/__init__.py +27 -0
  24. phonic-0.30.0/src/phonic/conversations/types/conversations_cancel_response.py +22 -0
  25. phonic-0.30.0/src/phonic/conversations/types/conversations_extract_data_response.py +22 -0
  26. phonic-0.30.0/src/phonic/conversations/types/conversations_get_analysis_response.py +20 -0
  27. phonic-0.30.0/src/phonic/conversations/types/conversations_get_response.py +20 -0
  28. phonic-0.30.0/src/phonic/conversations/types/conversations_list_evaluations_response.py +20 -0
  29. phonic-0.30.0/src/phonic/conversations/types/conversations_list_extractions_response.py +20 -0
  30. phonic-0.30.0/src/phonic/conversations/types/conversations_list_response.py +8 -0
  31. phonic-0.30.0/src/phonic/conversations/types/conversations_list_response_conversation.py +20 -0
  32. phonic-0.30.0/src/phonic/conversations/types/conversations_list_response_conversations.py +20 -0
  33. phonic-0.30.0/src/phonic/conversations/types/conversations_outbound_call_response.py +22 -0
  34. phonic-0.30.0/src/phonic/core/__init__.py +55 -0
  35. phonic-0.30.0/src/phonic/core/api_error.py +23 -0
  36. phonic-0.30.0/src/phonic/core/client_wrapper.py +80 -0
  37. phonic-0.30.0/src/phonic/core/datetime_utils.py +28 -0
  38. phonic-0.30.0/src/phonic/core/events.py +38 -0
  39. phonic-0.30.0/src/phonic/core/file.py +67 -0
  40. phonic-0.30.0/src/phonic/core/force_multipart.py +16 -0
  41. phonic-0.30.0/src/phonic/core/http_client.py +543 -0
  42. phonic-0.30.0/src/phonic/core/http_response.py +55 -0
  43. phonic-0.30.0/src/phonic/core/jsonable_encoder.py +100 -0
  44. phonic-0.30.0/src/phonic/core/pydantic_utilities.py +255 -0
  45. phonic-0.30.0/src/phonic/core/query_encoder.py +58 -0
  46. phonic-0.30.0/src/phonic/core/remove_none_from_dict.py +11 -0
  47. phonic-0.30.0/src/phonic/core/request_options.py +35 -0
  48. phonic-0.30.0/src/phonic/core/serialization.py +276 -0
  49. phonic-0.30.0/src/phonic/environment.py +14 -0
  50. phonic-0.30.0/src/phonic/errors/__init__.py +11 -0
  51. phonic-0.30.0/src/phonic/errors/bad_request_error.py +11 -0
  52. phonic-0.30.0/src/phonic/errors/conflict_error.py +11 -0
  53. phonic-0.30.0/src/phonic/errors/forbidden_error.py +11 -0
  54. phonic-0.30.0/src/phonic/errors/gateway_timeout_error.py +11 -0
  55. phonic-0.30.0/src/phonic/errors/not_found_error.py +11 -0
  56. phonic-0.30.0/src/phonic/extraction_schemas/__init__.py +19 -0
  57. phonic-0.30.0/src/phonic/extraction_schemas/client.py +582 -0
  58. phonic-0.30.0/src/phonic/extraction_schemas/raw_client.py +803 -0
  59. phonic-0.30.0/src/phonic/extraction_schemas/types/__init__.py +17 -0
  60. phonic-0.30.0/src/phonic/extraction_schemas/types/extraction_schemas_create_response.py +27 -0
  61. phonic-0.30.0/src/phonic/extraction_schemas/types/extraction_schemas_delete_response.py +22 -0
  62. phonic-0.30.0/src/phonic/extraction_schemas/types/extraction_schemas_get_response.py +20 -0
  63. phonic-0.30.0/src/phonic/extraction_schemas/types/extraction_schemas_list_response.py +20 -0
  64. phonic-0.30.0/src/phonic/extraction_schemas/types/extraction_schemas_update_response.py +22 -0
  65. phonic-0.30.0/src/phonic/projects/__init__.py +23 -0
  66. phonic-0.30.0/src/phonic/projects/client.py +595 -0
  67. phonic-0.30.0/src/phonic/projects/raw_client.py +707 -0
  68. phonic-0.30.0/src/phonic/projects/types/__init__.py +21 -0
  69. phonic-0.30.0/src/phonic/projects/types/projects_create_eval_prompt_response.py +22 -0
  70. phonic-0.30.0/src/phonic/projects/types/projects_create_response.py +27 -0
  71. phonic-0.30.0/src/phonic/projects/types/projects_delete_response.py +22 -0
  72. phonic-0.30.0/src/phonic/projects/types/projects_get_response.py +20 -0
  73. phonic-0.30.0/src/phonic/projects/types/projects_list_eval_prompts_response.py +20 -0
  74. phonic-0.30.0/src/phonic/projects/types/projects_list_response.py +20 -0
  75. phonic-0.30.0/src/phonic/projects/types/projects_update_response.py +22 -0
  76. phonic-0.30.0/src/phonic/py.typed +0 -0
  77. phonic-0.30.0/src/phonic/sts/__init__.py +4 -0
  78. phonic-0.30.0/src/phonic/sts/client.py +156 -0
  79. phonic-0.30.0/src/phonic/sts/raw_client.py +133 -0
  80. phonic-0.30.0/src/phonic/sts/socket_client.py +248 -0
  81. phonic-0.30.0/src/phonic/tools/__init__.py +27 -0
  82. phonic-0.30.0/src/phonic/tools/client.py +724 -0
  83. phonic-0.30.0/src/phonic/tools/raw_client.py +960 -0
  84. phonic-0.30.0/src/phonic/tools/types/__init__.py +25 -0
  85. phonic-0.30.0/src/phonic/tools/types/create_tool_request_execution_mode.py +5 -0
  86. phonic-0.30.0/src/phonic/tools/types/create_tool_request_type.py +5 -0
  87. phonic-0.30.0/src/phonic/tools/types/tools_create_response.py +27 -0
  88. phonic-0.30.0/src/phonic/tools/types/tools_delete_response.py +22 -0
  89. phonic-0.30.0/src/phonic/tools/types/tools_get_response.py +20 -0
  90. phonic-0.30.0/src/phonic/tools/types/tools_list_response.py +20 -0
  91. phonic-0.30.0/src/phonic/tools/types/tools_update_response.py +22 -0
  92. phonic-0.30.0/src/phonic/tools/types/update_tool_request_execution_mode.py +5 -0
  93. phonic-0.30.0/src/phonic/tools/types/update_tool_request_type.py +5 -0
  94. phonic-0.30.0/src/phonic/types/__init__.py +143 -0
  95. phonic-0.30.0/src/phonic/types/agent.py +113 -0
  96. phonic-0.30.0/src/phonic/types/agent_audio_format.py +5 -0
  97. phonic-0.30.0/src/phonic/types/agent_configuration_endpoint.py +28 -0
  98. phonic-0.30.0/src/phonic/types/agent_project.py +24 -0
  99. phonic-0.30.0/src/phonic/types/agent_template_variables_value.py +19 -0
  100. phonic-0.30.0/src/phonic/types/agent_tools_item.py +5 -0
  101. phonic-0.30.0/src/phonic/types/assistant_chose_not_to_respond_payload.py +19 -0
  102. phonic-0.30.0/src/phonic/types/assistant_ended_conversation_payload.py +19 -0
  103. phonic-0.30.0/src/phonic/types/audio_chunk_payload.py +29 -0
  104. phonic-0.30.0/src/phonic/types/audio_chunk_response_payload.py +28 -0
  105. phonic-0.30.0/src/phonic/types/audio_finished_payload.py +19 -0
  106. phonic-0.30.0/src/phonic/types/config_payload.py +125 -0
  107. phonic-0.30.0/src/phonic/types/config_payload_input_format.py +5 -0
  108. phonic-0.30.0/src/phonic/types/config_payload_output_format.py +5 -0
  109. phonic-0.30.0/src/phonic/types/conversation.py +94 -0
  110. phonic-0.30.0/src/phonic/types/conversation_analysis.py +27 -0
  111. phonic-0.30.0/src/phonic/types/conversation_created_payload.py +23 -0
  112. phonic-0.30.0/src/phonic/types/conversation_eval.py +5 -0
  113. phonic-0.30.0/src/phonic/types/conversation_eval_prompt.py +32 -0
  114. phonic-0.30.0/src/phonic/types/conversation_evaluation.py +23 -0
  115. phonic-0.30.0/src/phonic/types/conversation_evaluation_result.py +40 -0
  116. phonic-0.30.0/src/phonic/types/conversation_evaluation_result_prompt.py +24 -0
  117. phonic-0.30.0/src/phonic/types/conversation_evaluation_result_result.py +7 -0
  118. phonic-0.30.0/src/phonic/types/conversation_extraction.py +47 -0
  119. phonic-0.30.0/src/phonic/types/conversation_extraction_schema.py +20 -0
  120. phonic-0.30.0/src/phonic/types/conversation_item.py +64 -0
  121. phonic-0.30.0/src/phonic/types/conversation_item_role.py +5 -0
  122. phonic-0.30.0/src/phonic/types/create_agent_request.py +100 -0
  123. phonic-0.30.0/src/phonic/types/create_agent_request_audio_format.py +5 -0
  124. phonic-0.30.0/src/phonic/types/create_agent_request_configuration_endpoint.py +36 -0
  125. phonic-0.30.0/src/phonic/types/create_agent_request_template_variables_value.py +19 -0
  126. phonic-0.30.0/src/phonic/types/create_agent_request_tools_item.py +7 -0
  127. phonic-0.30.0/src/phonic/types/dtmf_payload.py +23 -0
  128. phonic-0.30.0/src/phonic/types/error.py +24 -0
  129. phonic-0.30.0/src/phonic/types/error_error.py +27 -0
  130. phonic-0.30.0/src/phonic/types/error_payload.py +25 -0
  131. phonic-0.30.0/src/phonic/types/error_payload_error.py +27 -0
  132. phonic-0.30.0/src/phonic/types/extraction_field.py +33 -0
  133. phonic-0.30.0/src/phonic/types/extraction_field_type.py +5 -0
  134. phonic-0.30.0/src/phonic/types/extraction_schema.py +38 -0
  135. phonic-0.30.0/src/phonic/types/input_cancelled_payload.py +19 -0
  136. phonic-0.30.0/src/phonic/types/input_text_payload.py +23 -0
  137. phonic-0.30.0/src/phonic/types/interrupted_response_payload.py +23 -0
  138. phonic-0.30.0/src/phonic/types/is_user_speaking_payload.py +23 -0
  139. phonic-0.30.0/src/phonic/types/outbound_call_config.py +77 -0
  140. phonic-0.30.0/src/phonic/types/outbound_call_config_tools_item.py +7 -0
  141. phonic-0.30.0/src/phonic/types/project.py +33 -0
  142. phonic-0.30.0/src/phonic/types/project_default_agent.py +31 -0
  143. phonic-0.30.0/src/phonic/types/ready_to_start_conversation_payload.py +19 -0
  144. phonic-0.30.0/src/phonic/types/set_external_id_payload.py +23 -0
  145. phonic-0.30.0/src/phonic/types/set_twilio_call_sid_payload.py +23 -0
  146. phonic-0.30.0/src/phonic/types/task.py +27 -0
  147. phonic-0.30.0/src/phonic/types/tool.py +77 -0
  148. phonic-0.30.0/src/phonic/types/tool_call_interrupted_payload.py +33 -0
  149. phonic-0.30.0/src/phonic/types/tool_call_output_payload.py +25 -0
  150. phonic-0.30.0/src/phonic/types/tool_call_output_processed_payload.py +68 -0
  151. phonic-0.30.0/src/phonic/types/tool_call_output_processed_payload_tool.py +27 -0
  152. phonic-0.30.0/src/phonic/types/tool_call_payload.py +33 -0
  153. phonic-0.30.0/src/phonic/types/tool_execution_mode.py +5 -0
  154. phonic-0.30.0/src/phonic/types/tool_parameter.py +44 -0
  155. phonic-0.30.0/src/phonic/types/tool_parameter_item_type.py +5 -0
  156. phonic-0.30.0/src/phonic/types/tool_parameter_type.py +5 -0
  157. phonic-0.30.0/src/phonic/types/tool_project.py +20 -0
  158. phonic-0.30.0/src/phonic/types/tool_type.py +5 -0
  159. phonic-0.30.0/src/phonic/types/update_system_prompt_payload.py +23 -0
  160. phonic-0.30.0/src/phonic/types/user_finished_speaking_payload.py +19 -0
  161. phonic-0.30.0/src/phonic/types/user_started_speaking_payload.py +19 -0
  162. phonic-0.30.0/src/phonic/types/voice.py +32 -0
  163. phonic-0.30.0/src/phonic/version.py +3 -0
  164. phonic-0.30.0/src/phonic/voices/__init__.py +7 -0
  165. phonic-0.30.0/src/phonic/voices/client.py +171 -0
  166. phonic-0.30.0/src/phonic/voices/raw_client.py +205 -0
  167. phonic-0.30.0/src/phonic/voices/types/__init__.py +8 -0
  168. phonic-0.30.0/src/phonic/voices/types/voices_get_response.py +20 -0
  169. phonic-0.30.0/src/phonic/voices/types/voices_list_response.py +20 -0
phonic-0.30.0/PKG-INFO ADDED
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.3
2
+ Name: phonic
3
+ Version: 0.30.0
4
+ Summary:
5
+ Requires-Python: >=3.8,<4.0
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: MacOS
8
+ Classifier: Operating System :: Microsoft :: Windows
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Operating System :: POSIX
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Dist: httpx (>=0.21.2)
23
+ Requires-Dist: pydantic (>=1.9.2)
24
+ Requires-Dist: pydantic-core (>=2.18.2)
25
+ Requires-Dist: typing_extensions (>=4.0.0)
26
+ Requires-Dist: websockets (>=12.0)
27
+ Project-URL: Repository, https://github.com/fern-demo/phonic-python-sdk
28
+ Description-Content-Type: text/markdown
29
+
30
+ # Phonic Python Library
31
+
32
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Ffern-demo%2Fphonic-python-sdk)
33
+ [![pypi](https://img.shields.io/pypi/v/phonic)](https://pypi.python.org/pypi/phonic)
34
+
35
+ The Phonic Python library provides convenient access to the Phonic API from Python.
36
+
37
+ ## Installation
38
+
39
+ ```sh
40
+ pip install phonic
41
+ ```
42
+
43
+ ## Reference
44
+
45
+ A full reference for this library is available [here](https://github.com/fern-demo/phonic-python-sdk/blob/HEAD/./reference.md).
46
+
47
+ ## Usage
48
+
49
+ Instantiate and use the client with the following:
50
+
51
+ ```python
52
+ from phonic import (
53
+ CreateAgentRequestConfigurationEndpoint,
54
+ CreateAgentRequestTemplateVariablesValue,
55
+ Phonic,
56
+ )
57
+
58
+ client = Phonic(
59
+ token="YOUR_TOKEN",
60
+ )
61
+ client.agents.create(
62
+ name="support-agent",
63
+ timezone="America/Los_Angeles",
64
+ voice_id="sarah",
65
+ audio_speed=1.0,
66
+ welcome_message="Hi {{customer_name}}. How can I help you today?",
67
+ system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
68
+ template_variables={
69
+ "customer_name": CreateAgentRequestTemplateVariablesValue(),
70
+ "subject": CreateAgentRequestTemplateVariablesValue(
71
+ default_value="Chess",
72
+ ),
73
+ },
74
+ tools=[],
75
+ no_input_poke_sec=30,
76
+ no_input_poke_text="Are you still there?",
77
+ boosted_keywords=["Load ID", "dispatch"],
78
+ configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
79
+ url="https://api.example.com/config",
80
+ headers={"Authorization": "Bearer token123"},
81
+ timeout_ms=7000,
82
+ ),
83
+ )
84
+ ```
85
+
86
+ ## Async Client
87
+
88
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
89
+
90
+ ```python
91
+ import asyncio
92
+
93
+ from phonic import (
94
+ AsyncPhonic,
95
+ CreateAgentRequestConfigurationEndpoint,
96
+ CreateAgentRequestTemplateVariablesValue,
97
+ )
98
+
99
+ client = AsyncPhonic(
100
+ token="YOUR_TOKEN",
101
+ )
102
+
103
+
104
+ async def main() -> None:
105
+ await client.agents.create(
106
+ name="support-agent",
107
+ timezone="America/Los_Angeles",
108
+ voice_id="sarah",
109
+ audio_speed=1.0,
110
+ welcome_message="Hi {{customer_name}}. How can I help you today?",
111
+ system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
112
+ template_variables={
113
+ "customer_name": CreateAgentRequestTemplateVariablesValue(),
114
+ "subject": CreateAgentRequestTemplateVariablesValue(
115
+ default_value="Chess",
116
+ ),
117
+ },
118
+ tools=[],
119
+ no_input_poke_sec=30,
120
+ no_input_poke_text="Are you still there?",
121
+ boosted_keywords=["Load ID", "dispatch"],
122
+ configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
123
+ url="https://api.example.com/config",
124
+ headers={"Authorization": "Bearer token123"},
125
+ timeout_ms=7000,
126
+ ),
127
+ )
128
+
129
+
130
+ asyncio.run(main())
131
+ ```
132
+
133
+ ## Exception Handling
134
+
135
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
136
+ will be thrown.
137
+
138
+ ```python
139
+ from phonic.core.api_error import ApiError
140
+
141
+ try:
142
+ client.agents.create(...)
143
+ except ApiError as e:
144
+ print(e.status_code)
145
+ print(e.body)
146
+ ```
147
+
148
+ ## Websockets
149
+
150
+ The SDK supports both sync and async websocket connections for real-time, low-latency communication. Sockets can be created using the `connect` method, which returns a context manager.
151
+ You can either iterate through the returned `SocketClient` to process messages as they arrive, or attach handlers to respond to specific events.
152
+
153
+ ```python
154
+
155
+ # Connect to the websocket (Sync)
156
+ import threading
157
+
158
+ from phonic import Phonic
159
+
160
+ client = Phonic(...)
161
+
162
+ with client.sts.connect(...) as socket:
163
+ # Iterate over the messages as they arrive
164
+ for message in socket
165
+ print(message)
166
+
167
+ # Or, attach handlers to specific events
168
+ socket.on(EventType.OPEN, lambda _: print("open"))
169
+ socket.on(EventType.MESSAGE, lambda message: print("received message", message))
170
+ socket.on(EventType.CLOSE, lambda _: print("close"))
171
+ socket.on(EventType.ERROR, lambda error: print("error", error))
172
+
173
+
174
+ # Start the listening loop in a background thread
175
+ listener_thread = threading.Thread(target=socket.start_listening, daemon=True)
176
+ listener_thread.start()
177
+ ```
178
+
179
+ ```python
180
+
181
+ # Connect to the websocket (Async)
182
+ import asyncio
183
+
184
+ from phonic import AsyncPhonic
185
+
186
+ client = AsyncPhonic(...)
187
+
188
+ async with client.sts.connect(...) as socket:
189
+ # Iterate over the messages as they arrive
190
+ async for message in socket
191
+ print(message)
192
+
193
+ # Or, attach handlers to specific events
194
+ socket.on(EventType.OPEN, lambda _: print("open"))
195
+ socket.on(EventType.MESSAGE, lambda message: print("received message", message))
196
+ socket.on(EventType.CLOSE, lambda _: print("close"))
197
+ socket.on(EventType.ERROR, lambda error: print("error", error))
198
+
199
+
200
+ # Start listening for events in an asyncio task
201
+ listen_task = asyncio.create_task(socket.start_listening())
202
+ ```
203
+
204
+ ## Advanced
205
+
206
+ ### Access Raw Response Data
207
+
208
+ The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
209
+ The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
210
+
211
+ ```python
212
+ from phonic import Phonic
213
+
214
+ client = Phonic(
215
+ ...,
216
+ )
217
+ response = client.agents.with_raw_response.create(...)
218
+ print(response.headers) # access the response headers
219
+ print(response.data) # access the underlying object
220
+ ```
221
+
222
+ ### Retries
223
+
224
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
225
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
226
+ retry limit (default: 2).
227
+
228
+ A request is deemed retryable when any of the following HTTP status codes is returned:
229
+
230
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
231
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
232
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
233
+
234
+ Use the `max_retries` request option to configure this behavior.
235
+
236
+ ```python
237
+ client.agents.create(..., request_options={
238
+ "max_retries": 1
239
+ })
240
+ ```
241
+
242
+ ### Timeouts
243
+
244
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
245
+
246
+ ```python
247
+
248
+ from phonic import Phonic
249
+
250
+ client = Phonic(
251
+ ...,
252
+ timeout=20.0,
253
+ )
254
+
255
+
256
+ # Override timeout for a specific method
257
+ client.agents.create(..., request_options={
258
+ "timeout_in_seconds": 1
259
+ })
260
+ ```
261
+
262
+ ### Custom Client
263
+
264
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
265
+ and transports.
266
+
267
+ ```python
268
+ import httpx
269
+ from phonic import Phonic
270
+
271
+ client = Phonic(
272
+ ...,
273
+ httpx_client=httpx.Client(
274
+ proxies="http://my.test.proxy.example.com",
275
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
276
+ ),
277
+ )
278
+ ```
279
+
280
+ ## Contributing
281
+
282
+ While we value open-source contributions to this SDK, this library is generated programmatically.
283
+ Additions made directly to this library would have to be moved over to our generation code,
284
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
285
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
286
+ an issue first to discuss with us!
287
+
288
+ On the other hand, contributions to the README are always very welcome!
289
+
@@ -0,0 +1,259 @@
1
+ # Phonic Python Library
2
+
3
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Ffern-demo%2Fphonic-python-sdk)
4
+ [![pypi](https://img.shields.io/pypi/v/phonic)](https://pypi.python.org/pypi/phonic)
5
+
6
+ The Phonic Python library provides convenient access to the Phonic API from Python.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ pip install phonic
12
+ ```
13
+
14
+ ## Reference
15
+
16
+ A full reference for this library is available [here](https://github.com/fern-demo/phonic-python-sdk/blob/HEAD/./reference.md).
17
+
18
+ ## Usage
19
+
20
+ Instantiate and use the client with the following:
21
+
22
+ ```python
23
+ from phonic import (
24
+ CreateAgentRequestConfigurationEndpoint,
25
+ CreateAgentRequestTemplateVariablesValue,
26
+ Phonic,
27
+ )
28
+
29
+ client = Phonic(
30
+ token="YOUR_TOKEN",
31
+ )
32
+ client.agents.create(
33
+ name="support-agent",
34
+ timezone="America/Los_Angeles",
35
+ voice_id="sarah",
36
+ audio_speed=1.0,
37
+ welcome_message="Hi {{customer_name}}. How can I help you today?",
38
+ system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
39
+ template_variables={
40
+ "customer_name": CreateAgentRequestTemplateVariablesValue(),
41
+ "subject": CreateAgentRequestTemplateVariablesValue(
42
+ default_value="Chess",
43
+ ),
44
+ },
45
+ tools=[],
46
+ no_input_poke_sec=30,
47
+ no_input_poke_text="Are you still there?",
48
+ boosted_keywords=["Load ID", "dispatch"],
49
+ configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
50
+ url="https://api.example.com/config",
51
+ headers={"Authorization": "Bearer token123"},
52
+ timeout_ms=7000,
53
+ ),
54
+ )
55
+ ```
56
+
57
+ ## Async Client
58
+
59
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
60
+
61
+ ```python
62
+ import asyncio
63
+
64
+ from phonic import (
65
+ AsyncPhonic,
66
+ CreateAgentRequestConfigurationEndpoint,
67
+ CreateAgentRequestTemplateVariablesValue,
68
+ )
69
+
70
+ client = AsyncPhonic(
71
+ token="YOUR_TOKEN",
72
+ )
73
+
74
+
75
+ async def main() -> None:
76
+ await client.agents.create(
77
+ name="support-agent",
78
+ timezone="America/Los_Angeles",
79
+ voice_id="sarah",
80
+ audio_speed=1.0,
81
+ welcome_message="Hi {{customer_name}}. How can I help you today?",
82
+ system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
83
+ template_variables={
84
+ "customer_name": CreateAgentRequestTemplateVariablesValue(),
85
+ "subject": CreateAgentRequestTemplateVariablesValue(
86
+ default_value="Chess",
87
+ ),
88
+ },
89
+ tools=[],
90
+ no_input_poke_sec=30,
91
+ no_input_poke_text="Are you still there?",
92
+ boosted_keywords=["Load ID", "dispatch"],
93
+ configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
94
+ url="https://api.example.com/config",
95
+ headers={"Authorization": "Bearer token123"},
96
+ timeout_ms=7000,
97
+ ),
98
+ )
99
+
100
+
101
+ asyncio.run(main())
102
+ ```
103
+
104
+ ## Exception Handling
105
+
106
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
107
+ will be thrown.
108
+
109
+ ```python
110
+ from phonic.core.api_error import ApiError
111
+
112
+ try:
113
+ client.agents.create(...)
114
+ except ApiError as e:
115
+ print(e.status_code)
116
+ print(e.body)
117
+ ```
118
+
119
+ ## Websockets
120
+
121
+ The SDK supports both sync and async websocket connections for real-time, low-latency communication. Sockets can be created using the `connect` method, which returns a context manager.
122
+ You can either iterate through the returned `SocketClient` to process messages as they arrive, or attach handlers to respond to specific events.
123
+
124
+ ```python
125
+
126
+ # Connect to the websocket (Sync)
127
+ import threading
128
+
129
+ from phonic import Phonic
130
+
131
+ client = Phonic(...)
132
+
133
+ with client.sts.connect(...) as socket:
134
+ # Iterate over the messages as they arrive
135
+ for message in socket
136
+ print(message)
137
+
138
+ # Or, attach handlers to specific events
139
+ socket.on(EventType.OPEN, lambda _: print("open"))
140
+ socket.on(EventType.MESSAGE, lambda message: print("received message", message))
141
+ socket.on(EventType.CLOSE, lambda _: print("close"))
142
+ socket.on(EventType.ERROR, lambda error: print("error", error))
143
+
144
+
145
+ # Start the listening loop in a background thread
146
+ listener_thread = threading.Thread(target=socket.start_listening, daemon=True)
147
+ listener_thread.start()
148
+ ```
149
+
150
+ ```python
151
+
152
+ # Connect to the websocket (Async)
153
+ import asyncio
154
+
155
+ from phonic import AsyncPhonic
156
+
157
+ client = AsyncPhonic(...)
158
+
159
+ async with client.sts.connect(...) as socket:
160
+ # Iterate over the messages as they arrive
161
+ async for message in socket
162
+ print(message)
163
+
164
+ # Or, attach handlers to specific events
165
+ socket.on(EventType.OPEN, lambda _: print("open"))
166
+ socket.on(EventType.MESSAGE, lambda message: print("received message", message))
167
+ socket.on(EventType.CLOSE, lambda _: print("close"))
168
+ socket.on(EventType.ERROR, lambda error: print("error", error))
169
+
170
+
171
+ # Start listening for events in an asyncio task
172
+ listen_task = asyncio.create_task(socket.start_listening())
173
+ ```
174
+
175
+ ## Advanced
176
+
177
+ ### Access Raw Response Data
178
+
179
+ The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
180
+ The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
181
+
182
+ ```python
183
+ from phonic import Phonic
184
+
185
+ client = Phonic(
186
+ ...,
187
+ )
188
+ response = client.agents.with_raw_response.create(...)
189
+ print(response.headers) # access the response headers
190
+ print(response.data) # access the underlying object
191
+ ```
192
+
193
+ ### Retries
194
+
195
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
196
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
197
+ retry limit (default: 2).
198
+
199
+ A request is deemed retryable when any of the following HTTP status codes is returned:
200
+
201
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
202
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
203
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
204
+
205
+ Use the `max_retries` request option to configure this behavior.
206
+
207
+ ```python
208
+ client.agents.create(..., request_options={
209
+ "max_retries": 1
210
+ })
211
+ ```
212
+
213
+ ### Timeouts
214
+
215
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
216
+
217
+ ```python
218
+
219
+ from phonic import Phonic
220
+
221
+ client = Phonic(
222
+ ...,
223
+ timeout=20.0,
224
+ )
225
+
226
+
227
+ # Override timeout for a specific method
228
+ client.agents.create(..., request_options={
229
+ "timeout_in_seconds": 1
230
+ })
231
+ ```
232
+
233
+ ### Custom Client
234
+
235
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
236
+ and transports.
237
+
238
+ ```python
239
+ import httpx
240
+ from phonic import Phonic
241
+
242
+ client = Phonic(
243
+ ...,
244
+ httpx_client=httpx.Client(
245
+ proxies="http://my.test.proxy.example.com",
246
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
247
+ ),
248
+ )
249
+ ```
250
+
251
+ ## Contributing
252
+
253
+ While we value open-source contributions to this SDK, this library is generated programmatically.
254
+ Additions made directly to this library would have to be moved over to our generation code,
255
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
256
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
257
+ an issue first to discuss with us!
258
+
259
+ On the other hand, contributions to the README are always very welcome!
@@ -0,0 +1,85 @@
1
+ [project]
2
+ name = "phonic"
3
+
4
+ [tool.poetry]
5
+ name = "phonic"
6
+ version = "0.30.0"
7
+ description = ""
8
+ readme = "README.md"
9
+ authors = []
10
+ keywords = []
11
+
12
+ classifiers = [
13
+ "Intended Audience :: Developers",
14
+ "Programming Language :: Python",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.8",
17
+ "Programming Language :: Python :: 3.9",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Operating System :: OS Independent",
22
+ "Operating System :: POSIX",
23
+ "Operating System :: MacOS",
24
+ "Operating System :: POSIX :: Linux",
25
+ "Operating System :: Microsoft :: Windows",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ "Typing :: Typed"
28
+ ]
29
+ packages = [
30
+ { include = "phonic", from = "src"}
31
+ ]
32
+
33
+ [project.urls]
34
+ Repository = 'https://github.com/fern-demo/phonic-python-sdk'
35
+
36
+ [tool.poetry.dependencies]
37
+ python = "^3.8"
38
+ httpx = ">=0.21.2"
39
+ pydantic = ">= 1.9.2"
40
+ pydantic-core = ">=2.18.2"
41
+ typing_extensions = ">= 4.0.0"
42
+ websockets = ">=12.0"
43
+
44
+ [tool.poetry.group.dev.dependencies]
45
+ mypy = "==1.13.0"
46
+ pytest = "^7.4.0"
47
+ pytest-asyncio = "^0.23.5"
48
+ python-dateutil = "^2.9.0"
49
+ types-python-dateutil = "^2.9.0.20240316"
50
+ ruff = "==0.11.5"
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = [ "tests" ]
54
+ asyncio_mode = "auto"
55
+
56
+ [tool.mypy]
57
+ plugins = ["pydantic.mypy"]
58
+
59
+ [tool.ruff]
60
+ line-length = 120
61
+
62
+ [tool.ruff.lint]
63
+ select = [
64
+ "E", # pycodestyle errors
65
+ "F", # pyflakes
66
+ "I", # isort
67
+ ]
68
+ ignore = [
69
+ "E402", # Module level import not at top of file
70
+ "E501", # Line too long
71
+ "E711", # Comparison to `None` should be `cond is not None`
72
+ "E712", # Avoid equality comparisons to `True`; use `if ...:` checks
73
+ "E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for insinstance checks
74
+ "E722", # Do not use bare `except`
75
+ "E731", # Do not assign a `lambda` expression, use a `def`
76
+ "F821", # Undefined name
77
+ "F841" # Local variable ... is assigned to but never used
78
+ ]
79
+
80
+ [tool.ruff.lint.isort]
81
+ section-order = ["future", "standard-library", "third-party", "first-party"]
82
+
83
+ [build-system]
84
+ requires = ["poetry-core"]
85
+ build-backend = "poetry.core.masonry.api"