spitch 1.33.0__py3-none-any.whl → 1.35.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.

Potentially problematic release.


This version of spitch might be problematic. Click here for more details.

spitch/__init__.py CHANGED
@@ -3,7 +3,7 @@
3
3
  import typing as _t
4
4
 
5
5
  from . import types
6
- from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes
6
+ from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
7
7
  from ._utils import file_from_path
8
8
  from ._client import Client, Spitch, Stream, Timeout, Transport, AsyncClient, AsyncSpitch, AsyncStream, RequestOptions
9
9
  from ._models import BaseModel
@@ -38,6 +38,8 @@ __all__ = [
38
38
  "ProxiesTypes",
39
39
  "NotGiven",
40
40
  "NOT_GIVEN",
41
+ "not_given",
42
+ "omit",
41
43
  "SpitchError",
42
44
  "APIError",
43
45
  "APIStatusError",
spitch/_base_client.py CHANGED
@@ -42,7 +42,6 @@ from . import _exceptions
42
42
  from ._qs import Querystring
43
43
  from ._files import to_httpx_files, async_to_httpx_files
44
44
  from ._types import (
45
- NOT_GIVEN,
46
45
  Body,
47
46
  Omit,
48
47
  Query,
@@ -57,9 +56,10 @@ from ._types import (
57
56
  RequestOptions,
58
57
  HttpxRequestFiles,
59
58
  ModelBuilderProtocol,
59
+ not_given,
60
60
  )
61
61
  from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
62
- from ._compat import PYDANTIC_V2, model_copy, model_dump
62
+ from ._compat import PYDANTIC_V1, model_copy, model_dump
63
63
  from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
64
64
  from ._response import (
65
65
  APIResponse,
@@ -145,9 +145,9 @@ class PageInfo:
145
145
  def __init__(
146
146
  self,
147
147
  *,
148
- url: URL | NotGiven = NOT_GIVEN,
149
- json: Body | NotGiven = NOT_GIVEN,
150
- params: Query | NotGiven = NOT_GIVEN,
148
+ url: URL | NotGiven = not_given,
149
+ json: Body | NotGiven = not_given,
150
+ params: Query | NotGiven = not_given,
151
151
  ) -> None:
152
152
  self.url = url
153
153
  self.json = json
@@ -232,7 +232,7 @@ class BaseSyncPage(BasePage[_T], Generic[_T]):
232
232
  model: Type[_T],
233
233
  options: FinalRequestOptions,
234
234
  ) -> None:
235
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
235
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
236
236
  self.__pydantic_private__ = {}
237
237
 
238
238
  self._model = model
@@ -320,7 +320,7 @@ class BaseAsyncPage(BasePage[_T], Generic[_T]):
320
320
  client: AsyncAPIClient,
321
321
  options: FinalRequestOptions,
322
322
  ) -> None:
323
- if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
323
+ if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
324
324
  self.__pydantic_private__ = {}
325
325
 
326
326
  self._model = model
@@ -595,7 +595,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
595
595
  # we internally support defining a temporary header to override the
596
596
  # default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
597
597
  # see _response.py for implementation details
598
- override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, NOT_GIVEN)
598
+ override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
599
599
  if is_given(override_cast_to):
600
600
  options.headers = headers
601
601
  return cast(Type[ResponseT], override_cast_to)
@@ -825,7 +825,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
825
825
  version: str,
826
826
  base_url: str | URL,
827
827
  max_retries: int = DEFAULT_MAX_RETRIES,
828
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
828
+ timeout: float | Timeout | None | NotGiven = not_given,
829
829
  http_client: httpx.Client | None = None,
830
830
  custom_headers: Mapping[str, str] | None = None,
831
831
  custom_query: Mapping[str, object] | None = None,
@@ -1356,7 +1356,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1356
1356
  base_url: str | URL,
1357
1357
  _strict_response_validation: bool,
1358
1358
  max_retries: int = DEFAULT_MAX_RETRIES,
1359
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
1359
+ timeout: float | Timeout | None | NotGiven = not_given,
1360
1360
  http_client: httpx.AsyncClient | None = None,
1361
1361
  custom_headers: Mapping[str, str] | None = None,
1362
1362
  custom_query: Mapping[str, object] | None = None,
@@ -1822,8 +1822,8 @@ def make_request_options(
1822
1822
  extra_query: Query | None = None,
1823
1823
  extra_body: Body | None = None,
1824
1824
  idempotency_key: str | None = None,
1825
- timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1826
- post_parser: PostParser | NotGiven = NOT_GIVEN,
1825
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
1826
+ post_parser: PostParser | NotGiven = not_given,
1827
1827
  ) -> RequestOptions:
1828
1828
  """Create a dict of type RequestOptions without keys of NotGiven values."""
1829
1829
  options: RequestOptions = {}
spitch/_client.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import os
6
- from typing import Any, Union, Mapping
6
+ from typing import Any, Mapping
7
7
  from typing_extensions import Self, override
8
8
 
9
9
  import httpx
@@ -11,16 +11,17 @@ import httpx
11
11
  from . import resources, _exceptions
12
12
  from ._qs import Querystring
13
13
  from ._types import (
14
- NOT_GIVEN,
15
14
  Omit,
16
15
  Timeout,
17
16
  NotGiven,
18
17
  Transport,
19
18
  ProxiesTypes,
20
19
  RequestOptions,
20
+ not_given,
21
21
  )
22
22
  from ._utils import is_given, get_async_library
23
23
  from ._version import __version__
24
+ from .resources import text, files, speech
24
25
  from ._streaming import Stream as Stream, AsyncStream as AsyncStream
25
26
  from ._exceptions import SpitchError, APIStatusError
26
27
  from ._base_client import (
@@ -43,8 +44,9 @@ __all__ = [
43
44
 
44
45
 
45
46
  class Spitch(SyncAPIClient):
46
- speech: resources.SpeechResource
47
- text: resources.TextResource
47
+ speech: speech.SpeechResource
48
+ text: text.TextResource
49
+ files: files.FilesResource
48
50
  with_raw_response: SpitchWithRawResponse
49
51
  with_streaming_response: SpitchWithStreamedResponse
50
52
 
@@ -56,7 +58,7 @@ class Spitch(SyncAPIClient):
56
58
  *,
57
59
  api_key: str | None = None,
58
60
  base_url: str | httpx.URL | None = None,
59
- timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
61
+ timeout: float | Timeout | None | NotGiven = not_given,
60
62
  max_retries: int = DEFAULT_MAX_RETRIES,
61
63
  default_headers: Mapping[str, str] | None = None,
62
64
  default_query: Mapping[str, object] | None = None,
@@ -102,8 +104,9 @@ class Spitch(SyncAPIClient):
102
104
  _strict_response_validation=_strict_response_validation,
103
105
  )
104
106
 
105
- self.speech = resources.SpeechResource(self)
106
- self.text = resources.TextResource(self)
107
+ self.speech = speech.SpeechResource(self)
108
+ self.text = text.TextResource(self)
109
+ self.files = files.FilesResource(self)
107
110
  self.with_raw_response = SpitchWithRawResponse(self)
108
111
  self.with_streaming_response = SpitchWithStreamedResponse(self)
109
112
 
@@ -132,9 +135,9 @@ class Spitch(SyncAPIClient):
132
135
  *,
133
136
  api_key: str | None = None,
134
137
  base_url: str | httpx.URL | None = None,
135
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
138
+ timeout: float | Timeout | None | NotGiven = not_given,
136
139
  http_client: httpx.Client | None = None,
137
- max_retries: int | NotGiven = NOT_GIVEN,
140
+ max_retries: int | NotGiven = not_given,
138
141
  default_headers: Mapping[str, str] | None = None,
139
142
  set_default_headers: Mapping[str, str] | None = None,
140
143
  default_query: Mapping[str, object] | None = None,
@@ -213,8 +216,9 @@ class Spitch(SyncAPIClient):
213
216
 
214
217
 
215
218
  class AsyncSpitch(AsyncAPIClient):
216
- speech: resources.AsyncSpeechResource
217
- text: resources.AsyncTextResource
219
+ speech: speech.AsyncSpeechResource
220
+ text: text.AsyncTextResource
221
+ files: files.AsyncFilesResource
218
222
  with_raw_response: AsyncSpitchWithRawResponse
219
223
  with_streaming_response: AsyncSpitchWithStreamedResponse
220
224
 
@@ -226,7 +230,7 @@ class AsyncSpitch(AsyncAPIClient):
226
230
  *,
227
231
  api_key: str | None = None,
228
232
  base_url: str | httpx.URL | None = None,
229
- timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
233
+ timeout: float | Timeout | None | NotGiven = not_given,
230
234
  max_retries: int = DEFAULT_MAX_RETRIES,
231
235
  default_headers: Mapping[str, str] | None = None,
232
236
  default_query: Mapping[str, object] | None = None,
@@ -272,8 +276,9 @@ class AsyncSpitch(AsyncAPIClient):
272
276
  _strict_response_validation=_strict_response_validation,
273
277
  )
274
278
 
275
- self.speech = resources.AsyncSpeechResource(self)
276
- self.text = resources.AsyncTextResource(self)
279
+ self.speech = speech.AsyncSpeechResource(self)
280
+ self.text = text.AsyncTextResource(self)
281
+ self.files = files.AsyncFilesResource(self)
277
282
  self.with_raw_response = AsyncSpitchWithRawResponse(self)
278
283
  self.with_streaming_response = AsyncSpitchWithStreamedResponse(self)
279
284
 
@@ -302,9 +307,9 @@ class AsyncSpitch(AsyncAPIClient):
302
307
  *,
303
308
  api_key: str | None = None,
304
309
  base_url: str | httpx.URL | None = None,
305
- timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
310
+ timeout: float | Timeout | None | NotGiven = not_given,
306
311
  http_client: httpx.AsyncClient | None = None,
307
- max_retries: int | NotGiven = NOT_GIVEN,
312
+ max_retries: int | NotGiven = not_given,
308
313
  default_headers: Mapping[str, str] | None = None,
309
314
  set_default_headers: Mapping[str, str] | None = None,
310
315
  default_query: Mapping[str, object] | None = None,
@@ -384,26 +389,30 @@ class AsyncSpitch(AsyncAPIClient):
384
389
 
385
390
  class SpitchWithRawResponse:
386
391
  def __init__(self, client: Spitch) -> None:
387
- self.speech = resources.SpeechResourceWithRawResponse(client.speech)
388
- self.text = resources.TextResourceWithRawResponse(client.text)
392
+ self.speech = speech.SpeechResourceWithRawResponse(client.speech)
393
+ self.text = text.TextResourceWithRawResponse(client.text)
394
+ self.files = files.FilesResourceWithRawResponse(client.files)
389
395
 
390
396
 
391
397
  class AsyncSpitchWithRawResponse:
392
398
  def __init__(self, client: AsyncSpitch) -> None:
393
- self.speech = resources.AsyncSpeechResourceWithRawResponse(client.speech)
394
- self.text = resources.AsyncTextResourceWithRawResponse(client.text)
399
+ self.speech = speech.AsyncSpeechResourceWithRawResponse(client.speech)
400
+ self.text = text.AsyncTextResourceWithRawResponse(client.text)
401
+ self.files = files.AsyncFilesResourceWithRawResponse(client.files)
395
402
 
396
403
 
397
404
  class SpitchWithStreamedResponse:
398
405
  def __init__(self, client: Spitch) -> None:
399
- self.speech = resources.SpeechResourceWithStreamingResponse(client.speech)
400
- self.text = resources.TextResourceWithStreamingResponse(client.text)
406
+ self.speech = speech.SpeechResourceWithStreamingResponse(client.speech)
407
+ self.text = text.TextResourceWithStreamingResponse(client.text)
408
+ self.files = files.FilesResourceWithStreamingResponse(client.files)
401
409
 
402
410
 
403
411
  class AsyncSpitchWithStreamedResponse:
404
412
  def __init__(self, client: AsyncSpitch) -> None:
405
- self.speech = resources.AsyncSpeechResourceWithStreamingResponse(client.speech)
406
- self.text = resources.AsyncTextResourceWithStreamingResponse(client.text)
413
+ self.speech = speech.AsyncSpeechResourceWithStreamingResponse(client.speech)
414
+ self.text = text.AsyncTextResourceWithStreamingResponse(client.text)
415
+ self.files = files.AsyncFilesResourceWithStreamingResponse(client.files)
407
416
 
408
417
 
409
418
  Client = Spitch
spitch/_compat.py CHANGED
@@ -12,14 +12,13 @@ from ._types import IncEx, StrBytesIntFloat
12
12
  _T = TypeVar("_T")
13
13
  _ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
14
14
 
15
- # --------------- Pydantic v2 compatibility ---------------
15
+ # --------------- Pydantic v2, v3 compatibility ---------------
16
16
 
17
17
  # Pyright incorrectly reports some of our functions as overriding a method when they don't
18
18
  # pyright: reportIncompatibleMethodOverride=false
19
19
 
20
- PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
20
+ PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
21
21
 
22
- # v1 re-exports
23
22
  if TYPE_CHECKING:
24
23
 
25
24
  def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
@@ -44,90 +43,92 @@ if TYPE_CHECKING:
44
43
  ...
45
44
 
46
45
  else:
47
- if PYDANTIC_V2:
48
- from pydantic.v1.typing import (
46
+ # v1 re-exports
47
+ if PYDANTIC_V1:
48
+ from pydantic.typing import (
49
49
  get_args as get_args,
50
50
  is_union as is_union,
51
51
  get_origin as get_origin,
52
52
  is_typeddict as is_typeddict,
53
53
  is_literal_type as is_literal_type,
54
54
  )
55
- from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
55
+ from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
56
56
  else:
57
- from pydantic.typing import (
57
+ from ._utils import (
58
58
  get_args as get_args,
59
59
  is_union as is_union,
60
60
  get_origin as get_origin,
61
+ parse_date as parse_date,
61
62
  is_typeddict as is_typeddict,
63
+ parse_datetime as parse_datetime,
62
64
  is_literal_type as is_literal_type,
63
65
  )
64
- from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
65
66
 
66
67
 
67
68
  # refactored config
68
69
  if TYPE_CHECKING:
69
70
  from pydantic import ConfigDict as ConfigDict
70
71
  else:
71
- if PYDANTIC_V2:
72
- from pydantic import ConfigDict
73
- else:
72
+ if PYDANTIC_V1:
74
73
  # TODO: provide an error message here?
75
74
  ConfigDict = None
75
+ else:
76
+ from pydantic import ConfigDict as ConfigDict
76
77
 
77
78
 
78
79
  # renamed methods / properties
79
80
  def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
80
- if PYDANTIC_V2:
81
- return model.model_validate(value)
82
- else:
81
+ if PYDANTIC_V1:
83
82
  return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
83
+ else:
84
+ return model.model_validate(value)
84
85
 
85
86
 
86
87
  def field_is_required(field: FieldInfo) -> bool:
87
- if PYDANTIC_V2:
88
- return field.is_required()
89
- return field.required # type: ignore
88
+ if PYDANTIC_V1:
89
+ return field.required # type: ignore
90
+ return field.is_required()
90
91
 
91
92
 
92
93
  def field_get_default(field: FieldInfo) -> Any:
93
94
  value = field.get_default()
94
- if PYDANTIC_V2:
95
- from pydantic_core import PydanticUndefined
96
-
97
- if value == PydanticUndefined:
98
- return None
95
+ if PYDANTIC_V1:
99
96
  return value
97
+ from pydantic_core import PydanticUndefined
98
+
99
+ if value == PydanticUndefined:
100
+ return None
100
101
  return value
101
102
 
102
103
 
103
104
  def field_outer_type(field: FieldInfo) -> Any:
104
- if PYDANTIC_V2:
105
- return field.annotation
106
- return field.outer_type_ # type: ignore
105
+ if PYDANTIC_V1:
106
+ return field.outer_type_ # type: ignore
107
+ return field.annotation
107
108
 
108
109
 
109
110
  def get_model_config(model: type[pydantic.BaseModel]) -> Any:
110
- if PYDANTIC_V2:
111
- return model.model_config
112
- return model.__config__ # type: ignore
111
+ if PYDANTIC_V1:
112
+ return model.__config__ # type: ignore
113
+ return model.model_config
113
114
 
114
115
 
115
116
  def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
116
- if PYDANTIC_V2:
117
- return model.model_fields
118
- return model.__fields__ # type: ignore
117
+ if PYDANTIC_V1:
118
+ return model.__fields__ # type: ignore
119
+ return model.model_fields
119
120
 
120
121
 
121
122
  def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
122
- if PYDANTIC_V2:
123
- return model.model_copy(deep=deep)
124
- return model.copy(deep=deep) # type: ignore
123
+ if PYDANTIC_V1:
124
+ return model.copy(deep=deep) # type: ignore
125
+ return model.model_copy(deep=deep)
125
126
 
126
127
 
127
128
  def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
128
- if PYDANTIC_V2:
129
- return model.model_dump_json(indent=indent)
130
- return model.json(indent=indent) # type: ignore
129
+ if PYDANTIC_V1:
130
+ return model.json(indent=indent) # type: ignore
131
+ return model.model_dump_json(indent=indent)
131
132
 
132
133
 
133
134
  def model_dump(
@@ -139,7 +140,7 @@ def model_dump(
139
140
  warnings: bool = True,
140
141
  mode: Literal["json", "python"] = "python",
141
142
  ) -> dict[str, Any]:
142
- if PYDANTIC_V2 or hasattr(model, "model_dump"):
143
+ if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
143
144
  return model.model_dump(
144
145
  mode=mode,
145
146
  exclude=exclude,
@@ -158,9 +159,9 @@ def model_dump(
158
159
 
159
160
 
160
161
  def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
161
- if PYDANTIC_V2:
162
- return model.model_validate(data)
163
- return model.parse_obj(data) # pyright: ignore[reportDeprecated]
162
+ if PYDANTIC_V1:
163
+ return model.parse_obj(data) # pyright: ignore[reportDeprecated]
164
+ return model.model_validate(data)
164
165
 
165
166
 
166
167
  # generic models
@@ -169,17 +170,16 @@ if TYPE_CHECKING:
169
170
  class GenericModel(pydantic.BaseModel): ...
170
171
 
171
172
  else:
172
- if PYDANTIC_V2:
173
+ if PYDANTIC_V1:
174
+ import pydantic.generics
175
+
176
+ class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
177
+ else:
173
178
  # there no longer needs to be a distinction in v2 but
174
179
  # we still have to create our own subclass to avoid
175
180
  # inconsistent MRO ordering errors
176
181
  class GenericModel(pydantic.BaseModel): ...
177
182
 
178
- else:
179
- import pydantic.generics
180
-
181
- class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
182
-
183
183
 
184
184
  # cached properties
185
185
  if TYPE_CHECKING: