voxevolv 0.1.0__py3-none-any.whl

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.
voxevolv/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ from .client import (
2
+ BrowserCredentials,
3
+ Session,
4
+ SessionsResource,
5
+ VoxEvolv,
6
+ VoxEvolvError,
7
+ idempotency_key_for,
8
+ )
9
+
10
+ __all__ = [
11
+ "BrowserCredentials",
12
+ "Session",
13
+ "SessionsResource",
14
+ "VoxEvolv",
15
+ "VoxEvolvError",
16
+ "idempotency_key_for",
17
+ ]
voxevolv/client.py ADDED
@@ -0,0 +1,250 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import json
5
+ import time
6
+ from dataclasses import dataclass
7
+ from email.utils import parsedate_to_datetime
8
+ from typing import Any, Callable, Mapping, TypedDict
9
+ from urllib.error import HTTPError, URLError
10
+ from urllib.request import Request, urlopen
11
+
12
+ Transport = Callable[[Request, float], Any]
13
+
14
+
15
+ class VoxEvolvError(Exception):
16
+ def __init__(
17
+ self,
18
+ message: str,
19
+ *,
20
+ status: int,
21
+ code: str | None = None,
22
+ request_id: str | None = None,
23
+ details: list[Any] | None = None,
24
+ retryable: bool = False,
25
+ ) -> None:
26
+ super().__init__(message)
27
+ self.status = status
28
+ self.code = code
29
+ self.request_id = request_id
30
+ self.details = details or []
31
+ self.retryable = retryable
32
+
33
+
34
+ class BrowserCredentials(TypedDict):
35
+ id: str
36
+ connection: Mapping[str, str]
37
+ access_token: str
38
+ access_token_expires_at: str
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class Session:
43
+ payload: Mapping[str, Any]
44
+
45
+ @property
46
+ def id(self) -> str:
47
+ return str(self.payload["id"])
48
+
49
+ @property
50
+ def profile_revision(self) -> str:
51
+ return str(self.payload["profile_revision"])
52
+
53
+ def browser_credentials(self) -> BrowserCredentials:
54
+ return {
55
+ "id": self.id,
56
+ "connection": self.payload["connection"],
57
+ "access_token": str(self.payload["access_token"]),
58
+ "access_token_expires_at": str(self.payload["access_token_expires_at"]),
59
+ }
60
+
61
+
62
+ class SessionsResource:
63
+ def __init__(self, client: VoxEvolv) -> None:
64
+ self._client = client
65
+
66
+ def create(
67
+ self,
68
+ *,
69
+ intent_id: str,
70
+ profile: str,
71
+ participant: Mapping[str, str],
72
+ instructions: str = "",
73
+ greeting: str = "",
74
+ language: str | None = None,
75
+ voice: str | None = None,
76
+ require: Mapping[str, Any] | None = None,
77
+ media: Mapping[str, Any] | None = None,
78
+ max_duration_seconds: int | None = None,
79
+ media_idle_timeout_seconds: int | None = None,
80
+ metadata: Mapping[str, Any] | None = None,
81
+ ) -> Session:
82
+ _validate_create(intent_id=intent_id, profile=profile, participant=participant)
83
+ identity = participant["identity"]
84
+ body: dict[str, Any] = {
85
+ "protocol_version": 1,
86
+ "client_reference_id": intent_id,
87
+ "profile": profile,
88
+ "participant": {
89
+ "identity": identity,
90
+ **(
91
+ {"display_name": participant["display_name"]}
92
+ if "display_name" in participant
93
+ else {}
94
+ ),
95
+ },
96
+ "instructions": instructions,
97
+ "greeting": greeting,
98
+ "metadata": dict(metadata or {}),
99
+ }
100
+ optional = {
101
+ "language": language,
102
+ "voice": voice,
103
+ "require": dict(require) if require is not None else None,
104
+ "media": dict(media) if media is not None else None,
105
+ "max_duration_seconds": max_duration_seconds,
106
+ "media_idle_timeout_seconds": media_idle_timeout_seconds,
107
+ }
108
+ body.update({key: value for key, value in optional.items() if value is not None})
109
+ payload = self._client._request(
110
+ "sessions/",
111
+ method="POST",
112
+ body=body,
113
+ headers={"Idempotency-Key": idempotency_key_for(intent_id)},
114
+ )
115
+ return Session(payload)
116
+
117
+ def get(self, session_id: str) -> Mapping[str, Any]:
118
+ return self._client._request(f"sessions/{session_id}")
119
+
120
+ def end(self, session_id: str) -> None:
121
+ self._client._request(f"sessions/{session_id}", method="DELETE")
122
+
123
+
124
+ class VoxEvolv:
125
+ def __init__(
126
+ self,
127
+ *,
128
+ api_key: str,
129
+ base_url: str,
130
+ max_retries: int = 2,
131
+ retry_base_seconds: float = 0.25,
132
+ timeout_seconds: float = 30.0,
133
+ transport: Transport | None = None,
134
+ sleep: Callable[[float], None] = time.sleep,
135
+ ) -> None:
136
+ if not api_key.startswith("sk_"):
137
+ raise TypeError("api_key must be a VoxEvolv server API key")
138
+ if max_retries < 0:
139
+ raise ValueError("max_retries cannot be negative")
140
+ self._api_key = api_key
141
+ self._base_url = base_url.rstrip("/")
142
+ self._max_retries = max_retries
143
+ self._retry_base_seconds = retry_base_seconds
144
+ self._timeout_seconds = timeout_seconds
145
+ self._transport = transport or _urlopen
146
+ self._sleep = sleep
147
+ self.sessions = SessionsResource(self)
148
+
149
+ def _request(
150
+ self,
151
+ path: str,
152
+ *,
153
+ method: str = "GET",
154
+ body: Mapping[str, Any] | None = None,
155
+ headers: Mapping[str, str] | None = None,
156
+ ) -> Mapping[str, Any]:
157
+ encoded = None if body is None else json.dumps(body).encode("utf-8")
158
+ request_headers = {
159
+ "Authorization": f"Bearer {self._api_key}",
160
+ "Accept": "application/json",
161
+ **({"Content-Type": "application/json"} if encoded is not None else {}),
162
+ **dict(headers or {}),
163
+ }
164
+ request = Request(
165
+ f"{self._base_url}/{path.lstrip('/')}",
166
+ data=encoded,
167
+ headers=request_headers,
168
+ method=method,
169
+ )
170
+ attempt = 0
171
+ while True:
172
+ try:
173
+ response = self._transport(request, self._timeout_seconds)
174
+ raw = response.read()
175
+ return {} if not raw else json.loads(raw)
176
+ except HTTPError as error:
177
+ retryable = error.code == 429 or error.code >= 500
178
+ if not retryable or attempt >= self._max_retries:
179
+ raise _api_error(error, retryable=retryable) from error
180
+ delay = _retry_after_seconds(error.headers.get("Retry-After"))
181
+ self._sleep(
182
+ delay
183
+ if delay is not None
184
+ else self._retry_base_seconds * (2**attempt)
185
+ )
186
+ attempt += 1
187
+ except URLError as error:
188
+ if attempt >= self._max_retries:
189
+ raise VoxEvolvError(
190
+ f"Could not reach VoxEvolv: {error.reason}",
191
+ status=0,
192
+ code="network_error",
193
+ retryable=True,
194
+ ) from error
195
+ self._sleep(self._retry_base_seconds * (2**attempt))
196
+ attempt += 1
197
+
198
+
199
+ def idempotency_key_for(intent_id: str) -> str:
200
+ if not intent_id or len(intent_id) > 200:
201
+ raise TypeError("intent_id must be between 1 and 200 characters")
202
+ digest = hashlib.sha256(intent_id.encode("utf-8")).hexdigest()
203
+ return f"intent_{digest}"
204
+
205
+
206
+ def _validate_create(
207
+ *,
208
+ intent_id: str,
209
+ profile: str,
210
+ participant: Mapping[str, str],
211
+ ) -> None:
212
+ import re
213
+
214
+ idempotency_key_for(intent_id)
215
+ if re.fullmatch(r"[a-z][a-z0-9-]{1,62}[a-z0-9]", profile) is None:
216
+ raise TypeError("profile must be a valid published profile name")
217
+ identity = participant.get("identity", "")
218
+ if re.fullmatch(r"[A-Za-z0-9_.:@-]{1,120}", identity) is None:
219
+ raise TypeError("participant identity is invalid")
220
+
221
+
222
+ def _urlopen(request: Request, timeout: float) -> Any:
223
+ return urlopen(request, timeout=timeout)
224
+
225
+
226
+ def _api_error(error: HTTPError, *, retryable: bool) -> VoxEvolvError:
227
+ try:
228
+ payload = json.loads(error.read())
229
+ except (json.JSONDecodeError, UnicodeDecodeError):
230
+ payload = {}
231
+ return VoxEvolvError(
232
+ payload.get("message", f"VoxEvolv request failed ({error.code})"),
233
+ status=error.code,
234
+ code=payload.get("error"),
235
+ request_id=payload.get("request_id"),
236
+ details=payload.get("details", []),
237
+ retryable=retryable,
238
+ )
239
+
240
+
241
+ def _retry_after_seconds(value: str | None) -> float | None:
242
+ if not value:
243
+ return None
244
+ try:
245
+ return max(0.0, float(value))
246
+ except ValueError:
247
+ try:
248
+ return max(0.0, parsedate_to_datetime(value).timestamp() - time.time())
249
+ except (TypeError, ValueError, OverflowError):
250
+ return None
voxevolv/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: voxevolv
3
+ Version: 0.1.0
4
+ Summary: Python server SDK for the VoxEvolv Voice Session API
5
+ Author: VoxEvolv contributors
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/shobhansuri/VoxEvolv
8
+ Project-URL: Issues, https://github.com/shobhansuri/VoxEvolv/issues
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # VoxEvolv Python SDK
22
+
23
+ Server-only Python client for creating and managing VoxEvolv sessions.
24
+
25
+ ```python
26
+ import os
27
+ from voxevolv import VoxEvolv
28
+
29
+ client = VoxEvolv(
30
+ api_key=os.environ["VOXEVOLV_API_KEY"],
31
+ base_url=os.environ["VOXEVOLV_API_BASE"],
32
+ )
33
+ session = client.sessions.create(
34
+ intent_id=interview_session_id,
35
+ profile="live-interviewer",
36
+ participant={"identity": user_id, "display_name": display_name},
37
+ instructions=instructions,
38
+ greeting=greeting,
39
+ )
40
+
41
+ return session.browser_credentials()
42
+ ```
43
+
44
+ The SDK derives one deterministic idempotency key from `intent_id`, preserves it
45
+ across bounded 429/5xx/network retries, and raises `VoxEvolvError` with typed API
46
+ failure information.
@@ -0,0 +1,8 @@
1
+ voxevolv/__init__.py,sha256=FCJFGPpqjUtvyN0Auz-vnEgUEmv9M4tkMv9ban8Hgu8,285
2
+ voxevolv/client.py,sha256=njwcEfgXH2Ymj6Ji1A38YyfzWGNaoMeJZtNJczqZxXM,8270
3
+ voxevolv/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
+ voxevolv-0.1.0.dist-info/licenses/LICENSE,sha256=X_9ZBwoirbzx79QmG66rQY7_lgRoC3oM7gj8hYfpKcc,1078
5
+ voxevolv-0.1.0.dist-info/METADATA,sha256=c7cQYAB9gZdp6vezjWtEquq32vPQRJE6KXot9avUGfI,1445
6
+ voxevolv-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
7
+ voxevolv-0.1.0.dist-info/top_level.txt,sha256=_c6f2s_VekeRA2z9O9DAqUa2Nlu2b5pZ0mgD32o8ywg,9
8
+ voxevolv-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VoxEvolv contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ voxevolv