sarvamai 0.1.5a5__tar.gz → 0.1.5a6__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 (143) hide show
  1. sarvamai-0.1.5a6/PKG-INFO +174 -0
  2. sarvamai-0.1.5a6/README.md +147 -0
  3. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/pyproject.toml +4 -25
  4. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/__init__.py +1 -45
  5. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/chat/__init__.py +0 -2
  6. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/chat/client.py +10 -9
  7. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/chat/raw_client.py +37 -48
  8. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/client.py +31 -13
  9. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/__init__.py +0 -5
  10. sarvamai-0.1.5a6/src/sarvamai/core/api_error.py +15 -0
  11. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/client_wrapper.py +20 -17
  12. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/http_client.py +24 -70
  13. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/http_response.py +11 -19
  14. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/pydantic_utilities.py +108 -69
  15. sarvamai-0.1.5a6/src/sarvamai/environment.py +7 -0
  16. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/errors/__init__.py +0 -2
  17. sarvamai-0.1.5a6/src/sarvamai/errors/bad_request_error.py +9 -0
  18. sarvamai-0.1.5a6/src/sarvamai/errors/forbidden_error.py +9 -0
  19. sarvamai-0.1.5a6/src/sarvamai/errors/internal_server_error.py +9 -0
  20. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/errors/service_unavailable_error.py +2 -4
  21. sarvamai-0.1.5a6/src/sarvamai/errors/too_many_requests_error.py +9 -0
  22. sarvamai-0.1.5a6/src/sarvamai/errors/unprocessable_entity_error.py +9 -0
  23. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/__init__.py +0 -18
  24. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/chat_completion_request_message.py +1 -3
  25. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/create_chat_completion_response.py +2 -2
  26. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/diarized_transcript.py +1 -2
  27. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/error_details.py +1 -0
  28. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/language_identification_response.py +1 -0
  29. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/speech_to_text_response.py +2 -1
  30. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/speech_to_text_translate_response.py +1 -0
  31. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/text_to_speech_response.py +2 -2
  32. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/timestamps_model.py +1 -2
  33. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/translation_response.py +1 -0
  34. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/transliteration_response.py +1 -0
  35. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/speech_to_text/__init__.py +0 -2
  36. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/speech_to_text/client.py +14 -13
  37. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/speech_to_text/raw_client.py +68 -99
  38. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text/__init__.py +0 -2
  39. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text/client.py +25 -24
  40. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text/raw_client.py +91 -126
  41. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text_to_speech/__init__.py +0 -2
  42. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text_to_speech/client.py +11 -10
  43. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/text_to_speech/raw_client.py +38 -49
  44. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/__init__.py +0 -24
  45. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/chat_completion_request_assistant_message.py +3 -3
  46. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/chat_completion_request_message.py +2 -3
  47. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/chat_completion_request_system_message.py +3 -3
  48. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/chat_completion_request_user_message.py +3 -3
  49. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/chat_completion_response_message.py +3 -3
  50. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/choice.py +4 -4
  51. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/completion_usage.py +3 -3
  52. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/create_chat_completion_response.py +3 -3
  53. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/diarized_entry.py +3 -3
  54. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/diarized_transcript.py +3 -3
  55. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/error_details.py +3 -3
  56. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/error_message.py +4 -4
  57. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/language_identification_response.py +2 -2
  58. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_response.py +3 -3
  59. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_translate_response.py +3 -3
  60. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/text_to_speech_response.py +2 -2
  61. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/timestamps_model.py +2 -2
  62. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translation_response.py +2 -2
  63. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/transliteration_response.py +2 -2
  64. sarvamai-0.1.5a5/PKG-INFO +0 -28
  65. sarvamai-0.1.5a5/README.md +0 -0
  66. sarvamai-0.1.5a5/src/sarvamai/core/api_error.py +0 -23
  67. sarvamai-0.1.5a5/src/sarvamai/core/events.py +0 -30
  68. sarvamai-0.1.5a5/src/sarvamai/core/force_multipart.py +0 -16
  69. sarvamai-0.1.5a5/src/sarvamai/environment.py +0 -14
  70. sarvamai-0.1.5a5/src/sarvamai/errors/bad_request_error.py +0 -10
  71. sarvamai-0.1.5a5/src/sarvamai/errors/forbidden_error.py +0 -10
  72. sarvamai-0.1.5a5/src/sarvamai/errors/internal_server_error.py +0 -10
  73. sarvamai-0.1.5a5/src/sarvamai/errors/too_many_requests_error.py +0 -10
  74. sarvamai-0.1.5a5/src/sarvamai/errors/unprocessable_entity_error.py +0 -10
  75. sarvamai-0.1.5a5/src/sarvamai/requests/audio_data.py +0 -21
  76. sarvamai-0.1.5a5/src/sarvamai/requests/audio_message.py +0 -8
  77. sarvamai-0.1.5a5/src/sarvamai/requests/error_data.py +0 -15
  78. sarvamai-0.1.5a5/src/sarvamai/requests/events_data.py +0 -17
  79. sarvamai-0.1.5a5/src/sarvamai/requests/speech_to_text_streaming_response.py +0 -10
  80. sarvamai-0.1.5a5/src/sarvamai/requests/speech_to_text_streaming_response_data.py +0 -9
  81. sarvamai-0.1.5a5/src/sarvamai/requests/transcription_data.py +0 -35
  82. sarvamai-0.1.5a5/src/sarvamai/requests/transcription_metrics.py +0 -15
  83. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/__init__.py +0 -7
  84. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/client.py +0 -189
  85. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/raw_client.py +0 -166
  86. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/socket_client.py +0 -129
  87. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/types/__init__.py +0 -8
  88. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_language_code.py +0 -8
  89. sarvamai-0.1.5a5/src/sarvamai/speech_to_text_streaming/types/speech_to_text_streaming_model.py +0 -5
  90. sarvamai-0.1.5a5/src/sarvamai/types/audio_data.py +0 -33
  91. sarvamai-0.1.5a5/src/sarvamai/types/audio_data_encoding.py +0 -5
  92. sarvamai-0.1.5a5/src/sarvamai/types/audio_message.py +0 -20
  93. sarvamai-0.1.5a5/src/sarvamai/types/error_data.py +0 -27
  94. sarvamai-0.1.5a5/src/sarvamai/types/events_data.py +0 -28
  95. sarvamai-0.1.5a5/src/sarvamai/types/format.py +0 -5
  96. sarvamai-0.1.5a5/src/sarvamai/types/speech_to_text_streaming_response.py +0 -22
  97. sarvamai-0.1.5a5/src/sarvamai/types/speech_to_text_streaming_response_data.py +0 -9
  98. sarvamai-0.1.5a5/src/sarvamai/types/speech_to_text_streaming_response_type.py +0 -5
  99. sarvamai-0.1.5a5/src/sarvamai/types/transcription_data.py +0 -45
  100. sarvamai-0.1.5a5/src/sarvamai/types/transcription_metrics.py +0 -27
  101. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/datetime_utils.py +0 -0
  102. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/file.py +0 -0
  103. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/jsonable_encoder.py +0 -0
  104. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/query_encoder.py +0 -0
  105. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/remove_none_from_dict.py +0 -0
  106. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/request_options.py +0 -0
  107. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/core/serialization.py +0 -0
  108. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/play.py +0 -0
  109. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/py.typed +0 -0
  110. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/chat_completion_request_assistant_message.py +0 -0
  111. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/chat_completion_request_system_message.py +0 -0
  112. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/chat_completion_request_user_message.py +0 -0
  113. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/chat_completion_response_message.py +0 -0
  114. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/choice.py +0 -0
  115. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/completion_usage.py +0 -0
  116. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/diarized_entry.py +0 -0
  117. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/error_message.py +0 -0
  118. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/requests/stop_configuration.py +0 -0
  119. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/error_code.py +0 -0
  120. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/finish_reason.py +0 -0
  121. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/numerals_format.py +0 -0
  122. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/reasoning_effort.py +0 -0
  123. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/role.py +0 -0
  124. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/sarvam_model_ids.py +0 -0
  125. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_sample_rate.py +0 -0
  126. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_language.py +0 -0
  127. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_model.py +0 -0
  128. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_translate_language.py +0 -0
  129. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/speech_to_text_translate_model.py +0 -0
  130. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/spoken_form_numerals_format.py +0 -0
  131. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/stop_configuration.py +0 -0
  132. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/text_to_speech_language.py +0 -0
  133. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/text_to_speech_model.py +0 -0
  134. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/text_to_speech_speaker.py +0 -0
  135. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translate_mode.py +0 -0
  136. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translate_model.py +0 -0
  137. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translate_source_language.py +0 -0
  138. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translate_speaker_gender.py +0 -0
  139. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translate_target_language.py +0 -0
  140. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/translatiterate_target_language.py +0 -0
  141. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/transliterate_mode.py +0 -0
  142. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/types/transliterate_source_language.py +0 -0
  143. {sarvamai-0.1.5a5 → sarvamai-0.1.5a6}/src/sarvamai/version.py +0 -0
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.1
2
+ Name: sarvamai
3
+ Version: 0.1.5a6
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: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: httpx (>=0.21.2)
22
+ Requires-Dist: pydantic (>=1.9.2)
23
+ Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
24
+ Requires-Dist: typing_extensions (>=4.0.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Sarvam Python Library
28
+
29
+ [![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%2Fsarvamai%2Fsarvam-python-sdk)
30
+ [![pypi](https://img.shields.io/pypi/v/sarvamai)](https://pypi.python.org/pypi/sarvamai)
31
+
32
+ The Sarvam Python library provides convenient access to the Sarvam API from Python.
33
+
34
+ ## Documentation
35
+
36
+ API reference documentation is available [here](https://www.sarvam.ai/).
37
+
38
+ ## Installation
39
+
40
+ ```sh
41
+ pip install sarvamai
42
+ ```
43
+
44
+ ## Reference
45
+
46
+ A full reference for this library is available [here](https://github.com/sarvamai/sarvam-python-sdk/blob/HEAD/./reference.md).
47
+
48
+ ## Usage
49
+
50
+ Instantiate and use the client with the following:
51
+
52
+ ```python
53
+ from sarvamai import SarvamAI
54
+
55
+ client = SarvamAI(
56
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
57
+ )
58
+ client.text.translate(
59
+ input="input",
60
+ source_language_code="auto",
61
+ target_language_code="bn-IN",
62
+ )
63
+ ```
64
+
65
+ ## Async Client
66
+
67
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
68
+
69
+ ```python
70
+ import asyncio
71
+
72
+ from sarvamai import AsyncSarvamAI
73
+
74
+ client = AsyncSarvamAI(
75
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
76
+ )
77
+
78
+
79
+ async def main() -> None:
80
+ await client.text.translate(
81
+ input="input",
82
+ source_language_code="auto",
83
+ target_language_code="bn-IN",
84
+ )
85
+
86
+
87
+ asyncio.run(main())
88
+ ```
89
+
90
+ ## Exception Handling
91
+
92
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
93
+ will be thrown.
94
+
95
+ ```python
96
+ from sarvamai.core.api_error import ApiError
97
+
98
+ try:
99
+ client.text.translate(...)
100
+ except ApiError as e:
101
+ print(e.status_code)
102
+ print(e.body)
103
+ ```
104
+
105
+ ## Advanced
106
+
107
+ ### Retries
108
+
109
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
110
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
111
+ retry limit (default: 2).
112
+
113
+ A request is deemed retryable when any of the following HTTP status codes is returned:
114
+
115
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
116
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
117
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
118
+
119
+ Use the `max_retries` request option to configure this behavior.
120
+
121
+ ```python
122
+ client.text.translate(..., request_options={
123
+ "max_retries": 1
124
+ })
125
+ ```
126
+
127
+ ### Timeouts
128
+
129
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
130
+
131
+ ```python
132
+
133
+ from sarvamai import SarvamAI
134
+
135
+ client = SarvamAI(
136
+ ...,
137
+ timeout=20.0,
138
+ )
139
+
140
+
141
+ # Override timeout for a specific method
142
+ client.text.translate(..., request_options={
143
+ "timeout_in_seconds": 1
144
+ })
145
+ ```
146
+
147
+ ### Custom Client
148
+
149
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
150
+ and transports.
151
+
152
+ ```python
153
+ import httpx
154
+ from sarvamai import SarvamAI
155
+
156
+ client = SarvamAI(
157
+ ...,
158
+ httpx_client=httpx.Client(
159
+ proxies="http://my.test.proxy.example.com",
160
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
161
+ ),
162
+ )
163
+ ```
164
+
165
+ ## Contributing
166
+
167
+ While we value open-source contributions to this SDK, this library is generated programmatically.
168
+ Additions made directly to this library would have to be moved over to our generation code,
169
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
170
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
171
+ an issue first to discuss with us!
172
+
173
+ On the other hand, contributions to the README are always very welcome!
174
+
@@ -0,0 +1,147 @@
1
+ # Sarvam 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%2Fsarvamai%2Fsarvam-python-sdk)
4
+ [![pypi](https://img.shields.io/pypi/v/sarvamai)](https://pypi.python.org/pypi/sarvamai)
5
+
6
+ The Sarvam Python library provides convenient access to the Sarvam API from Python.
7
+
8
+ ## Documentation
9
+
10
+ API reference documentation is available [here](https://www.sarvam.ai/).
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install sarvamai
16
+ ```
17
+
18
+ ## Reference
19
+
20
+ A full reference for this library is available [here](https://github.com/sarvamai/sarvam-python-sdk/blob/HEAD/./reference.md).
21
+
22
+ ## Usage
23
+
24
+ Instantiate and use the client with the following:
25
+
26
+ ```python
27
+ from sarvamai import SarvamAI
28
+
29
+ client = SarvamAI(
30
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
31
+ )
32
+ client.text.translate(
33
+ input="input",
34
+ source_language_code="auto",
35
+ target_language_code="bn-IN",
36
+ )
37
+ ```
38
+
39
+ ## Async Client
40
+
41
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
42
+
43
+ ```python
44
+ import asyncio
45
+
46
+ from sarvamai import AsyncSarvamAI
47
+
48
+ client = AsyncSarvamAI(
49
+ api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
50
+ )
51
+
52
+
53
+ async def main() -> None:
54
+ await client.text.translate(
55
+ input="input",
56
+ source_language_code="auto",
57
+ target_language_code="bn-IN",
58
+ )
59
+
60
+
61
+ asyncio.run(main())
62
+ ```
63
+
64
+ ## Exception Handling
65
+
66
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
67
+ will be thrown.
68
+
69
+ ```python
70
+ from sarvamai.core.api_error import ApiError
71
+
72
+ try:
73
+ client.text.translate(...)
74
+ except ApiError as e:
75
+ print(e.status_code)
76
+ print(e.body)
77
+ ```
78
+
79
+ ## Advanced
80
+
81
+ ### Retries
82
+
83
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
84
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
85
+ retry limit (default: 2).
86
+
87
+ A request is deemed retryable when any of the following HTTP status codes is returned:
88
+
89
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
90
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
91
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
92
+
93
+ Use the `max_retries` request option to configure this behavior.
94
+
95
+ ```python
96
+ client.text.translate(..., request_options={
97
+ "max_retries": 1
98
+ })
99
+ ```
100
+
101
+ ### Timeouts
102
+
103
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
104
+
105
+ ```python
106
+
107
+ from sarvamai import SarvamAI
108
+
109
+ client = SarvamAI(
110
+ ...,
111
+ timeout=20.0,
112
+ )
113
+
114
+
115
+ # Override timeout for a specific method
116
+ client.text.translate(..., request_options={
117
+ "timeout_in_seconds": 1
118
+ })
119
+ ```
120
+
121
+ ### Custom Client
122
+
123
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
124
+ and transports.
125
+
126
+ ```python
127
+ import httpx
128
+ from sarvamai import SarvamAI
129
+
130
+ client = SarvamAI(
131
+ ...,
132
+ httpx_client=httpx.Client(
133
+ proxies="http://my.test.proxy.example.com",
134
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
135
+ ),
136
+ )
137
+ ```
138
+
139
+ ## Contributing
140
+
141
+ While we value open-source contributions to this SDK, this library is generated programmatically.
142
+ Additions made directly to this library would have to be moved over to our generation code,
143
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
144
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
145
+ an issue first to discuss with us!
146
+
147
+ On the other hand, contributions to the README are always very welcome!
@@ -3,7 +3,7 @@ name = "sarvamai"
3
3
 
4
4
  [tool.poetry]
5
5
  name = "sarvamai"
6
- version = "0.1.5a5"
6
+ version = "0.1.5a6"
7
7
  description = ""
8
8
  readme = "README.md"
9
9
  authors = []
@@ -39,15 +39,14 @@ httpx = ">=0.21.2"
39
39
  pydantic = ">= 1.9.2"
40
40
  pydantic-core = "^2.18.2"
41
41
  typing_extensions = ">= 4.0.0"
42
- websockets = "12.0"
43
42
 
44
- [tool.poetry.group.dev.dependencies]
45
- mypy = "==1.13.0"
43
+ [tool.poetry.dev-dependencies]
44
+ mypy = "1.0.1"
46
45
  pytest = "^7.4.0"
47
46
  pytest-asyncio = "^0.23.5"
48
47
  python-dateutil = "^2.9.0"
49
48
  types-python-dateutil = "^2.9.0.20240316"
50
- ruff = "==0.11.5"
49
+ ruff = "^0.5.6"
51
50
 
52
51
  [tool.pytest.ini_options]
53
52
  testpaths = [ "tests" ]
@@ -59,26 +58,6 @@ plugins = ["pydantic.mypy"]
59
58
  [tool.ruff]
60
59
  line-length = 120
61
60
 
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
61
 
83
62
  [build-system]
84
63
  requires = ["poetry-core"]
@@ -1,11 +1,6 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- # isort: skip_file
4
-
5
3
  from .types import (
6
- AudioData,
7
- AudioDataEncoding,
8
- AudioMessage,
9
4
  ChatCompletionRequestAssistantMessage,
10
5
  ChatCompletionRequestMessage,
11
6
  ChatCompletionRequestMessage_Assistant,
@@ -20,12 +15,9 @@ from .types import (
20
15
  DiarizedEntry,
21
16
  DiarizedTranscript,
22
17
  ErrorCode,
23
- ErrorData,
24
18
  ErrorDetails,
25
19
  ErrorMessage,
26
- EventsData,
27
20
  FinishReason,
28
- Format,
29
21
  LanguageIdentificationResponse,
30
22
  NumeralsFormat,
31
23
  ReasoningEffort,
@@ -35,9 +27,6 @@ from .types import (
35
27
  SpeechToTextLanguage,
36
28
  SpeechToTextModel,
37
29
  SpeechToTextResponse,
38
- SpeechToTextStreamingResponse,
39
- SpeechToTextStreamingResponseData,
40
- SpeechToTextStreamingResponseType,
41
30
  SpeechToTextTranslateLanguage,
42
31
  SpeechToTextTranslateModel,
43
32
  SpeechToTextTranslateResponse,
@@ -48,8 +37,6 @@ from .types import (
48
37
  TextToSpeechResponse,
49
38
  TextToSpeechSpeaker,
50
39
  TimestampsModel,
51
- TranscriptionData,
52
- TranscriptionMetrics,
53
40
  TranslateMode,
54
41
  TranslateModel,
55
42
  TranslateSourceLanguage,
@@ -69,12 +56,10 @@ from .errors import (
69
56
  TooManyRequestsError,
70
57
  UnprocessableEntityError,
71
58
  )
72
- from . import chat, speech_to_text, speech_to_text_streaming, text, text_to_speech
59
+ from . import chat, speech_to_text, text, text_to_speech
73
60
  from .client import AsyncSarvamAI, SarvamAI
74
61
  from .environment import SarvamAIEnvironment
75
62
  from .requests import (
76
- AudioDataParams,
77
- AudioMessageParams,
78
63
  ChatCompletionRequestAssistantMessageParams,
79
64
  ChatCompletionRequestMessageParams,
80
65
  ChatCompletionRequestMessage_AssistantParams,
@@ -88,33 +73,21 @@ from .requests import (
88
73
  CreateChatCompletionResponseParams,
89
74
  DiarizedEntryParams,
90
75
  DiarizedTranscriptParams,
91
- ErrorDataParams,
92
76
  ErrorDetailsParams,
93
77
  ErrorMessageParams,
94
- EventsDataParams,
95
78
  LanguageIdentificationResponseParams,
96
79
  SpeechToTextResponseParams,
97
- SpeechToTextStreamingResponseDataParams,
98
- SpeechToTextStreamingResponseParams,
99
80
  SpeechToTextTranslateResponseParams,
100
81
  StopConfigurationParams,
101
82
  TextToSpeechResponseParams,
102
83
  TimestampsModelParams,
103
- TranscriptionDataParams,
104
- TranscriptionMetricsParams,
105
84
  TranslationResponseParams,
106
85
  TransliterationResponseParams,
107
86
  )
108
- from .speech_to_text_streaming import SpeechToTextStreamingLanguageCode, SpeechToTextStreamingModel
109
87
  from .version import __version__
110
88
 
111
89
  __all__ = [
112
90
  "AsyncSarvamAI",
113
- "AudioData",
114
- "AudioDataEncoding",
115
- "AudioDataParams",
116
- "AudioMessage",
117
- "AudioMessageParams",
118
91
  "BadRequestError",
119
92
  "ChatCompletionRequestAssistantMessage",
120
93
  "ChatCompletionRequestAssistantMessageParams",
@@ -143,17 +116,12 @@ __all__ = [
143
116
  "DiarizedTranscript",
144
117
  "DiarizedTranscriptParams",
145
118
  "ErrorCode",
146
- "ErrorData",
147
- "ErrorDataParams",
148
119
  "ErrorDetails",
149
120
  "ErrorDetailsParams",
150
121
  "ErrorMessage",
151
122
  "ErrorMessageParams",
152
- "EventsData",
153
- "EventsDataParams",
154
123
  "FinishReason",
155
124
  "ForbiddenError",
156
- "Format",
157
125
  "InternalServerError",
158
126
  "LanguageIdentificationResponse",
159
127
  "LanguageIdentificationResponseParams",
@@ -169,13 +137,6 @@ __all__ = [
169
137
  "SpeechToTextModel",
170
138
  "SpeechToTextResponse",
171
139
  "SpeechToTextResponseParams",
172
- "SpeechToTextStreamingLanguageCode",
173
- "SpeechToTextStreamingModel",
174
- "SpeechToTextStreamingResponse",
175
- "SpeechToTextStreamingResponseData",
176
- "SpeechToTextStreamingResponseDataParams",
177
- "SpeechToTextStreamingResponseParams",
178
- "SpeechToTextStreamingResponseType",
179
140
  "SpeechToTextTranslateLanguage",
180
141
  "SpeechToTextTranslateModel",
181
142
  "SpeechToTextTranslateResponse",
@@ -191,10 +152,6 @@ __all__ = [
191
152
  "TimestampsModel",
192
153
  "TimestampsModelParams",
193
154
  "TooManyRequestsError",
194
- "TranscriptionData",
195
- "TranscriptionDataParams",
196
- "TranscriptionMetrics",
197
- "TranscriptionMetricsParams",
198
155
  "TranslateMode",
199
156
  "TranslateModel",
200
157
  "TranslateSourceLanguage",
@@ -211,7 +168,6 @@ __all__ = [
211
168
  "__version__",
212
169
  "chat",
213
170
  "speech_to_text",
214
- "speech_to_text_streaming",
215
171
  "text",
216
172
  "text_to_speech",
217
173
  ]
@@ -1,4 +1,2 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
- # isort: skip_file
4
-
@@ -1,14 +1,15 @@
1
1
  # This file was auto-generated by Fern from our API Definition.
2
2
 
3
3
  import typing
4
-
5
- from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6
- from ..core.request_options import RequestOptions
4
+ from ..core.client_wrapper import SyncClientWrapper
5
+ from .raw_client import RawChatClient
7
6
  from ..requests.chat_completion_request_message import ChatCompletionRequestMessageParams
7
+ from ..types.reasoning_effort import ReasoningEffort
8
8
  from ..requests.stop_configuration import StopConfigurationParams
9
+ from ..core.request_options import RequestOptions
9
10
  from ..types.create_chat_completion_response import CreateChatCompletionResponse
10
- from ..types.reasoning_effort import ReasoningEffort
11
- from .raw_client import AsyncRawChatClient, RawChatClient
11
+ from ..core.client_wrapper import AsyncClientWrapper
12
+ from .raw_client import AsyncRawChatClient
12
13
 
13
14
  # this is used as the default value for optional parameters
14
15
  OMIT = typing.cast(typing.Any, ...)
@@ -116,7 +117,7 @@ class ChatClient:
116
117
  messages=[{"content": "content", "role": "assistant"}],
117
118
  )
118
119
  """
119
- _response = self._raw_client.completions(
120
+ response = self._raw_client.completions(
120
121
  messages=messages,
121
122
  temperature=temperature,
122
123
  top_p=top_p,
@@ -131,7 +132,7 @@ class ChatClient:
131
132
  wiki_grounding=wiki_grounding,
132
133
  request_options=request_options,
133
134
  )
134
- return _response.data
135
+ return response.data
135
136
 
136
137
 
137
138
  class AsyncChatClient:
@@ -244,7 +245,7 @@ class AsyncChatClient:
244
245
 
245
246
  asyncio.run(main())
246
247
  """
247
- _response = await self._raw_client.completions(
248
+ response = await self._raw_client.completions(
248
249
  messages=messages,
249
250
  temperature=temperature,
250
251
  top_p=top_p,
@@ -259,4 +260,4 @@ class AsyncChatClient:
259
260
  wiki_grounding=wiki_grounding,
260
261
  request_options=request_options,
261
262
  )
262
- return _response.data
263
+ return response.data