mirascope 2.0.0a2__py3-none-any.whl → 2.0.0a4__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 (252) hide show
  1. mirascope/__init__.py +2 -2
  2. mirascope/api/__init__.py +6 -0
  3. mirascope/api/_generated/README.md +207 -0
  4. mirascope/api/_generated/__init__.py +141 -0
  5. mirascope/api/_generated/client.py +163 -0
  6. mirascope/api/_generated/core/__init__.py +52 -0
  7. mirascope/api/_generated/core/api_error.py +23 -0
  8. mirascope/api/_generated/core/client_wrapper.py +58 -0
  9. mirascope/api/_generated/core/datetime_utils.py +30 -0
  10. mirascope/api/_generated/core/file.py +70 -0
  11. mirascope/api/_generated/core/force_multipart.py +16 -0
  12. mirascope/api/_generated/core/http_client.py +619 -0
  13. mirascope/api/_generated/core/http_response.py +55 -0
  14. mirascope/api/_generated/core/jsonable_encoder.py +102 -0
  15. mirascope/api/_generated/core/pydantic_utilities.py +310 -0
  16. mirascope/api/_generated/core/query_encoder.py +60 -0
  17. mirascope/api/_generated/core/remove_none_from_dict.py +11 -0
  18. mirascope/api/_generated/core/request_options.py +35 -0
  19. mirascope/api/_generated/core/serialization.py +282 -0
  20. mirascope/api/_generated/docs/__init__.py +4 -0
  21. mirascope/api/_generated/docs/client.py +95 -0
  22. mirascope/api/_generated/docs/raw_client.py +132 -0
  23. mirascope/api/_generated/environment.py +9 -0
  24. mirascope/api/_generated/errors/__init__.py +17 -0
  25. mirascope/api/_generated/errors/bad_request_error.py +15 -0
  26. mirascope/api/_generated/errors/conflict_error.py +15 -0
  27. mirascope/api/_generated/errors/forbidden_error.py +15 -0
  28. mirascope/api/_generated/errors/internal_server_error.py +15 -0
  29. mirascope/api/_generated/errors/not_found_error.py +15 -0
  30. mirascope/api/_generated/health/__init__.py +7 -0
  31. mirascope/api/_generated/health/client.py +96 -0
  32. mirascope/api/_generated/health/raw_client.py +129 -0
  33. mirascope/api/_generated/health/types/__init__.py +8 -0
  34. mirascope/api/_generated/health/types/health_check_response.py +24 -0
  35. mirascope/api/_generated/health/types/health_check_response_status.py +5 -0
  36. mirascope/api/_generated/organizations/__init__.py +25 -0
  37. mirascope/api/_generated/organizations/client.py +380 -0
  38. mirascope/api/_generated/organizations/raw_client.py +876 -0
  39. mirascope/api/_generated/organizations/types/__init__.py +23 -0
  40. mirascope/api/_generated/organizations/types/organizations_create_response.py +24 -0
  41. mirascope/api/_generated/organizations/types/organizations_create_response_role.py +7 -0
  42. mirascope/api/_generated/organizations/types/organizations_get_response.py +24 -0
  43. mirascope/api/_generated/organizations/types/organizations_get_response_role.py +7 -0
  44. mirascope/api/_generated/organizations/types/organizations_list_response_item.py +24 -0
  45. mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +7 -0
  46. mirascope/api/_generated/organizations/types/organizations_update_response.py +24 -0
  47. mirascope/api/_generated/organizations/types/organizations_update_response_role.py +7 -0
  48. mirascope/api/_generated/projects/__init__.py +17 -0
  49. mirascope/api/_generated/projects/client.py +458 -0
  50. mirascope/api/_generated/projects/raw_client.py +1016 -0
  51. mirascope/api/_generated/projects/types/__init__.py +15 -0
  52. mirascope/api/_generated/projects/types/projects_create_response.py +30 -0
  53. mirascope/api/_generated/projects/types/projects_get_response.py +30 -0
  54. mirascope/api/_generated/projects/types/projects_list_response_item.py +30 -0
  55. mirascope/api/_generated/projects/types/projects_update_response.py +30 -0
  56. mirascope/api/_generated/reference.md +753 -0
  57. mirascope/api/_generated/traces/__init__.py +55 -0
  58. mirascope/api/_generated/traces/client.py +162 -0
  59. mirascope/api/_generated/traces/raw_client.py +168 -0
  60. mirascope/api/_generated/traces/types/__init__.py +95 -0
  61. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +36 -0
  62. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +31 -0
  63. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +25 -0
  64. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +54 -0
  65. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +23 -0
  66. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +28 -0
  67. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +24 -0
  68. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +35 -0
  69. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +35 -0
  70. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +27 -0
  71. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +54 -0
  72. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +23 -0
  73. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +28 -0
  74. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +24 -0
  75. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +60 -0
  76. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +29 -0
  77. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +54 -0
  78. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +23 -0
  79. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +28 -0
  80. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +24 -0
  81. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +24 -0
  82. mirascope/api/_generated/traces/types/traces_create_response.py +27 -0
  83. mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +28 -0
  84. mirascope/api/_generated/types/__init__.py +37 -0
  85. mirascope/api/_generated/types/already_exists_error.py +24 -0
  86. mirascope/api/_generated/types/already_exists_error_tag.py +5 -0
  87. mirascope/api/_generated/types/database_error.py +24 -0
  88. mirascope/api/_generated/types/database_error_tag.py +5 -0
  89. mirascope/api/_generated/types/http_api_decode_error.py +29 -0
  90. mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
  91. mirascope/api/_generated/types/issue.py +40 -0
  92. mirascope/api/_generated/types/issue_tag.py +17 -0
  93. mirascope/api/_generated/types/not_found_error_body.py +24 -0
  94. mirascope/api/_generated/types/not_found_error_tag.py +5 -0
  95. mirascope/api/_generated/types/permission_denied_error.py +24 -0
  96. mirascope/api/_generated/types/permission_denied_error_tag.py +7 -0
  97. mirascope/api/_generated/types/property_key.py +7 -0
  98. mirascope/api/_generated/types/property_key_key.py +27 -0
  99. mirascope/api/_generated/types/property_key_key_tag.py +5 -0
  100. mirascope/api/client.py +255 -0
  101. mirascope/api/settings.py +81 -0
  102. mirascope/llm/__init__.py +45 -11
  103. mirascope/llm/calls/calls.py +81 -57
  104. mirascope/llm/calls/decorator.py +121 -115
  105. mirascope/llm/content/__init__.py +3 -2
  106. mirascope/llm/context/_utils.py +19 -6
  107. mirascope/llm/exceptions.py +30 -16
  108. mirascope/llm/formatting/_utils.py +9 -5
  109. mirascope/llm/formatting/format.py +2 -2
  110. mirascope/llm/formatting/from_call_args.py +2 -2
  111. mirascope/llm/messages/message.py +13 -5
  112. mirascope/llm/models/__init__.py +2 -2
  113. mirascope/llm/models/models.py +189 -81
  114. mirascope/llm/prompts/__init__.py +13 -12
  115. mirascope/llm/prompts/_utils.py +27 -24
  116. mirascope/llm/prompts/decorator.py +133 -204
  117. mirascope/llm/prompts/prompts.py +424 -0
  118. mirascope/llm/prompts/protocols.py +25 -59
  119. mirascope/llm/providers/__init__.py +44 -0
  120. mirascope/llm/{clients → providers}/_missing_import_stubs.py +8 -6
  121. mirascope/llm/providers/anthropic/__init__.py +29 -0
  122. mirascope/llm/providers/anthropic/_utils/__init__.py +23 -0
  123. mirascope/llm/providers/anthropic/_utils/beta_decode.py +271 -0
  124. mirascope/llm/providers/anthropic/_utils/beta_encode.py +216 -0
  125. mirascope/llm/{clients → providers}/anthropic/_utils/decode.py +44 -11
  126. mirascope/llm/providers/anthropic/_utils/encode.py +356 -0
  127. mirascope/llm/providers/anthropic/beta_provider.py +322 -0
  128. mirascope/llm/providers/anthropic/model_id.py +23 -0
  129. mirascope/llm/providers/anthropic/model_info.py +87 -0
  130. mirascope/llm/providers/anthropic/provider.py +416 -0
  131. mirascope/llm/{clients → providers}/base/__init__.py +3 -3
  132. mirascope/llm/{clients → providers}/base/_utils.py +25 -8
  133. mirascope/llm/{clients/base/client.py → providers/base/base_provider.py} +255 -126
  134. mirascope/llm/providers/google/__init__.py +21 -0
  135. mirascope/llm/{clients → providers}/google/_utils/decode.py +61 -7
  136. mirascope/llm/{clients → providers}/google/_utils/encode.py +44 -30
  137. mirascope/llm/providers/google/model_id.py +22 -0
  138. mirascope/llm/providers/google/model_info.py +62 -0
  139. mirascope/llm/providers/google/provider.py +442 -0
  140. mirascope/llm/providers/load_provider.py +54 -0
  141. mirascope/llm/providers/mlx/__init__.py +24 -0
  142. mirascope/llm/providers/mlx/_utils.py +129 -0
  143. mirascope/llm/providers/mlx/encoding/__init__.py +8 -0
  144. mirascope/llm/providers/mlx/encoding/base.py +69 -0
  145. mirascope/llm/providers/mlx/encoding/transformers.py +147 -0
  146. mirascope/llm/providers/mlx/mlx.py +237 -0
  147. mirascope/llm/providers/mlx/model_id.py +17 -0
  148. mirascope/llm/providers/mlx/provider.py +415 -0
  149. mirascope/llm/providers/model_id.py +16 -0
  150. mirascope/llm/providers/ollama/__init__.py +19 -0
  151. mirascope/llm/providers/ollama/provider.py +71 -0
  152. mirascope/llm/providers/openai/__init__.py +6 -0
  153. mirascope/llm/providers/openai/completions/__init__.py +25 -0
  154. mirascope/llm/{clients → providers}/openai/completions/_utils/__init__.py +2 -0
  155. mirascope/llm/{clients → providers}/openai/completions/_utils/decode.py +60 -6
  156. mirascope/llm/{clients → providers}/openai/completions/_utils/encode.py +37 -26
  157. mirascope/llm/providers/openai/completions/base_provider.py +513 -0
  158. mirascope/llm/providers/openai/completions/provider.py +22 -0
  159. mirascope/llm/providers/openai/model_id.py +31 -0
  160. mirascope/llm/providers/openai/model_info.py +303 -0
  161. mirascope/llm/providers/openai/provider.py +398 -0
  162. mirascope/llm/providers/openai/responses/__init__.py +21 -0
  163. mirascope/llm/{clients → providers}/openai/responses/_utils/decode.py +59 -6
  164. mirascope/llm/{clients → providers}/openai/responses/_utils/encode.py +34 -23
  165. mirascope/llm/providers/openai/responses/provider.py +469 -0
  166. mirascope/llm/providers/provider_id.py +23 -0
  167. mirascope/llm/providers/provider_registry.py +169 -0
  168. mirascope/llm/providers/together/__init__.py +19 -0
  169. mirascope/llm/providers/together/provider.py +40 -0
  170. mirascope/llm/responses/__init__.py +3 -0
  171. mirascope/llm/responses/base_response.py +14 -5
  172. mirascope/llm/responses/base_stream_response.py +35 -6
  173. mirascope/llm/responses/finish_reason.py +1 -0
  174. mirascope/llm/responses/response.py +33 -13
  175. mirascope/llm/responses/root_response.py +12 -13
  176. mirascope/llm/responses/stream_response.py +35 -23
  177. mirascope/llm/responses/usage.py +95 -0
  178. mirascope/llm/tools/__init__.py +9 -2
  179. mirascope/llm/tools/_utils.py +12 -3
  180. mirascope/llm/tools/protocols.py +4 -4
  181. mirascope/llm/tools/tool_schema.py +44 -9
  182. mirascope/llm/tools/tools.py +10 -9
  183. mirascope/ops/__init__.py +156 -0
  184. mirascope/ops/_internal/__init__.py +5 -0
  185. mirascope/ops/_internal/closure.py +1118 -0
  186. mirascope/ops/_internal/configuration.py +126 -0
  187. mirascope/ops/_internal/context.py +76 -0
  188. mirascope/ops/_internal/exporters/__init__.py +26 -0
  189. mirascope/ops/_internal/exporters/exporters.py +342 -0
  190. mirascope/ops/_internal/exporters/processors.py +104 -0
  191. mirascope/ops/_internal/exporters/types.py +165 -0
  192. mirascope/ops/_internal/exporters/utils.py +29 -0
  193. mirascope/ops/_internal/instrumentation/__init__.py +8 -0
  194. mirascope/ops/_internal/instrumentation/llm/__init__.py +8 -0
  195. mirascope/ops/_internal/instrumentation/llm/encode.py +238 -0
  196. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +38 -0
  197. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +31 -0
  198. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +38 -0
  199. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +18 -0
  200. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +100 -0
  201. mirascope/ops/_internal/instrumentation/llm/llm.py +1288 -0
  202. mirascope/ops/_internal/propagation.py +198 -0
  203. mirascope/ops/_internal/protocols.py +51 -0
  204. mirascope/ops/_internal/session.py +139 -0
  205. mirascope/ops/_internal/spans.py +232 -0
  206. mirascope/ops/_internal/traced_calls.py +371 -0
  207. mirascope/ops/_internal/traced_functions.py +394 -0
  208. mirascope/ops/_internal/tracing.py +276 -0
  209. mirascope/ops/_internal/types.py +13 -0
  210. mirascope/ops/_internal/utils.py +75 -0
  211. mirascope/ops/_internal/versioned_calls.py +512 -0
  212. mirascope/ops/_internal/versioned_functions.py +346 -0
  213. mirascope/ops/_internal/versioning.py +303 -0
  214. mirascope/ops/exceptions.py +21 -0
  215. {mirascope-2.0.0a2.dist-info → mirascope-2.0.0a4.dist-info}/METADATA +78 -3
  216. mirascope-2.0.0a4.dist-info/RECORD +247 -0
  217. {mirascope-2.0.0a2.dist-info → mirascope-2.0.0a4.dist-info}/WHEEL +1 -1
  218. mirascope/graphs/__init__.py +0 -22
  219. mirascope/graphs/finite_state_machine.py +0 -625
  220. mirascope/llm/agents/__init__.py +0 -15
  221. mirascope/llm/agents/agent.py +0 -97
  222. mirascope/llm/agents/agent_template.py +0 -45
  223. mirascope/llm/agents/decorator.py +0 -176
  224. mirascope/llm/calls/base_call.py +0 -33
  225. mirascope/llm/clients/__init__.py +0 -34
  226. mirascope/llm/clients/anthropic/__init__.py +0 -25
  227. mirascope/llm/clients/anthropic/_utils/encode.py +0 -243
  228. mirascope/llm/clients/anthropic/clients.py +0 -819
  229. mirascope/llm/clients/anthropic/model_ids.py +0 -8
  230. mirascope/llm/clients/google/__init__.py +0 -20
  231. mirascope/llm/clients/google/clients.py +0 -853
  232. mirascope/llm/clients/google/model_ids.py +0 -15
  233. mirascope/llm/clients/openai/__init__.py +0 -25
  234. mirascope/llm/clients/openai/completions/__init__.py +0 -28
  235. mirascope/llm/clients/openai/completions/_utils/model_features.py +0 -81
  236. mirascope/llm/clients/openai/completions/clients.py +0 -833
  237. mirascope/llm/clients/openai/completions/model_ids.py +0 -8
  238. mirascope/llm/clients/openai/responses/__init__.py +0 -26
  239. mirascope/llm/clients/openai/responses/_utils/__init__.py +0 -13
  240. mirascope/llm/clients/openai/responses/_utils/model_features.py +0 -87
  241. mirascope/llm/clients/openai/responses/clients.py +0 -832
  242. mirascope/llm/clients/openai/responses/model_ids.py +0 -8
  243. mirascope/llm/clients/openai/shared/__init__.py +0 -7
  244. mirascope/llm/clients/openai/shared/_utils.py +0 -55
  245. mirascope/llm/clients/providers.py +0 -175
  246. mirascope-2.0.0a2.dist-info/RECORD +0 -102
  247. /mirascope/llm/{clients → providers}/base/kwargs.py +0 -0
  248. /mirascope/llm/{clients → providers}/base/params.py +0 -0
  249. /mirascope/llm/{clients/anthropic → providers/google}/_utils/__init__.py +0 -0
  250. /mirascope/llm/{clients → providers}/google/message.py +0 -0
  251. /mirascope/llm/{clients/google → providers/openai/responses}/_utils/__init__.py +0 -0
  252. {mirascope-2.0.0a2.dist-info → mirascope-2.0.0a4.dist-info}/licenses/LICENSE +0 -0
mirascope/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  """Mirascope v2 Beta."""
2
2
 
3
- from . import graphs as graphs, llm as llm
3
+ from . import api as api, llm as llm, ops as ops
4
4
 
5
- __all__ = ["graphs", "llm"]
5
+ __all__ = ["api", "llm", "ops"]
@@ -0,0 +1,6 @@
1
+ """The Mirascope Cloud API client."""
2
+
3
+ from .client import AsyncMirascope, Mirascope
4
+ from .settings import get_settings, settings
5
+
6
+ __all__ = ["AsyncMirascope", "Mirascope", "get_settings", "settings"]
@@ -0,0 +1,207 @@
1
+ # Mirascope 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=Mirascope%2FPython)
4
+ [![pypi](https://img.shields.io/pypi/v/mirascope)](https://pypi.python.org/pypi/mirascope)
5
+
6
+ The Mirascope Python library provides convenient access to the Mirascope APIs from Python.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Reference](#reference)
12
+ - [Usage](#usage)
13
+ - [Async Client](#async-client)
14
+ - [Exception Handling](#exception-handling)
15
+ - [Advanced](#advanced)
16
+ - [Access Raw Response Data](#access-raw-response-data)
17
+ - [Retries](#retries)
18
+ - [Timeouts](#timeouts)
19
+ - [Custom Client](#custom-client)
20
+ - [Contributing](#contributing)
21
+
22
+ ## Installation
23
+
24
+ ```sh
25
+ pip install mirascope
26
+ ```
27
+
28
+ ## Reference
29
+
30
+ A full reference for this library is available [here](./reference.md).
31
+
32
+ ## Usage
33
+
34
+ Instantiate and use the client with the following:
35
+
36
+ ```python
37
+ from mirascope.api._generated import Mirascope
38
+ from mirascope.api._generated.traces import (
39
+ TracesCreateRequestResourceSpansItem,
40
+ TracesCreateRequestResourceSpansItemScopeSpansItem,
41
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem,
42
+ )
43
+
44
+ client = Mirascope()
45
+ client.traces.create(
46
+ resource_spans=[
47
+ TracesCreateRequestResourceSpansItem(
48
+ scope_spans=[
49
+ TracesCreateRequestResourceSpansItemScopeSpansItem(
50
+ spans=[
51
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem(
52
+ trace_id="traceId",
53
+ span_id="spanId",
54
+ name="name",
55
+ start_time_unix_nano="startTimeUnixNano",
56
+ end_time_unix_nano="endTimeUnixNano",
57
+ )
58
+ ],
59
+ )
60
+ ],
61
+ )
62
+ ],
63
+ )
64
+ ```
65
+
66
+ ## Async Client
67
+
68
+ The SDK also exports an `async` client so that you can make non-blocking calls to our API.
69
+
70
+ ```python
71
+ import asyncio
72
+
73
+ from mirascope.api._generated import AsyncMirascope
74
+ from mirascope.api._generated.traces import (
75
+ TracesCreateRequestResourceSpansItem,
76
+ TracesCreateRequestResourceSpansItemScopeSpansItem,
77
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem,
78
+ )
79
+
80
+ client = AsyncMirascope()
81
+
82
+
83
+ async def main() -> None:
84
+ await client.traces.create(
85
+ resource_spans=[
86
+ TracesCreateRequestResourceSpansItem(
87
+ scope_spans=[
88
+ TracesCreateRequestResourceSpansItemScopeSpansItem(
89
+ spans=[
90
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem(
91
+ trace_id="traceId",
92
+ span_id="spanId",
93
+ name="name",
94
+ start_time_unix_nano="startTimeUnixNano",
95
+ end_time_unix_nano="endTimeUnixNano",
96
+ )
97
+ ],
98
+ )
99
+ ],
100
+ )
101
+ ],
102
+ )
103
+
104
+
105
+ asyncio.run(main())
106
+ ```
107
+
108
+ ## Exception Handling
109
+
110
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
111
+ will be thrown.
112
+
113
+ ```python
114
+ from mirascope.api._generated.core.api_error import ApiError
115
+
116
+ try:
117
+ client.traces.create(...)
118
+ except ApiError as e:
119
+ print(e.status_code)
120
+ print(e.body)
121
+ ```
122
+
123
+ ## Advanced
124
+
125
+ ### Access Raw Response Data
126
+
127
+ The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
128
+ The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
129
+
130
+ ```python
131
+ from mirascope.api._generated import Mirascope
132
+
133
+ client = Mirascope(
134
+ ...,
135
+ )
136
+ response = client.traces.with_raw_response.create(...)
137
+ print(response.headers) # access the response headers
138
+ print(response.data) # access the underlying object
139
+ ```
140
+
141
+ ### Retries
142
+
143
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
144
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
145
+ retry limit (default: 2).
146
+
147
+ A request is deemed retryable when any of the following HTTP status codes is returned:
148
+
149
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
150
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
151
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
152
+
153
+ Use the `max_retries` request option to configure this behavior.
154
+
155
+ ```python
156
+ client.traces.create(..., request_options={
157
+ "max_retries": 1
158
+ })
159
+ ```
160
+
161
+ ### Timeouts
162
+
163
+ The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
164
+
165
+ ```python
166
+
167
+ from mirascope.api._generated import Mirascope
168
+
169
+ client = Mirascope(
170
+ ...,
171
+ timeout=20.0,
172
+ )
173
+
174
+
175
+ # Override timeout for a specific method
176
+ client.traces.create(..., request_options={
177
+ "timeout_in_seconds": 1
178
+ })
179
+ ```
180
+
181
+ ### Custom Client
182
+
183
+ You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
184
+ and transports.
185
+
186
+ ```python
187
+ import httpx
188
+ from mirascope.api._generated import Mirascope
189
+
190
+ client = Mirascope(
191
+ ...,
192
+ httpx_client=httpx.Client(
193
+ proxies="http://my.test.proxy.example.com",
194
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
195
+ ),
196
+ )
197
+ ```
198
+
199
+ ## Contributing
200
+
201
+ While we value open-source contributions to this SDK, this library is generated programmatically.
202
+ Additions made directly to this library would have to be moved over to our generation code,
203
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
204
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
205
+ an issue first to discuss with us!
206
+
207
+ On the other hand, contributions to the README are always very welcome!
@@ -0,0 +1,141 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .types import (
6
+ AlreadyExistsError,
7
+ AlreadyExistsErrorTag,
8
+ DatabaseError,
9
+ DatabaseErrorTag,
10
+ HttpApiDecodeError,
11
+ HttpApiDecodeErrorTag,
12
+ Issue,
13
+ IssueTag,
14
+ NotFoundErrorBody,
15
+ NotFoundErrorTag,
16
+ PermissionDeniedError,
17
+ PermissionDeniedErrorTag,
18
+ PropertyKey,
19
+ PropertyKeyKey,
20
+ PropertyKeyKeyTag,
21
+ )
22
+ from .errors import (
23
+ BadRequestError,
24
+ ConflictError,
25
+ ForbiddenError,
26
+ InternalServerError,
27
+ NotFoundError,
28
+ )
29
+ from . import docs, health, organizations, projects, traces
30
+ from .client import AsyncMirascope, Mirascope
31
+ from .environment import MirascopeEnvironment
32
+ from .health import HealthCheckResponse, HealthCheckResponseStatus
33
+ from .organizations import (
34
+ OrganizationsCreateResponse,
35
+ OrganizationsCreateResponseRole,
36
+ OrganizationsGetResponse,
37
+ OrganizationsGetResponseRole,
38
+ OrganizationsListResponseItem,
39
+ OrganizationsListResponseItemRole,
40
+ OrganizationsUpdateResponse,
41
+ OrganizationsUpdateResponseRole,
42
+ )
43
+ from .projects import (
44
+ ProjectsCreateResponse,
45
+ ProjectsGetResponse,
46
+ ProjectsListResponseItem,
47
+ ProjectsUpdateResponse,
48
+ )
49
+ from .traces import (
50
+ TracesCreateRequestResourceSpansItem,
51
+ TracesCreateRequestResourceSpansItemResource,
52
+ TracesCreateRequestResourceSpansItemResourceAttributesItem,
53
+ TracesCreateRequestResourceSpansItemResourceAttributesItemValue,
54
+ TracesCreateRequestResourceSpansItemResourceAttributesItemValueArrayValue,
55
+ TracesCreateRequestResourceSpansItemResourceAttributesItemValueKvlistValue,
56
+ TracesCreateRequestResourceSpansItemResourceAttributesItemValueKvlistValueValuesItem,
57
+ TracesCreateRequestResourceSpansItemScopeSpansItem,
58
+ TracesCreateRequestResourceSpansItemScopeSpansItemScope,
59
+ TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItem,
60
+ TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValue,
61
+ TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueArrayValue,
62
+ TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueKvlistValue,
63
+ TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueKvlistValueValuesItem,
64
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem,
65
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItem,
66
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValue,
67
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueArrayValue,
68
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueKvlistValue,
69
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueKvlistValueValuesItem,
70
+ TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemStatus,
71
+ TracesCreateResponse,
72
+ TracesCreateResponsePartialSuccess,
73
+ )
74
+
75
+ __all__ = [
76
+ "AlreadyExistsError",
77
+ "AlreadyExistsErrorTag",
78
+ "AsyncMirascope",
79
+ "BadRequestError",
80
+ "ConflictError",
81
+ "DatabaseError",
82
+ "DatabaseErrorTag",
83
+ "ForbiddenError",
84
+ "HealthCheckResponse",
85
+ "HealthCheckResponseStatus",
86
+ "HttpApiDecodeError",
87
+ "HttpApiDecodeErrorTag",
88
+ "InternalServerError",
89
+ "Issue",
90
+ "IssueTag",
91
+ "Mirascope",
92
+ "MirascopeEnvironment",
93
+ "NotFoundError",
94
+ "NotFoundErrorBody",
95
+ "NotFoundErrorTag",
96
+ "OrganizationsCreateResponse",
97
+ "OrganizationsCreateResponseRole",
98
+ "OrganizationsGetResponse",
99
+ "OrganizationsGetResponseRole",
100
+ "OrganizationsListResponseItem",
101
+ "OrganizationsListResponseItemRole",
102
+ "OrganizationsUpdateResponse",
103
+ "OrganizationsUpdateResponseRole",
104
+ "PermissionDeniedError",
105
+ "PermissionDeniedErrorTag",
106
+ "ProjectsCreateResponse",
107
+ "ProjectsGetResponse",
108
+ "ProjectsListResponseItem",
109
+ "ProjectsUpdateResponse",
110
+ "PropertyKey",
111
+ "PropertyKeyKey",
112
+ "PropertyKeyKeyTag",
113
+ "TracesCreateRequestResourceSpansItem",
114
+ "TracesCreateRequestResourceSpansItemResource",
115
+ "TracesCreateRequestResourceSpansItemResourceAttributesItem",
116
+ "TracesCreateRequestResourceSpansItemResourceAttributesItemValue",
117
+ "TracesCreateRequestResourceSpansItemResourceAttributesItemValueArrayValue",
118
+ "TracesCreateRequestResourceSpansItemResourceAttributesItemValueKvlistValue",
119
+ "TracesCreateRequestResourceSpansItemResourceAttributesItemValueKvlistValueValuesItem",
120
+ "TracesCreateRequestResourceSpansItemScopeSpansItem",
121
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScope",
122
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItem",
123
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValue",
124
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueArrayValue",
125
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueKvlistValue",
126
+ "TracesCreateRequestResourceSpansItemScopeSpansItemScopeAttributesItemValueKvlistValueValuesItem",
127
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItem",
128
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItem",
129
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValue",
130
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueArrayValue",
131
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueKvlistValue",
132
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemAttributesItemValueKvlistValueValuesItem",
133
+ "TracesCreateRequestResourceSpansItemScopeSpansItemSpansItemStatus",
134
+ "TracesCreateResponse",
135
+ "TracesCreateResponsePartialSuccess",
136
+ "docs",
137
+ "health",
138
+ "organizations",
139
+ "projects",
140
+ "traces",
141
+ ]
@@ -0,0 +1,163 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
7
+ from .docs.client import AsyncDocsClient, DocsClient
8
+ from .environment import MirascopeEnvironment
9
+ from .health.client import AsyncHealthClient, HealthClient
10
+ from .organizations.client import AsyncOrganizationsClient, OrganizationsClient
11
+ from .projects.client import AsyncProjectsClient, ProjectsClient
12
+ from .traces.client import AsyncTracesClient, TracesClient
13
+
14
+
15
+ class Mirascope:
16
+ """
17
+ 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.
18
+
19
+ Parameters
20
+ ----------
21
+ base_url : typing.Optional[str]
22
+ The base url to use for requests from the client.
23
+
24
+ environment : MirascopeEnvironment
25
+ The environment to use for requests from the client. from .environment import MirascopeEnvironment
26
+
27
+
28
+
29
+ Defaults to MirascopeEnvironment.PRODUCTION
30
+
31
+
32
+
33
+ timeout : typing.Optional[float]
34
+ The timeout to be used, in seconds, for requests. By default the timeout is 180 seconds, unless a custom httpx client is used, in which case this default is not enforced.
35
+
36
+ follow_redirects : typing.Optional[bool]
37
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
38
+
39
+ httpx_client : typing.Optional[httpx.Client]
40
+ 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.
41
+
42
+ Examples
43
+ --------
44
+ from mirascope.api._generated import Mirascope
45
+
46
+ client = Mirascope()
47
+ """
48
+
49
+ def __init__(
50
+ self,
51
+ *,
52
+ base_url: typing.Optional[str] = None,
53
+ environment: MirascopeEnvironment = MirascopeEnvironment.PRODUCTION,
54
+ timeout: typing.Optional[float] = None,
55
+ follow_redirects: typing.Optional[bool] = True,
56
+ httpx_client: typing.Optional[httpx.Client] = None,
57
+ ):
58
+ _defaulted_timeout = (
59
+ timeout
60
+ if timeout is not None
61
+ else 180
62
+ if httpx_client is None
63
+ else httpx_client.timeout.read
64
+ )
65
+ self._client_wrapper = SyncClientWrapper(
66
+ base_url=_get_base_url(base_url=base_url, environment=environment),
67
+ httpx_client=httpx_client
68
+ if httpx_client is not None
69
+ else httpx.Client(
70
+ timeout=_defaulted_timeout, follow_redirects=follow_redirects
71
+ )
72
+ if follow_redirects is not None
73
+ else httpx.Client(timeout=_defaulted_timeout),
74
+ timeout=_defaulted_timeout,
75
+ )
76
+ self.health = HealthClient(client_wrapper=self._client_wrapper)
77
+ self.traces = TracesClient(client_wrapper=self._client_wrapper)
78
+ self.docs = DocsClient(client_wrapper=self._client_wrapper)
79
+ self.organizations = OrganizationsClient(client_wrapper=self._client_wrapper)
80
+ self.projects = ProjectsClient(client_wrapper=self._client_wrapper)
81
+
82
+
83
+ class AsyncMirascope:
84
+ """
85
+ 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.
86
+
87
+ Parameters
88
+ ----------
89
+ base_url : typing.Optional[str]
90
+ The base url to use for requests from the client.
91
+
92
+ environment : MirascopeEnvironment
93
+ The environment to use for requests from the client. from .environment import MirascopeEnvironment
94
+
95
+
96
+
97
+ Defaults to MirascopeEnvironment.PRODUCTION
98
+
99
+
100
+
101
+ timeout : typing.Optional[float]
102
+ The timeout to be used, in seconds, for requests. By default the timeout is 180 seconds, unless a custom httpx client is used, in which case this default is not enforced.
103
+
104
+ follow_redirects : typing.Optional[bool]
105
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
106
+
107
+ httpx_client : typing.Optional[httpx.AsyncClient]
108
+ 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.
109
+
110
+ Examples
111
+ --------
112
+ from mirascope.api._generated import AsyncMirascope
113
+
114
+ client = AsyncMirascope()
115
+ """
116
+
117
+ def __init__(
118
+ self,
119
+ *,
120
+ base_url: typing.Optional[str] = None,
121
+ environment: MirascopeEnvironment = MirascopeEnvironment.PRODUCTION,
122
+ timeout: typing.Optional[float] = None,
123
+ follow_redirects: typing.Optional[bool] = True,
124
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
125
+ ):
126
+ _defaulted_timeout = (
127
+ timeout
128
+ if timeout is not None
129
+ else 180
130
+ if httpx_client is None
131
+ else httpx_client.timeout.read
132
+ )
133
+ self._client_wrapper = AsyncClientWrapper(
134
+ base_url=_get_base_url(base_url=base_url, environment=environment),
135
+ httpx_client=httpx_client
136
+ if httpx_client is not None
137
+ else httpx.AsyncClient(
138
+ timeout=_defaulted_timeout, follow_redirects=follow_redirects
139
+ )
140
+ if follow_redirects is not None
141
+ else httpx.AsyncClient(timeout=_defaulted_timeout),
142
+ timeout=_defaulted_timeout,
143
+ )
144
+ self.health = AsyncHealthClient(client_wrapper=self._client_wrapper)
145
+ self.traces = AsyncTracesClient(client_wrapper=self._client_wrapper)
146
+ self.docs = AsyncDocsClient(client_wrapper=self._client_wrapper)
147
+ self.organizations = AsyncOrganizationsClient(
148
+ client_wrapper=self._client_wrapper
149
+ )
150
+ self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
151
+
152
+
153
+ def _get_base_url(
154
+ *, base_url: typing.Optional[str] = None, environment: MirascopeEnvironment
155
+ ) -> str:
156
+ if base_url is not None:
157
+ return base_url
158
+ elif environment is not None:
159
+ return environment.value
160
+ else:
161
+ raise Exception(
162
+ "Please pass in either base_url or environment to construct the client"
163
+ )
@@ -0,0 +1,52 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .api_error import ApiError
6
+ from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
7
+ from .datetime_utils import serialize_datetime
8
+ from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
9
+ from .http_client import AsyncHttpClient, HttpClient
10
+ from .http_response import AsyncHttpResponse, HttpResponse
11
+ from .jsonable_encoder import jsonable_encoder
12
+ from .pydantic_utilities import (
13
+ IS_PYDANTIC_V2,
14
+ UniversalBaseModel,
15
+ UniversalRootModel,
16
+ parse_obj_as,
17
+ universal_field_validator,
18
+ universal_root_validator,
19
+ update_forward_refs,
20
+ )
21
+ from .query_encoder import encode_query
22
+ from .remove_none_from_dict import remove_none_from_dict
23
+ from .request_options import RequestOptions
24
+ from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
25
+
26
+ __all__ = [
27
+ "ApiError",
28
+ "AsyncClientWrapper",
29
+ "AsyncHttpClient",
30
+ "AsyncHttpResponse",
31
+ "BaseClientWrapper",
32
+ "FieldMetadata",
33
+ "File",
34
+ "HttpClient",
35
+ "HttpResponse",
36
+ "IS_PYDANTIC_V2",
37
+ "RequestOptions",
38
+ "SyncClientWrapper",
39
+ "UniversalBaseModel",
40
+ "UniversalRootModel",
41
+ "convert_and_respect_annotation_metadata",
42
+ "convert_file_dict_to_httpx_tuples",
43
+ "encode_query",
44
+ "jsonable_encoder",
45
+ "parse_obj_as",
46
+ "remove_none_from_dict",
47
+ "serialize_datetime",
48
+ "universal_field_validator",
49
+ "universal_root_validator",
50
+ "update_forward_refs",
51
+ "with_content_type",
52
+ ]
@@ -0,0 +1,23 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+
6
+ class ApiError(Exception):
7
+ headers: Optional[Dict[str, str]]
8
+ status_code: Optional[int]
9
+ body: Any
10
+
11
+ def __init__(
12
+ self,
13
+ *,
14
+ headers: Optional[Dict[str, str]] = None,
15
+ status_code: Optional[int] = None,
16
+ body: Any = None,
17
+ ) -> None:
18
+ self.headers = headers
19
+ self.status_code = status_code
20
+ self.body = body
21
+
22
+ def __str__(self) -> str:
23
+ return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
@@ -0,0 +1,58 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .http_client import AsyncHttpClient, HttpClient
7
+
8
+
9
+ class BaseClientWrapper:
10
+ def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None):
11
+ self._base_url = base_url
12
+ self._timeout = timeout
13
+
14
+ def get_headers(self) -> typing.Dict[str, str]:
15
+ headers: typing.Dict[str, str] = {
16
+ "X-Fern-Language": "Python",
17
+ }
18
+ return headers
19
+
20
+ def get_base_url(self) -> str:
21
+ return self._base_url
22
+
23
+ def get_timeout(self) -> typing.Optional[float]:
24
+ return self._timeout
25
+
26
+
27
+ class SyncClientWrapper(BaseClientWrapper):
28
+ def __init__(
29
+ self,
30
+ *,
31
+ base_url: str,
32
+ timeout: typing.Optional[float] = None,
33
+ httpx_client: httpx.Client,
34
+ ):
35
+ super().__init__(base_url=base_url, timeout=timeout)
36
+ self.httpx_client = HttpClient(
37
+ httpx_client=httpx_client,
38
+ base_headers=self.get_headers,
39
+ base_timeout=self.get_timeout,
40
+ base_url=self.get_base_url,
41
+ )
42
+
43
+
44
+ class AsyncClientWrapper(BaseClientWrapper):
45
+ def __init__(
46
+ self,
47
+ *,
48
+ base_url: str,
49
+ timeout: typing.Optional[float] = None,
50
+ httpx_client: httpx.AsyncClient,
51
+ ):
52
+ super().__init__(base_url=base_url, timeout=timeout)
53
+ self.httpx_client = AsyncHttpClient(
54
+ httpx_client=httpx_client,
55
+ base_headers=self.get_headers,
56
+ base_timeout=self.get_timeout,
57
+ base_url=self.get_base_url,
58
+ )
@@ -0,0 +1,30 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import datetime as dt
4
+
5
+
6
+ def serialize_datetime(v: dt.datetime) -> str:
7
+ """
8
+ Serialize a datetime including timezone info.
9
+
10
+ Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
11
+
12
+ UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
13
+ """
14
+
15
+ def _serialize_zoned_datetime(v: dt.datetime) -> str:
16
+ if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(
17
+ None
18
+ ):
19
+ # UTC is a special case where we use "Z" at the end instead of "+00:00"
20
+ return v.isoformat().replace("+00:00", "Z")
21
+ else:
22
+ # Delegate to the typical +/- offset format
23
+ return v.isoformat()
24
+
25
+ if v.tzinfo is not None:
26
+ return _serialize_zoned_datetime(v)
27
+ else:
28
+ local_tz = dt.datetime.now().astimezone().tzinfo
29
+ localized_dt = v.replace(tzinfo=local_tz)
30
+ return _serialize_zoned_datetime(localized_dt)