tapra 0.1.1__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.
Files changed (101) hide show
  1. tapra/.fernignore +1 -0
  2. tapra/__init__.py +214 -0
  3. tapra/_default_clients.py +30 -0
  4. tapra/client.py +331 -0
  5. tapra/core/__init__.py +127 -0
  6. tapra/core/api_error.py +23 -0
  7. tapra/core/client_wrapper.py +142 -0
  8. tapra/core/datetime_utils.py +70 -0
  9. tapra/core/file.py +67 -0
  10. tapra/core/force_multipart.py +18 -0
  11. tapra/core/http_client.py +965 -0
  12. tapra/core/http_response.py +63 -0
  13. tapra/core/http_sse/__init__.py +42 -0
  14. tapra/core/http_sse/_api.py +455 -0
  15. tapra/core/http_sse/_decoders.py +74 -0
  16. tapra/core/http_sse/_exceptions.py +7 -0
  17. tapra/core/http_sse/_models.py +17 -0
  18. tapra/core/jsonable_encoder.py +133 -0
  19. tapra/core/logging.py +107 -0
  20. tapra/core/parse_error.py +36 -0
  21. tapra/core/pydantic_utilities.py +486 -0
  22. tapra/core/query_encoder.py +58 -0
  23. tapra/core/remove_none_from_dict.py +11 -0
  24. tapra/core/request_options.py +40 -0
  25. tapra/core/serialization.py +347 -0
  26. tapra/diarization/__init__.py +4 -0
  27. tapra/diarization/client.py +128 -0
  28. tapra/diarization/raw_client.py +328 -0
  29. tapra/environment.py +7 -0
  30. tapra/errors/__init__.py +59 -0
  31. tapra/errors/bad_request_error.py +11 -0
  32. tapra/errors/content_too_large_error.py +11 -0
  33. tapra/errors/forbidden_error.py +11 -0
  34. tapra/errors/internal_server_error.py +11 -0
  35. tapra/errors/payment_required_error.py +11 -0
  36. tapra/errors/service_unavailable_error.py +11 -0
  37. tapra/errors/too_many_requests_error.py +11 -0
  38. tapra/errors/unauthorized_error.py +11 -0
  39. tapra/models/__init__.py +4 -0
  40. tapra/models/client.py +96 -0
  41. tapra/models/raw_client.py +95 -0
  42. tapra/realtime.py +295 -0
  43. tapra/script/__init__.py +34 -0
  44. tapra/script/client.py +138 -0
  45. tapra/script/raw_client.py +330 -0
  46. tapra/script/types/__init__.py +34 -0
  47. tapra/script/types/conversion_request_direction.py +5 -0
  48. tapra/speech/__init__.py +49 -0
  49. tapra/speech/client.py +274 -0
  50. tapra/speech/raw_client.py +466 -0
  51. tapra/speech/types/__init__.py +47 -0
  52. tapra/speech/types/create_speech_request_engine.py +5 -0
  53. tapra/speech/types/create_speech_request_pronunciation_mode.py +5 -0
  54. tapra/speech/types/create_speech_request_pronunciation_style.py +5 -0
  55. tapra/speech/types/create_speech_request_response_format.py +5 -0
  56. tapra/transcriptions/__init__.py +34 -0
  57. tapra/transcriptions/client.py +203 -0
  58. tapra/transcriptions/raw_client.py +399 -0
  59. tapra/transcriptions/types/__init__.py +36 -0
  60. tapra/transcriptions/types/create_transcriptions_request_timestamps.py +5 -0
  61. tapra/translations/__init__.py +37 -0
  62. tapra/translations/client.py +386 -0
  63. tapra/translations/raw_client.py +875 -0
  64. tapra/translations/types/__init__.py +38 -0
  65. tapra/translations/types/create_translations_request_direction.py +5 -0
  66. tapra/translations/types/create_translations_stream_request_direction.py +5 -0
  67. tapra/types/__init__.py +128 -0
  68. tapra/types/conversion.py +26 -0
  69. tapra/types/conversion_direction.py +5 -0
  70. tapra/types/diarization.py +30 -0
  71. tapra/types/error.py +24 -0
  72. tapra/types/error_object.py +21 -0
  73. tapra/types/error_object_type.py +18 -0
  74. tapra/types/model.py +23 -0
  75. tapra/types/model_list.py +22 -0
  76. tapra/types/model_list_object.py +5 -0
  77. tapra/types/model_object.py +5 -0
  78. tapra/types/model_owned_by.py +5 -0
  79. tapra/types/realtime_client_message.py +24 -0
  80. tapra/types/realtime_client_message_type.py +5 -0
  81. tapra/types/realtime_event.py +64 -0
  82. tapra/types/realtime_event_type.py +5 -0
  83. tapra/types/segment.py +30 -0
  84. tapra/types/speaker.py +23 -0
  85. tapra/types/speaker_turn.py +21 -0
  86. tapra/types/speech.py +37 -0
  87. tapra/types/speech_audio_format.py +5 -0
  88. tapra/types/transcription.py +47 -0
  89. tapra/types/translation.py +30 -0
  90. tapra/types/translation_language.py +22 -0
  91. tapra/types/translation_language_list.py +23 -0
  92. tapra/types/translation_language_list_object.py +5 -0
  93. tapra/types/translation_request.py +41 -0
  94. tapra/types/translation_request_direction.py +5 -0
  95. tapra/types/translation_stream_event.py +26 -0
  96. tapra/types/translation_stream_event_type.py +5 -0
  97. tapra/types/usage.py +28 -0
  98. tapra/types/word.py +34 -0
  99. tapra-0.1.1.dist-info/METADATA +60 -0
  100. tapra-0.1.1.dist-info/RECORD +101 -0
  101. tapra-0.1.1.dist-info/WHEEL +4 -0
tapra/.fernignore ADDED
@@ -0,0 +1 @@
1
+ realtime.py
tapra/__init__.py ADDED
@@ -0,0 +1,214 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .types import (
10
+ Conversion,
11
+ ConversionDirection,
12
+ Diarization,
13
+ Error,
14
+ ErrorObject,
15
+ ErrorObjectType,
16
+ Model,
17
+ ModelList,
18
+ ModelListObject,
19
+ ModelObject,
20
+ ModelOwnedBy,
21
+ RealtimeClientMessage,
22
+ RealtimeClientMessageType,
23
+ RealtimeEvent,
24
+ RealtimeEventType,
25
+ Segment,
26
+ Speaker,
27
+ SpeakerTurn,
28
+ Speech,
29
+ SpeechAudioFormat,
30
+ Transcription,
31
+ Translation,
32
+ TranslationLanguage,
33
+ TranslationLanguageList,
34
+ TranslationLanguageListObject,
35
+ TranslationRequest,
36
+ TranslationRequestDirection,
37
+ TranslationStreamEvent,
38
+ TranslationStreamEventType,
39
+ Usage,
40
+ Word,
41
+ )
42
+ from .errors import (
43
+ BadRequestError,
44
+ ContentTooLargeError,
45
+ ForbiddenError,
46
+ InternalServerError,
47
+ PaymentRequiredError,
48
+ ServiceUnavailableError,
49
+ TooManyRequestsError,
50
+ UnauthorizedError,
51
+ )
52
+ from . import diarization, models, script, speech, transcriptions, translations
53
+ from ._default_clients import DefaultAioHttpClient, DefaultAsyncHttpxClient
54
+ from .client import AsyncTapra, Tapra
55
+ from .environment import TapraEnvironment
56
+ from .realtime import RealtimeError, RealtimeSession, connect_realtime
57
+ from .script import ConversionRequestDirection
58
+ from .speech import (
59
+ CreateSpeechRequestEngine,
60
+ CreateSpeechRequestPronunciationMode,
61
+ CreateSpeechRequestPronunciationStyle,
62
+ CreateSpeechRequestResponseFormat,
63
+ )
64
+ from .transcriptions import CreateTranscriptionsRequestTimestamps
65
+ from .translations import CreateTranslationsRequestDirection, CreateTranslationsStreamRequestDirection
66
+ _dynamic_imports: typing.Dict[str, str] = {
67
+ "AsyncTapra": ".client",
68
+ "BadRequestError": ".errors",
69
+ "ContentTooLargeError": ".errors",
70
+ "Conversion": ".types",
71
+ "ConversionDirection": ".types",
72
+ "ConversionRequestDirection": ".script",
73
+ "CreateSpeechRequestEngine": ".speech",
74
+ "CreateSpeechRequestPronunciationMode": ".speech",
75
+ "CreateSpeechRequestPronunciationStyle": ".speech",
76
+ "CreateSpeechRequestResponseFormat": ".speech",
77
+ "CreateTranscriptionsRequestTimestamps": ".transcriptions",
78
+ "CreateTranslationsRequestDirection": ".translations",
79
+ "CreateTranslationsStreamRequestDirection": ".translations",
80
+ "DefaultAioHttpClient": "._default_clients",
81
+ "DefaultAsyncHttpxClient": "._default_clients",
82
+ "Diarization": ".types",
83
+ "Error": ".types",
84
+ "ErrorObject": ".types",
85
+ "ErrorObjectType": ".types",
86
+ "ForbiddenError": ".errors",
87
+ "InternalServerError": ".errors",
88
+ "Model": ".types",
89
+ "ModelList": ".types",
90
+ "ModelListObject": ".types",
91
+ "ModelObject": ".types",
92
+ "ModelOwnedBy": ".types",
93
+ "PaymentRequiredError": ".errors",
94
+ "RealtimeClientMessage": ".types",
95
+ "RealtimeClientMessageType": ".types",
96
+ "RealtimeError": ".realtime",
97
+ "RealtimeEvent": ".types",
98
+ "RealtimeEventType": ".types",
99
+ "RealtimeSession": ".realtime",
100
+ "Segment": ".types",
101
+ "ServiceUnavailableError": ".errors",
102
+ "Speaker": ".types",
103
+ "SpeakerTurn": ".types",
104
+ "Speech": ".types",
105
+ "SpeechAudioFormat": ".types",
106
+ "Tapra": ".client",
107
+ "TapraEnvironment": ".environment",
108
+ "TooManyRequestsError": ".errors",
109
+ "Transcription": ".types",
110
+ "Translation": ".types",
111
+ "TranslationLanguage": ".types",
112
+ "TranslationLanguageList": ".types",
113
+ "TranslationLanguageListObject": ".types",
114
+ "TranslationRequest": ".types",
115
+ "TranslationRequestDirection": ".types",
116
+ "TranslationStreamEvent": ".types",
117
+ "TranslationStreamEventType": ".types",
118
+ "UnauthorizedError": ".errors",
119
+ "Usage": ".types",
120
+ "Word": ".types",
121
+ "connect_realtime": ".realtime",
122
+ "diarization": ".diarization",
123
+ "models": ".models",
124
+ "script": ".script",
125
+ "speech": ".speech",
126
+ "transcriptions": ".transcriptions",
127
+ "translations": ".translations",
128
+ }
129
+
130
+
131
+ def __getattr__(attr_name: str) -> typing.Any:
132
+ module_name = _dynamic_imports.get(attr_name)
133
+ if module_name is None:
134
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
135
+ try:
136
+ module = import_module(module_name, __package__)
137
+ if module_name == f".{attr_name}":
138
+ return module
139
+ else:
140
+ return getattr(module, attr_name)
141
+ except ImportError as e:
142
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
143
+ except AttributeError as e:
144
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
145
+
146
+
147
+ def __dir__():
148
+ lazy_attrs = list(_dynamic_imports.keys())
149
+ return sorted(lazy_attrs)
150
+
151
+
152
+ __all__ = [
153
+ "AsyncTapra",
154
+ "BadRequestError",
155
+ "ContentTooLargeError",
156
+ "Conversion",
157
+ "ConversionDirection",
158
+ "ConversionRequestDirection",
159
+ "CreateSpeechRequestEngine",
160
+ "CreateSpeechRequestPronunciationMode",
161
+ "CreateSpeechRequestPronunciationStyle",
162
+ "CreateSpeechRequestResponseFormat",
163
+ "CreateTranscriptionsRequestTimestamps",
164
+ "CreateTranslationsRequestDirection",
165
+ "CreateTranslationsStreamRequestDirection",
166
+ "DefaultAioHttpClient",
167
+ "DefaultAsyncHttpxClient",
168
+ "Diarization",
169
+ "Error",
170
+ "ErrorObject",
171
+ "ErrorObjectType",
172
+ "ForbiddenError",
173
+ "InternalServerError",
174
+ "Model",
175
+ "ModelList",
176
+ "ModelListObject",
177
+ "ModelObject",
178
+ "ModelOwnedBy",
179
+ "PaymentRequiredError",
180
+ "RealtimeClientMessage",
181
+ "RealtimeClientMessageType",
182
+ "RealtimeError",
183
+ "RealtimeEvent",
184
+ "RealtimeEventType",
185
+ "RealtimeSession",
186
+ "Segment",
187
+ "ServiceUnavailableError",
188
+ "Speaker",
189
+ "SpeakerTurn",
190
+ "Speech",
191
+ "SpeechAudioFormat",
192
+ "Tapra",
193
+ "TapraEnvironment",
194
+ "TooManyRequestsError",
195
+ "Transcription",
196
+ "Translation",
197
+ "TranslationLanguage",
198
+ "TranslationLanguageList",
199
+ "TranslationLanguageListObject",
200
+ "TranslationRequest",
201
+ "TranslationRequestDirection",
202
+ "TranslationStreamEvent",
203
+ "TranslationStreamEventType",
204
+ "UnauthorizedError",
205
+ "Usage",
206
+ "Word",
207
+ "connect_realtime",
208
+ "diarization",
209
+ "models",
210
+ "script",
211
+ "speech",
212
+ "transcriptions",
213
+ "translations",
214
+ ]
@@ -0,0 +1,30 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+
7
+ SDK_DEFAULT_TIMEOUT = 60
8
+
9
+ try:
10
+ import httpx_aiohttp # type: ignore[import-not-found]
11
+ except ImportError:
12
+
13
+ class DefaultAioHttpClient(httpx.AsyncClient): # type: ignore
14
+ def __init__(self, **kwargs: typing.Any) -> None:
15
+ raise RuntimeError("To use the aiohttp client, install the aiohttp extra: pip install tapra[aiohttp]")
16
+
17
+ else:
18
+
19
+ class DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
20
+ def __init__(self, **kwargs: typing.Any) -> None:
21
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
22
+ kwargs.setdefault("follow_redirects", True)
23
+ super().__init__(**kwargs)
24
+
25
+
26
+ class DefaultAsyncHttpxClient(httpx.AsyncClient):
27
+ def __init__(self, **kwargs: typing.Any) -> None:
28
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
29
+ kwargs.setdefault("follow_redirects", True)
30
+ super().__init__(**kwargs)
tapra/client.py ADDED
@@ -0,0 +1,331 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import typing
7
+
8
+ import httpx
9
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
10
+ from .core.logging import LogConfig, Logger
11
+ from .environment import TapraEnvironment
12
+
13
+ if typing.TYPE_CHECKING:
14
+ from .diarization.client import AsyncDiarizationClient, DiarizationClient
15
+ from .models.client import AsyncModelsClient, ModelsClient
16
+ from .script.client import AsyncScriptClient, ScriptClient
17
+ from .speech.client import AsyncSpeechClient, SpeechClient
18
+ from .transcriptions.client import AsyncTranscriptionsClient, TranscriptionsClient
19
+ from .translations.client import AsyncTranslationsClient, TranslationsClient
20
+
21
+
22
+ class Tapra:
23
+ """
24
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
25
+
26
+ Parameters
27
+ ----------
28
+ base_url : typing.Optional[str]
29
+ The base url to use for requests from the client.
30
+
31
+ environment : TapraEnvironment
32
+ The environment to use for requests from the client. from .environment import TapraEnvironment
33
+
34
+
35
+
36
+ Defaults to TapraEnvironment.DEFAULT
37
+
38
+
39
+
40
+ api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
41
+ headers : typing.Optional[typing.Dict[str, str]]
42
+ Additional headers to send with every request.
43
+
44
+ timeout : typing.Optional[float]
45
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
46
+
47
+ max_retries : typing.Optional[int]
48
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
49
+
50
+ stream_reconnection_enabled : typing.Optional[bool]
51
+ Whether to automatically reconnect on stream disconnection for resumable streaming endpoints. Defaults to True. Per-request `stream_reconnection_enabled` in `request_options` takes precedence over this value.
52
+
53
+ max_stream_reconnection_attempts : typing.Optional[int]
54
+ The maximum number of reconnection attempts for resumable streaming endpoints. Defaults to no limit. Per-request `max_stream_reconnection_attempts` in `request_options` takes precedence over this value.
55
+
56
+ follow_redirects : typing.Optional[bool]
57
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
58
+
59
+ httpx_client : typing.Optional[httpx.Client]
60
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
61
+
62
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
63
+ Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
64
+
65
+ Examples
66
+ --------
67
+ from tapra import Tapra
68
+
69
+ client = Tapra(
70
+ api_key="YOUR_API_KEY",
71
+ )
72
+ """
73
+
74
+ def __init__(
75
+ self,
76
+ *,
77
+ base_url: typing.Optional[str] = None,
78
+ environment: TapraEnvironment = TapraEnvironment.DEFAULT,
79
+ api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
80
+ headers: typing.Optional[typing.Dict[str, str]] = None,
81
+ timeout: typing.Optional[float] = None,
82
+ max_retries: typing.Optional[int] = None,
83
+ stream_reconnection_enabled: typing.Optional[bool] = None,
84
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
85
+ follow_redirects: typing.Optional[bool] = True,
86
+ httpx_client: typing.Optional[httpx.Client] = None,
87
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
88
+ ):
89
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
90
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
91
+ api_key = api_key if api_key is not None else os.getenv("TAPRA_API_KEY")
92
+ self._client_wrapper = SyncClientWrapper(
93
+ base_url=_get_base_url(base_url=base_url, environment=environment),
94
+ api_key=api_key,
95
+ headers=headers,
96
+ httpx_client=httpx_client
97
+ if httpx_client is not None
98
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
99
+ if follow_redirects is not None
100
+ else httpx.Client(timeout=_defaulted_timeout),
101
+ timeout=_defaulted_timeout,
102
+ max_retries=_defaulted_max_retries,
103
+ stream_reconnection_enabled=stream_reconnection_enabled,
104
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
105
+ logging=logging,
106
+ )
107
+ self._models: typing.Optional[ModelsClient] = None
108
+ self._transcriptions: typing.Optional[TranscriptionsClient] = None
109
+ self._diarization: typing.Optional[DiarizationClient] = None
110
+ self._speech: typing.Optional[SpeechClient] = None
111
+ self._translations: typing.Optional[TranslationsClient] = None
112
+ self._script: typing.Optional[ScriptClient] = None
113
+
114
+ @property
115
+ def models(self):
116
+ if self._models is None:
117
+ from .models.client import ModelsClient # noqa: E402
118
+
119
+ self._models = ModelsClient(client_wrapper=self._client_wrapper)
120
+ return self._models
121
+
122
+ @property
123
+ def transcriptions(self):
124
+ if self._transcriptions is None:
125
+ from .transcriptions.client import TranscriptionsClient # noqa: E402
126
+
127
+ self._transcriptions = TranscriptionsClient(client_wrapper=self._client_wrapper)
128
+ return self._transcriptions
129
+
130
+ @property
131
+ def diarization(self):
132
+ if self._diarization is None:
133
+ from .diarization.client import DiarizationClient # noqa: E402
134
+
135
+ self._diarization = DiarizationClient(client_wrapper=self._client_wrapper)
136
+ return self._diarization
137
+
138
+ @property
139
+ def speech(self):
140
+ if self._speech is None:
141
+ from .speech.client import SpeechClient # noqa: E402
142
+
143
+ self._speech = SpeechClient(client_wrapper=self._client_wrapper)
144
+ return self._speech
145
+
146
+ @property
147
+ def translations(self):
148
+ if self._translations is None:
149
+ from .translations.client import TranslationsClient # noqa: E402
150
+
151
+ self._translations = TranslationsClient(client_wrapper=self._client_wrapper)
152
+ return self._translations
153
+
154
+ @property
155
+ def script(self):
156
+ if self._script is None:
157
+ from .script.client import ScriptClient # noqa: E402
158
+
159
+ self._script = ScriptClient(client_wrapper=self._client_wrapper)
160
+ return self._script
161
+
162
+
163
+ def _make_default_async_client(
164
+ timeout: typing.Optional[float],
165
+ follow_redirects: typing.Optional[bool],
166
+ ) -> httpx.AsyncClient:
167
+ try:
168
+ import httpx_aiohttp # type: ignore[import-not-found]
169
+ except ImportError:
170
+ pass
171
+ else:
172
+ if follow_redirects is not None:
173
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
174
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)
175
+
176
+ if follow_redirects is not None:
177
+ return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
178
+ return httpx.AsyncClient(timeout=timeout)
179
+
180
+
181
+ class AsyncTapra:
182
+ """
183
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
184
+
185
+ Parameters
186
+ ----------
187
+ base_url : typing.Optional[str]
188
+ The base url to use for requests from the client.
189
+
190
+ environment : TapraEnvironment
191
+ The environment to use for requests from the client. from .environment import TapraEnvironment
192
+
193
+
194
+
195
+ Defaults to TapraEnvironment.DEFAULT
196
+
197
+
198
+
199
+ api_key : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
200
+ headers : typing.Optional[typing.Dict[str, str]]
201
+ Additional headers to send with every request.
202
+
203
+ async_token : typing.Optional[typing.Callable[[], typing.Awaitable[str]]]
204
+ An async callable that returns a bearer token. Use this when token acquisition involves async I/O (e.g., refreshing tokens via an async HTTP client). When provided, this is used instead of the synchronous token for async requests.
205
+
206
+ timeout : typing.Optional[float]
207
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
208
+
209
+ max_retries : typing.Optional[int]
210
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
211
+
212
+ stream_reconnection_enabled : typing.Optional[bool]
213
+ Whether to automatically reconnect on stream disconnection for resumable streaming endpoints. Defaults to True. Per-request `stream_reconnection_enabled` in `request_options` takes precedence over this value.
214
+
215
+ max_stream_reconnection_attempts : typing.Optional[int]
216
+ The maximum number of reconnection attempts for resumable streaming endpoints. Defaults to no limit. Per-request `max_stream_reconnection_attempts` in `request_options` takes precedence over this value.
217
+
218
+ follow_redirects : typing.Optional[bool]
219
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
220
+
221
+ httpx_client : typing.Optional[httpx.AsyncClient]
222
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
223
+
224
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
225
+ Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
226
+
227
+ Examples
228
+ --------
229
+ from tapra import AsyncTapra
230
+
231
+ client = AsyncTapra(
232
+ api_key="YOUR_API_KEY",
233
+ )
234
+ """
235
+
236
+ def __init__(
237
+ self,
238
+ *,
239
+ base_url: typing.Optional[str] = None,
240
+ environment: TapraEnvironment = TapraEnvironment.DEFAULT,
241
+ api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
242
+ headers: typing.Optional[typing.Dict[str, str]] = None,
243
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
244
+ timeout: typing.Optional[float] = None,
245
+ max_retries: typing.Optional[int] = None,
246
+ stream_reconnection_enabled: typing.Optional[bool] = None,
247
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
248
+ follow_redirects: typing.Optional[bool] = True,
249
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
250
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
251
+ ):
252
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
253
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
254
+ api_key = api_key if api_key is not None else os.getenv("TAPRA_API_KEY")
255
+ self._client_wrapper = AsyncClientWrapper(
256
+ base_url=_get_base_url(base_url=base_url, environment=environment),
257
+ api_key=api_key,
258
+ headers=headers,
259
+ async_token=async_token,
260
+ httpx_client=httpx_client
261
+ if httpx_client is not None
262
+ else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
263
+ timeout=_defaulted_timeout,
264
+ max_retries=_defaulted_max_retries,
265
+ stream_reconnection_enabled=stream_reconnection_enabled,
266
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
267
+ logging=logging,
268
+ )
269
+ self._models: typing.Optional[AsyncModelsClient] = None
270
+ self._transcriptions: typing.Optional[AsyncTranscriptionsClient] = None
271
+ self._diarization: typing.Optional[AsyncDiarizationClient] = None
272
+ self._speech: typing.Optional[AsyncSpeechClient] = None
273
+ self._translations: typing.Optional[AsyncTranslationsClient] = None
274
+ self._script: typing.Optional[AsyncScriptClient] = None
275
+
276
+ @property
277
+ def models(self):
278
+ if self._models is None:
279
+ from .models.client import AsyncModelsClient # noqa: E402
280
+
281
+ self._models = AsyncModelsClient(client_wrapper=self._client_wrapper)
282
+ return self._models
283
+
284
+ @property
285
+ def transcriptions(self):
286
+ if self._transcriptions is None:
287
+ from .transcriptions.client import AsyncTranscriptionsClient # noqa: E402
288
+
289
+ self._transcriptions = AsyncTranscriptionsClient(client_wrapper=self._client_wrapper)
290
+ return self._transcriptions
291
+
292
+ @property
293
+ def diarization(self):
294
+ if self._diarization is None:
295
+ from .diarization.client import AsyncDiarizationClient # noqa: E402
296
+
297
+ self._diarization = AsyncDiarizationClient(client_wrapper=self._client_wrapper)
298
+ return self._diarization
299
+
300
+ @property
301
+ def speech(self):
302
+ if self._speech is None:
303
+ from .speech.client import AsyncSpeechClient # noqa: E402
304
+
305
+ self._speech = AsyncSpeechClient(client_wrapper=self._client_wrapper)
306
+ return self._speech
307
+
308
+ @property
309
+ def translations(self):
310
+ if self._translations is None:
311
+ from .translations.client import AsyncTranslationsClient # noqa: E402
312
+
313
+ self._translations = AsyncTranslationsClient(client_wrapper=self._client_wrapper)
314
+ return self._translations
315
+
316
+ @property
317
+ def script(self):
318
+ if self._script is None:
319
+ from .script.client import AsyncScriptClient # noqa: E402
320
+
321
+ self._script = AsyncScriptClient(client_wrapper=self._client_wrapper)
322
+ return self._script
323
+
324
+
325
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: TapraEnvironment) -> str:
326
+ if base_url is not None:
327
+ return base_url
328
+ elif environment is not None:
329
+ return environment.value
330
+ else:
331
+ raise Exception("Please pass in either base_url or environment to construct the client")