levelfour 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. levelfour/__init__.py +495 -0
  2. levelfour/api_keys/__init__.py +34 -0
  3. levelfour/api_keys/client.py +337 -0
  4. levelfour/api_keys/raw_client.py +621 -0
  5. levelfour/api_keys/types/__init__.py +34 -0
  6. levelfour/api_keys/types/create_api_key_request_scope.py +5 -0
  7. levelfour/async_levelfour_client.py +39 -0
  8. levelfour/base_client.py +346 -0
  9. levelfour/client.py +54 -0
  10. levelfour/core/__init__.py +127 -0
  11. levelfour/core/api_error.py +23 -0
  12. levelfour/core/client_wrapper.py +105 -0
  13. levelfour/core/datetime_utils.py +70 -0
  14. levelfour/core/file.py +67 -0
  15. levelfour/core/force_multipart.py +18 -0
  16. levelfour/core/http_client.py +776 -0
  17. levelfour/core/http_response.py +59 -0
  18. levelfour/core/http_sse/__init__.py +42 -0
  19. levelfour/core/http_sse/_api.py +112 -0
  20. levelfour/core/http_sse/_decoders.py +61 -0
  21. levelfour/core/http_sse/_exceptions.py +7 -0
  22. levelfour/core/http_sse/_models.py +17 -0
  23. levelfour/core/jsonable_encoder.py +108 -0
  24. levelfour/core/logging.py +107 -0
  25. levelfour/core/pagination.py +82 -0
  26. levelfour/core/pydantic_utilities.py +577 -0
  27. levelfour/core/query_encoder.py +58 -0
  28. levelfour/core/remove_none_from_dict.py +11 -0
  29. levelfour/core/request_options.py +35 -0
  30. levelfour/core/serialization.py +276 -0
  31. levelfour/errors/__init__.py +40 -0
  32. levelfour/errors/forbidden_error.py +11 -0
  33. levelfour/errors/unauthorized_error.py +11 -0
  34. levelfour/errors/unprocessable_entity_error.py +11 -0
  35. levelfour/evaluation/__init__.py +4 -0
  36. levelfour/evaluation/client.py +102 -0
  37. levelfour/evaluation/raw_client.py +141 -0
  38. levelfour/exceptions.py +63 -0
  39. levelfour/health/__init__.py +4 -0
  40. levelfour/health/client.py +163 -0
  41. levelfour/health/raw_client.py +164 -0
  42. levelfour/integrations/__init__.py +0 -0
  43. levelfour/integrations/django.py +26 -0
  44. levelfour/integrations/fastapi.py +39 -0
  45. levelfour/integrations/telemetry.py +66 -0
  46. levelfour/levelfour_client.py +47 -0
  47. levelfour/pagination.py +84 -0
  48. levelfour/pr_analysis/__init__.py +4 -0
  49. levelfour/pr_analysis/client.py +408 -0
  50. levelfour/pr_analysis/raw_client.py +620 -0
  51. levelfour/pr_analysis_actions/__init__.py +4 -0
  52. levelfour/pr_analysis_actions/client.py +588 -0
  53. levelfour/pr_analysis_actions/raw_client.py +939 -0
  54. levelfour/pr_analysis_installations/__init__.py +4 -0
  55. levelfour/pr_analysis_installations/client.py +470 -0
  56. levelfour/pr_analysis_installations/raw_client.py +868 -0
  57. levelfour/providers/__init__.py +34 -0
  58. levelfour/providers/client.py +1504 -0
  59. levelfour/providers/raw_client.py +2398 -0
  60. levelfour/providers/types/__init__.py +36 -0
  61. levelfour/providers/types/list_spending_breakdown_providers_response.py +11 -0
  62. levelfour/py.typed +0 -0
  63. levelfour/recommendations/__init__.py +4 -0
  64. levelfour/recommendations/client.py +1018 -0
  65. levelfour/recommendations/raw_client.py +1810 -0
  66. levelfour/savings/__init__.py +4 -0
  67. levelfour/savings/client.py +401 -0
  68. levelfour/savings/raw_client.py +624 -0
  69. levelfour/spending/__init__.py +34 -0
  70. levelfour/spending/client.py +437 -0
  71. levelfour/spending/raw_client.py +684 -0
  72. levelfour/spending/types/__init__.py +34 -0
  73. levelfour/spending/types/list_breakdown_spending_response.py +12 -0
  74. levelfour/types/__init__.py +413 -0
  75. levelfour/types/accept_terms_data.py +25 -0
  76. levelfour/types/accept_terms_response.py +27 -0
  77. levelfour/types/action_request.py +42 -0
  78. levelfour/types/api_key_created_data.py +28 -0
  79. levelfour/types/api_key_data.py +27 -0
  80. levelfour/types/authentication_error.py +5 -0
  81. levelfour/types/authorization_error.py +5 -0
  82. levelfour/types/bad_request_error.py +5 -0
  83. levelfour/types/comparison_item.py +32 -0
  84. levelfour/types/complete_wizard_data.py +27 -0
  85. levelfour/types/complete_wizard_response.py +27 -0
  86. levelfour/types/conflict_error.py +5 -0
  87. levelfour/types/cost_breakdown_data.py +35 -0
  88. levelfour/types/cost_breakdown_item.py +71 -0
  89. levelfour/types/cost_breakdown_raw_data.py +37 -0
  90. levelfour/types/cost_breakdown_raw_response.py +27 -0
  91. levelfour/types/cost_breakdown_response.py +27 -0
  92. levelfour/types/costs_breakdown_chart_data.py +48 -0
  93. levelfour/types/costs_breakdown_chart_response.py +27 -0
  94. levelfour/types/costs_breakdown_data_point.py +46 -0
  95. levelfour/types/costs_breakdown_grouped_chart_data.py +52 -0
  96. levelfour/types/costs_breakdown_grouped_chart_response.py +27 -0
  97. levelfour/types/costs_breakdown_grouped_data_point.py +36 -0
  98. levelfour/types/costs_breakdown_totals.py +41 -0
  99. levelfour/types/create_api_key_response.py +23 -0
  100. levelfour/types/daily_spending_breakdown_data.py +42 -0
  101. levelfour/types/daily_spending_breakdown_response.py +27 -0
  102. levelfour/types/daily_spending_data_point.py +31 -0
  103. levelfour/types/dashboard_summary_data.py +72 -0
  104. levelfour/types/dashboard_summary_response.py +27 -0
  105. levelfour/types/delete_endpoint_data.py +20 -0
  106. levelfour/types/delete_endpoint_response.py +23 -0
  107. levelfour/types/endpoint_data.py +23 -0
  108. levelfour/types/error_response.py +23 -0
  109. levelfour/types/error_response_error.py +21 -0
  110. levelfour/types/evaluation_status_data.py +71 -0
  111. levelfour/types/evaluation_status_response.py +27 -0
  112. levelfour/types/execution_log_command.py +21 -0
  113. levelfour/types/execution_log_entry.py +23 -0
  114. levelfour/types/execution_step_schema.py +23 -0
  115. levelfour/types/http_validation_error.py +20 -0
  116. levelfour/types/implementation_method_data.py +25 -0
  117. levelfour/types/implementation_method_response.py +27 -0
  118. levelfour/types/implementation_step.py +27 -0
  119. levelfour/types/internal_server_error.py +5 -0
  120. levelfour/types/list_api_keys_data.py +21 -0
  121. levelfour/types/list_api_keys_response.py +23 -0
  122. levelfour/types/list_endpoints_response.py +23 -0
  123. levelfour/types/metric_data_point.py +27 -0
  124. levelfour/types/metric_series.py +40 -0
  125. levelfour/types/metric_series_entry.py +25 -0
  126. levelfour/types/monthly_spending_data.py +27 -0
  127. levelfour/types/monthly_spending_data_point.py +31 -0
  128. levelfour/types/monthly_spending_response.py +27 -0
  129. levelfour/types/not_found_error.py +5 -0
  130. levelfour/types/pagination_meta.py +51 -0
  131. levelfour/types/processing_recommendation_item.py +61 -0
  132. levelfour/types/processing_recommendations_data.py +28 -0
  133. levelfour/types/processing_recommendations_response.py +27 -0
  134. levelfour/types/provider.py +46 -0
  135. levelfour/types/provider_breakdown_data.py +31 -0
  136. levelfour/types/provider_breakdown_item.py +77 -0
  137. levelfour/types/provider_breakdown_response.py +27 -0
  138. levelfour/types/provider_filter_options_data.py +51 -0
  139. levelfour/types/provider_filter_options_response.py +27 -0
  140. levelfour/types/provider_potential_savings_summary_data.py +46 -0
  141. levelfour/types/provider_potential_savings_summary_response.py +27 -0
  142. levelfour/types/provider_recommendations_summary_data.py +37 -0
  143. levelfour/types/provider_recommendations_summary_response.py +27 -0
  144. levelfour/types/provider_saved_summary_data.py +56 -0
  145. levelfour/types/provider_saved_summary_response.py +27 -0
  146. levelfour/types/provider_service_breakdown_data.py +65 -0
  147. levelfour/types/provider_service_breakdown_item.py +72 -0
  148. levelfour/types/provider_service_breakdown_raw_data.py +62 -0
  149. levelfour/types/provider_service_breakdown_raw_response.py +27 -0
  150. levelfour/types/provider_service_breakdown_response.py +27 -0
  151. levelfour/types/provider_service_costs_breakdown_data.py +62 -0
  152. levelfour/types/provider_service_costs_breakdown_response.py +27 -0
  153. levelfour/types/provider_service_costs_data_point.py +36 -0
  154. levelfour/types/provider_spending.py +61 -0
  155. levelfour/types/provider_spending_summary_data.py +67 -0
  156. levelfour/types/provider_spending_summary_response.py +27 -0
  157. levelfour/types/provider_timeline_data.py +57 -0
  158. levelfour/types/provider_timeline_response.py +27 -0
  159. levelfour/types/provider_top_service.py +36 -0
  160. levelfour/types/providers_summary_data.py +24 -0
  161. levelfour/types/providers_summary_response.py +27 -0
  162. levelfour/types/rate_limit_error.py +5 -0
  163. levelfour/types/recommendation_actions.py +60 -0
  164. levelfour/types/recommendation_detail.py +42 -0
  165. levelfour/types/recommendation_detail_response.py +27 -0
  166. levelfour/types/recommendation_filter_options_data.py +41 -0
  167. levelfour/types/recommendation_filter_options_response.py +27 -0
  168. levelfour/types/recommendation_item.py +36 -0
  169. levelfour/types/recommendation_wizard_data.py +173 -0
  170. levelfour/types/recommendation_wizard_data_metrics.py +7 -0
  171. levelfour/types/recommendation_wizard_response.py +27 -0
  172. levelfour/types/recommendations_breakdown_data.py +26 -0
  173. levelfour/types/recommendations_breakdown_response.py +27 -0
  174. levelfour/types/recommendations_overview_data.py +51 -0
  175. levelfour/types/recommendations_overview_response.py +27 -0
  176. levelfour/types/register_endpoint_response.py +23 -0
  177. levelfour/types/resource_change.py +42 -0
  178. levelfour/types/resource_snapshot.py +21 -0
  179. levelfour/types/revoke_api_key_data.py +20 -0
  180. levelfour/types/revoke_api_key_response.py +23 -0
  181. levelfour/types/risk_assessment.py +29 -0
  182. levelfour/types/risk_factor.py +27 -0
  183. levelfour/types/saved_breakdown_data.py +31 -0
  184. levelfour/types/saved_breakdown_response.py +27 -0
  185. levelfour/types/saved_by_provider_breakdown_data.py +31 -0
  186. levelfour/types/saved_by_provider_breakdown_response.py +27 -0
  187. levelfour/types/saved_by_provider_item.py +76 -0
  188. levelfour/types/saved_item.py +35 -0
  189. levelfour/types/saved_provider_summary.py +36 -0
  190. levelfour/types/saved_summary_data.py +57 -0
  191. levelfour/types/saved_summary_response.py +27 -0
  192. levelfour/types/savings_decision_data.py +28 -0
  193. levelfour/types/savings_decision_response.py +27 -0
  194. levelfour/types/spending_by_date_item.py +36 -0
  195. levelfour/types/top_recommendation.py +56 -0
  196. levelfour/types/trigger_info.py +22 -0
  197. levelfour/types/update_tag_data.py +20 -0
  198. levelfour/types/update_tag_response.py +23 -0
  199. levelfour/types/validation_error.py +24 -0
  200. levelfour/types/validation_error_loc_item.py +5 -0
  201. levelfour/webhooks/__init__.py +4 -0
  202. levelfour/webhooks/client.py +273 -0
  203. levelfour/webhooks/raw_client.py +483 -0
  204. levelfour/webhooks/verifier.py +61 -0
  205. levelfour-0.1.0.dist-info/METADATA +12 -0
  206. levelfour-0.1.0.dist-info/RECORD +208 -0
  207. levelfour-0.1.0.dist-info/WHEEL +5 -0
  208. levelfour-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,276 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import collections
4
+ import inspect
5
+ import typing
6
+
7
+ import pydantic
8
+ import typing_extensions
9
+
10
+
11
+ class FieldMetadata:
12
+ """
13
+ Metadata class used to annotate fields to provide additional information.
14
+
15
+ Example:
16
+ class MyDict(TypedDict):
17
+ field: typing.Annotated[str, FieldMetadata(alias="field_name")]
18
+
19
+ Will serialize: `{"field": "value"}`
20
+ To: `{"field_name": "value"}`
21
+ """
22
+
23
+ alias: str
24
+
25
+ def __init__(self, *, alias: str) -> None:
26
+ self.alias = alias
27
+
28
+
29
+ def convert_and_respect_annotation_metadata(
30
+ *,
31
+ object_: typing.Any,
32
+ annotation: typing.Any,
33
+ inner_type: typing.Optional[typing.Any] = None,
34
+ direction: typing.Literal["read", "write"],
35
+ ) -> typing.Any:
36
+ """
37
+ Respect the metadata annotations on a field, such as aliasing. This function effectively
38
+ manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for
39
+ TypedDicts, which cannot support aliasing out of the box, and can be extended for additional
40
+ utilities, such as defaults.
41
+
42
+ Parameters
43
+ ----------
44
+ object_ : typing.Any
45
+
46
+ annotation : type
47
+ The type we're looking to apply typing annotations from
48
+
49
+ inner_type : typing.Optional[type]
50
+
51
+ Returns
52
+ -------
53
+ typing.Any
54
+ """
55
+
56
+ if object_ is None:
57
+ return None
58
+ if inner_type is None:
59
+ inner_type = annotation
60
+
61
+ clean_type = _remove_annotations(inner_type)
62
+ # Pydantic models
63
+ if (
64
+ inspect.isclass(clean_type)
65
+ and issubclass(clean_type, pydantic.BaseModel)
66
+ and isinstance(object_, typing.Mapping)
67
+ ):
68
+ return _convert_mapping(object_, clean_type, direction)
69
+ # TypedDicts
70
+ if typing_extensions.is_typeddict(clean_type) and isinstance(object_, typing.Mapping):
71
+ return _convert_mapping(object_, clean_type, direction)
72
+
73
+ if (
74
+ typing_extensions.get_origin(clean_type) == typing.Dict
75
+ or typing_extensions.get_origin(clean_type) == dict
76
+ or clean_type == typing.Dict
77
+ ) and isinstance(object_, typing.Dict):
78
+ key_type = typing_extensions.get_args(clean_type)[0]
79
+ value_type = typing_extensions.get_args(clean_type)[1]
80
+
81
+ return {
82
+ key: convert_and_respect_annotation_metadata(
83
+ object_=value,
84
+ annotation=annotation,
85
+ inner_type=value_type,
86
+ direction=direction,
87
+ )
88
+ for key, value in object_.items()
89
+ }
90
+
91
+ # If you're iterating on a string, do not bother to coerce it to a sequence.
92
+ if not isinstance(object_, str):
93
+ if (
94
+ typing_extensions.get_origin(clean_type) == typing.Set
95
+ or typing_extensions.get_origin(clean_type) == set
96
+ or clean_type == typing.Set
97
+ ) and isinstance(object_, typing.Set):
98
+ inner_type = typing_extensions.get_args(clean_type)[0]
99
+ return {
100
+ convert_and_respect_annotation_metadata(
101
+ object_=item,
102
+ annotation=annotation,
103
+ inner_type=inner_type,
104
+ direction=direction,
105
+ )
106
+ for item in object_
107
+ }
108
+ elif (
109
+ (
110
+ typing_extensions.get_origin(clean_type) == typing.List
111
+ or typing_extensions.get_origin(clean_type) == list
112
+ or clean_type == typing.List
113
+ )
114
+ and isinstance(object_, typing.List)
115
+ ) or (
116
+ (
117
+ typing_extensions.get_origin(clean_type) == typing.Sequence
118
+ or typing_extensions.get_origin(clean_type) == collections.abc.Sequence
119
+ or clean_type == typing.Sequence
120
+ )
121
+ and isinstance(object_, typing.Sequence)
122
+ ):
123
+ inner_type = typing_extensions.get_args(clean_type)[0]
124
+ return [
125
+ convert_and_respect_annotation_metadata(
126
+ object_=item,
127
+ annotation=annotation,
128
+ inner_type=inner_type,
129
+ direction=direction,
130
+ )
131
+ for item in object_
132
+ ]
133
+
134
+ if typing_extensions.get_origin(clean_type) == typing.Union:
135
+ # We should be able to ~relatively~ safely try to convert keys against all
136
+ # member types in the union, the edge case here is if one member aliases a field
137
+ # of the same name to a different name from another member
138
+ # Or if another member aliases a field of the same name that another member does not.
139
+ for member in typing_extensions.get_args(clean_type):
140
+ object_ = convert_and_respect_annotation_metadata(
141
+ object_=object_,
142
+ annotation=annotation,
143
+ inner_type=member,
144
+ direction=direction,
145
+ )
146
+ return object_
147
+
148
+ annotated_type = _get_annotation(annotation)
149
+ if annotated_type is None:
150
+ return object_
151
+
152
+ # If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.)
153
+ # Then we can safely call it on the recursive conversion.
154
+ return object_
155
+
156
+
157
+ def _convert_mapping(
158
+ object_: typing.Mapping[str, object],
159
+ expected_type: typing.Any,
160
+ direction: typing.Literal["read", "write"],
161
+ ) -> typing.Mapping[str, object]:
162
+ converted_object: typing.Dict[str, object] = {}
163
+ try:
164
+ annotations = typing_extensions.get_type_hints(expected_type, include_extras=True)
165
+ except NameError:
166
+ # The TypedDict contains a circular reference, so
167
+ # we use the __annotations__ attribute directly.
168
+ annotations = getattr(expected_type, "__annotations__", {})
169
+ aliases_to_field_names = _get_alias_to_field_name(annotations)
170
+ for key, value in object_.items():
171
+ if direction == "read" and key in aliases_to_field_names:
172
+ dealiased_key = aliases_to_field_names.get(key)
173
+ if dealiased_key is not None:
174
+ type_ = annotations.get(dealiased_key)
175
+ else:
176
+ type_ = annotations.get(key)
177
+ # Note you can't get the annotation by the field name if you're in read mode, so you must check the aliases map
178
+ #
179
+ # So this is effectively saying if we're in write mode, and we don't have a type, or if we're in read mode and we don't have an alias
180
+ # then we can just pass the value through as is
181
+ if type_ is None:
182
+ converted_object[key] = value
183
+ elif direction == "read" and key not in aliases_to_field_names:
184
+ converted_object[key] = convert_and_respect_annotation_metadata(
185
+ object_=value, annotation=type_, direction=direction
186
+ )
187
+ else:
188
+ converted_object[_alias_key(key, type_, direction, aliases_to_field_names)] = (
189
+ convert_and_respect_annotation_metadata(object_=value, annotation=type_, direction=direction)
190
+ )
191
+ return converted_object
192
+
193
+
194
+ def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]:
195
+ maybe_annotated_type = typing_extensions.get_origin(type_)
196
+ if maybe_annotated_type is None:
197
+ return None
198
+
199
+ if maybe_annotated_type == typing_extensions.NotRequired:
200
+ type_ = typing_extensions.get_args(type_)[0]
201
+ maybe_annotated_type = typing_extensions.get_origin(type_)
202
+
203
+ if maybe_annotated_type == typing_extensions.Annotated:
204
+ return type_
205
+
206
+ return None
207
+
208
+
209
+ def _remove_annotations(type_: typing.Any) -> typing.Any:
210
+ maybe_annotated_type = typing_extensions.get_origin(type_)
211
+ if maybe_annotated_type is None:
212
+ return type_
213
+
214
+ if maybe_annotated_type == typing_extensions.NotRequired:
215
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
216
+
217
+ if maybe_annotated_type == typing_extensions.Annotated:
218
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
219
+
220
+ return type_
221
+
222
+
223
+ def get_alias_to_field_mapping(type_: typing.Any) -> typing.Dict[str, str]:
224
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
225
+ return _get_alias_to_field_name(annotations)
226
+
227
+
228
+ def get_field_to_alias_mapping(type_: typing.Any) -> typing.Dict[str, str]:
229
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
230
+ return _get_field_to_alias_name(annotations)
231
+
232
+
233
+ def _get_alias_to_field_name(
234
+ field_to_hint: typing.Dict[str, typing.Any],
235
+ ) -> typing.Dict[str, str]:
236
+ aliases = {}
237
+ for field, hint in field_to_hint.items():
238
+ maybe_alias = _get_alias_from_type(hint)
239
+ if maybe_alias is not None:
240
+ aliases[maybe_alias] = field
241
+ return aliases
242
+
243
+
244
+ def _get_field_to_alias_name(
245
+ field_to_hint: typing.Dict[str, typing.Any],
246
+ ) -> typing.Dict[str, str]:
247
+ aliases = {}
248
+ for field, hint in field_to_hint.items():
249
+ maybe_alias = _get_alias_from_type(hint)
250
+ if maybe_alias is not None:
251
+ aliases[field] = maybe_alias
252
+ return aliases
253
+
254
+
255
+ def _get_alias_from_type(type_: typing.Any) -> typing.Optional[str]:
256
+ maybe_annotated_type = _get_annotation(type_)
257
+
258
+ if maybe_annotated_type is not None:
259
+ # The actual annotations are 1 onward, the first is the annotated type
260
+ annotations = typing_extensions.get_args(maybe_annotated_type)[1:]
261
+
262
+ for annotation in annotations:
263
+ if isinstance(annotation, FieldMetadata) and annotation.alias is not None:
264
+ return annotation.alias
265
+ return None
266
+
267
+
268
+ def _alias_key(
269
+ key: str,
270
+ type_: typing.Any,
271
+ direction: typing.Literal["read", "write"],
272
+ aliases_to_field_names: typing.Dict[str, str],
273
+ ) -> str:
274
+ if direction == "read":
275
+ return aliases_to_field_names.get(key, key)
276
+ return _get_alias_from_type(type_=type_) or key
@@ -0,0 +1,40 @@
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 .forbidden_error import ForbiddenError
10
+ from .unauthorized_error import UnauthorizedError
11
+ from .unprocessable_entity_error import UnprocessableEntityError
12
+ _dynamic_imports: typing.Dict[str, str] = {
13
+ "ForbiddenError": ".forbidden_error",
14
+ "UnauthorizedError": ".unauthorized_error",
15
+ "UnprocessableEntityError": ".unprocessable_entity_error",
16
+ }
17
+
18
+
19
+ def __getattr__(attr_name: str) -> typing.Any:
20
+ module_name = _dynamic_imports.get(attr_name)
21
+ if module_name is None:
22
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
23
+ try:
24
+ module = import_module(module_name, __package__)
25
+ if module_name == f".{attr_name}":
26
+ return module
27
+ else:
28
+ return getattr(module, attr_name)
29
+ except ImportError as e:
30
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
31
+ except AttributeError as e:
32
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
33
+
34
+
35
+ def __dir__():
36
+ lazy_attrs = list(_dynamic_imports.keys())
37
+ return sorted(lazy_attrs)
38
+
39
+
40
+ __all__ = ["ForbiddenError", "UnauthorizedError", "UnprocessableEntityError"]
@@ -0,0 +1,11 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.api_error import ApiError
6
+ from ..types.authorization_error import AuthorizationError
7
+
8
+
9
+ class ForbiddenError(ApiError):
10
+ def __init__(self, body: AuthorizationError, headers: typing.Optional[typing.Dict[str, str]] = None):
11
+ super().__init__(status_code=403, headers=headers, body=body)
@@ -0,0 +1,11 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.api_error import ApiError
6
+ from ..types.authentication_error import AuthenticationError
7
+
8
+
9
+ class UnauthorizedError(ApiError):
10
+ def __init__(self, body: AuthenticationError, headers: typing.Optional[typing.Dict[str, str]] = None):
11
+ super().__init__(status_code=401, headers=headers, body=body)
@@ -0,0 +1,11 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.api_error import ApiError
6
+ from ..types.http_validation_error import HttpValidationError
7
+
8
+
9
+ class UnprocessableEntityError(ApiError):
10
+ def __init__(self, body: HttpValidationError, headers: typing.Optional[typing.Dict[str, str]] = None):
11
+ super().__init__(status_code=422, headers=headers, body=body)
@@ -0,0 +1,4 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
@@ -0,0 +1,102 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6
+ from ..core.request_options import RequestOptions
7
+ from ..types.evaluation_status_response import EvaluationStatusResponse
8
+ from .raw_client import AsyncRawEvaluationClient, RawEvaluationClient
9
+
10
+
11
+ class EvaluationClient:
12
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
13
+ self._raw_client = RawEvaluationClient(client_wrapper=client_wrapper)
14
+
15
+ @property
16
+ def with_raw_response(self) -> RawEvaluationClient:
17
+ """
18
+ Retrieves a raw implementation of this client that returns raw responses.
19
+
20
+ Returns
21
+ -------
22
+ RawEvaluationClient
23
+ """
24
+ return self._raw_client
25
+
26
+ def get_status(self, *, request_options: typing.Optional[RequestOptions] = None) -> EvaluationStatusResponse:
27
+ """
28
+ Returns the current evaluation period status for the authenticated tenant
29
+
30
+ Parameters
31
+ ----------
32
+ request_options : typing.Optional[RequestOptions]
33
+ Request-specific configuration.
34
+
35
+ Returns
36
+ -------
37
+ EvaluationStatusResponse
38
+ Successful Response
39
+
40
+ Examples
41
+ --------
42
+ from levelfour import BaseLevelFour
43
+
44
+ client = BaseLevelFour(
45
+ token="YOUR_TOKEN",
46
+ base_url="https://yourhost.com/path/to/api",
47
+ )
48
+ client.evaluation.get_status()
49
+ """
50
+ _response = self._raw_client.get_status(request_options=request_options)
51
+ return _response.data
52
+
53
+
54
+ class AsyncEvaluationClient:
55
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
56
+ self._raw_client = AsyncRawEvaluationClient(client_wrapper=client_wrapper)
57
+
58
+ @property
59
+ def with_raw_response(self) -> AsyncRawEvaluationClient:
60
+ """
61
+ Retrieves a raw implementation of this client that returns raw responses.
62
+
63
+ Returns
64
+ -------
65
+ AsyncRawEvaluationClient
66
+ """
67
+ return self._raw_client
68
+
69
+ async def get_status(self, *, request_options: typing.Optional[RequestOptions] = None) -> EvaluationStatusResponse:
70
+ """
71
+ Returns the current evaluation period status for the authenticated tenant
72
+
73
+ Parameters
74
+ ----------
75
+ request_options : typing.Optional[RequestOptions]
76
+ Request-specific configuration.
77
+
78
+ Returns
79
+ -------
80
+ EvaluationStatusResponse
81
+ Successful Response
82
+
83
+ Examples
84
+ --------
85
+ import asyncio
86
+
87
+ from levelfour import AsyncBaseLevelFour
88
+
89
+ client = AsyncBaseLevelFour(
90
+ token="YOUR_TOKEN",
91
+ base_url="https://yourhost.com/path/to/api",
92
+ )
93
+
94
+
95
+ async def main() -> None:
96
+ await client.evaluation.get_status()
97
+
98
+
99
+ asyncio.run(main())
100
+ """
101
+ _response = await self._raw_client.get_status(request_options=request_options)
102
+ return _response.data
@@ -0,0 +1,141 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from json.decoder import JSONDecodeError
5
+
6
+ from ..core.api_error import ApiError
7
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8
+ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
+ from ..core.pydantic_utilities import parse_obj_as
10
+ from ..core.request_options import RequestOptions
11
+ from ..errors.forbidden_error import ForbiddenError
12
+ from ..errors.unauthorized_error import UnauthorizedError
13
+ from ..types.authentication_error import AuthenticationError
14
+ from ..types.authorization_error import AuthorizationError
15
+ from ..types.evaluation_status_response import EvaluationStatusResponse
16
+
17
+
18
+ class RawEvaluationClient:
19
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
20
+ self._client_wrapper = client_wrapper
21
+
22
+ def get_status(
23
+ self, *, request_options: typing.Optional[RequestOptions] = None
24
+ ) -> HttpResponse[EvaluationStatusResponse]:
25
+ """
26
+ Returns the current evaluation period status for the authenticated tenant
27
+
28
+ Parameters
29
+ ----------
30
+ request_options : typing.Optional[RequestOptions]
31
+ Request-specific configuration.
32
+
33
+ Returns
34
+ -------
35
+ HttpResponse[EvaluationStatusResponse]
36
+ Successful Response
37
+ """
38
+ _response = self._client_wrapper.httpx_client.request(
39
+ "api/v1/evaluation/status",
40
+ method="GET",
41
+ request_options=request_options,
42
+ )
43
+ try:
44
+ if 200 <= _response.status_code < 300:
45
+ _data = typing.cast(
46
+ EvaluationStatusResponse,
47
+ parse_obj_as(
48
+ type_=EvaluationStatusResponse, # type: ignore
49
+ object_=_response.json(),
50
+ ),
51
+ )
52
+ return HttpResponse(response=_response, data=_data)
53
+ if _response.status_code == 401:
54
+ raise UnauthorizedError(
55
+ headers=dict(_response.headers),
56
+ body=typing.cast(
57
+ AuthenticationError,
58
+ parse_obj_as(
59
+ type_=AuthenticationError, # type: ignore
60
+ object_=_response.json(),
61
+ ),
62
+ ),
63
+ )
64
+ if _response.status_code == 403:
65
+ raise ForbiddenError(
66
+ headers=dict(_response.headers),
67
+ body=typing.cast(
68
+ AuthorizationError,
69
+ parse_obj_as(
70
+ type_=AuthorizationError, # type: ignore
71
+ object_=_response.json(),
72
+ ),
73
+ ),
74
+ )
75
+ _response_json = _response.json()
76
+ except JSONDecodeError:
77
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
78
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
79
+
80
+
81
+ class AsyncRawEvaluationClient:
82
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
83
+ self._client_wrapper = client_wrapper
84
+
85
+ async def get_status(
86
+ self, *, request_options: typing.Optional[RequestOptions] = None
87
+ ) -> AsyncHttpResponse[EvaluationStatusResponse]:
88
+ """
89
+ Returns the current evaluation period status for the authenticated tenant
90
+
91
+ Parameters
92
+ ----------
93
+ request_options : typing.Optional[RequestOptions]
94
+ Request-specific configuration.
95
+
96
+ Returns
97
+ -------
98
+ AsyncHttpResponse[EvaluationStatusResponse]
99
+ Successful Response
100
+ """
101
+ _response = await self._client_wrapper.httpx_client.request(
102
+ "api/v1/evaluation/status",
103
+ method="GET",
104
+ request_options=request_options,
105
+ )
106
+ try:
107
+ if 200 <= _response.status_code < 300:
108
+ _data = typing.cast(
109
+ EvaluationStatusResponse,
110
+ parse_obj_as(
111
+ type_=EvaluationStatusResponse, # type: ignore
112
+ object_=_response.json(),
113
+ ),
114
+ )
115
+ return AsyncHttpResponse(response=_response, data=_data)
116
+ if _response.status_code == 401:
117
+ raise UnauthorizedError(
118
+ headers=dict(_response.headers),
119
+ body=typing.cast(
120
+ AuthenticationError,
121
+ parse_obj_as(
122
+ type_=AuthenticationError, # type: ignore
123
+ object_=_response.json(),
124
+ ),
125
+ ),
126
+ )
127
+ if _response.status_code == 403:
128
+ raise ForbiddenError(
129
+ headers=dict(_response.headers),
130
+ body=typing.cast(
131
+ AuthorizationError,
132
+ parse_obj_as(
133
+ type_=AuthorizationError, # type: ignore
134
+ object_=_response.json(),
135
+ ),
136
+ ),
137
+ )
138
+ _response_json = _response.json()
139
+ except JSONDecodeError:
140
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
141
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
@@ -0,0 +1,63 @@
1
+ class LevelFourError(Exception):
2
+ def __init__(self, status_code: int, code: str, message: str, details: dict | list | None = None):
3
+ self.status_code = status_code
4
+ self.code = code
5
+ self.message = message
6
+ self.details = details
7
+ super().__init__(message)
8
+
9
+ def __repr__(self) -> str:
10
+ return f"{type(self).__name__}(status_code={self.status_code}, code={self.code!r}, message={self.message!r})"
11
+
12
+
13
+ class AuthenticationError(LevelFourError):
14
+ def __init__(self, message: str = "Authentication failed", details: dict | list | None = None):
15
+ super().__init__(401, "AUTHENTICATION_ERROR", message, details)
16
+
17
+
18
+ class AuthorizationError(LevelFourError):
19
+ def __init__(self, message: str = "Authorization failed", details: dict | list | None = None):
20
+ super().__init__(403, "AUTHORIZATION_ERROR", message, details)
21
+
22
+
23
+ class NotFoundError(LevelFourError):
24
+ def __init__(self, message: str = "Resource not found", details: dict | list | None = None):
25
+ super().__init__(404, "NOT_FOUND", message, details)
26
+
27
+
28
+ class BadRequestError(LevelFourError):
29
+ def __init__(self, message: str = "Bad request", details: dict | list | None = None):
30
+ super().__init__(400, "BAD_REQUEST", message, details)
31
+
32
+
33
+ class ConflictError(LevelFourError):
34
+ def __init__(self, message: str = "Conflict", details: dict | list | None = None):
35
+ super().__init__(409, "CONFLICT", message, details)
36
+
37
+
38
+ class RateLimitError(LevelFourError):
39
+ def __init__(self, message: str = "Rate limit exceeded", details: dict | list | None = None, retry_after: str | None = None):
40
+ super().__init__(429, "RATE_LIMIT_EXCEEDED", message, details)
41
+ self.retry_after = retry_after
42
+
43
+
44
+ class ValidationError(LevelFourError):
45
+ def __init__(self, message: str = "Validation error", details: dict | list | None = None):
46
+ super().__init__(422, "VALIDATION_ERROR", message, details)
47
+
48
+
49
+ class InternalServerError(LevelFourError):
50
+ def __init__(self, message: str = "Internal server error", details: dict | list | None = None):
51
+ super().__init__(500, "INTERNAL_SERVER_ERROR", message, details)
52
+
53
+
54
+ STATUS_TO_EXCEPTION: dict[int, type[LevelFourError]] = {
55
+ 400: BadRequestError,
56
+ 401: AuthenticationError,
57
+ 403: AuthorizationError,
58
+ 404: NotFoundError,
59
+ 409: ConflictError,
60
+ 422: ValidationError,
61
+ 429: RateLimitError,
62
+ 500: InternalServerError,
63
+ }
@@ -0,0 +1,4 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+