casedev 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 (185) hide show
  1. casedev/__init__.py +104 -0
  2. casedev/_base_client.py +1995 -0
  3. casedev/_client.py +560 -0
  4. casedev/_compat.py +219 -0
  5. casedev/_constants.py +14 -0
  6. casedev/_exceptions.py +108 -0
  7. casedev/_files.py +123 -0
  8. casedev/_models.py +857 -0
  9. casedev/_qs.py +150 -0
  10. casedev/_resource.py +43 -0
  11. casedev/_response.py +830 -0
  12. casedev/_streaming.py +333 -0
  13. casedev/_types.py +260 -0
  14. casedev/_utils/__init__.py +64 -0
  15. casedev/_utils/_compat.py +45 -0
  16. casedev/_utils/_datetime_parse.py +136 -0
  17. casedev/_utils/_logs.py +25 -0
  18. casedev/_utils/_proxy.py +65 -0
  19. casedev/_utils/_reflection.py +42 -0
  20. casedev/_utils/_resources_proxy.py +24 -0
  21. casedev/_utils/_streams.py +12 -0
  22. casedev/_utils/_sync.py +58 -0
  23. casedev/_utils/_transform.py +457 -0
  24. casedev/_utils/_typing.py +156 -0
  25. casedev/_utils/_utils.py +421 -0
  26. casedev/_version.py +4 -0
  27. casedev/lib/.keep +4 -0
  28. casedev/py.typed +0 -0
  29. casedev/resources/__init__.py +173 -0
  30. casedev/resources/actions/__init__.py +33 -0
  31. casedev/resources/actions/actions.py +102 -0
  32. casedev/resources/actions/v1.py +640 -0
  33. casedev/resources/compute/__init__.py +33 -0
  34. casedev/resources/compute/compute.py +102 -0
  35. casedev/resources/compute/v1/__init__.py +89 -0
  36. casedev/resources/compute/v1/environments.py +492 -0
  37. casedev/resources/compute/v1/functions.py +278 -0
  38. casedev/resources/compute/v1/invoke.py +216 -0
  39. casedev/resources/compute/v1/runs.py +290 -0
  40. casedev/resources/compute/v1/secrets.py +655 -0
  41. casedev/resources/compute/v1/v1.py +583 -0
  42. casedev/resources/convert/__init__.py +33 -0
  43. casedev/resources/convert/convert.py +102 -0
  44. casedev/resources/convert/v1/__init__.py +33 -0
  45. casedev/resources/convert/v1/jobs.py +254 -0
  46. casedev/resources/convert/v1/v1.py +450 -0
  47. casedev/resources/format/__init__.py +33 -0
  48. casedev/resources/format/format.py +102 -0
  49. casedev/resources/format/v1/__init__.py +33 -0
  50. casedev/resources/format/v1/templates.py +419 -0
  51. casedev/resources/format/v1/v1.py +244 -0
  52. casedev/resources/llm/__init__.py +33 -0
  53. casedev/resources/llm/llm.py +192 -0
  54. casedev/resources/llm/v1/__init__.py +33 -0
  55. casedev/resources/llm/v1/chat.py +243 -0
  56. casedev/resources/llm/v1/v1.py +317 -0
  57. casedev/resources/ocr/__init__.py +33 -0
  58. casedev/resources/ocr/ocr.py +102 -0
  59. casedev/resources/ocr/v1.py +407 -0
  60. casedev/resources/search/__init__.py +33 -0
  61. casedev/resources/search/search.py +102 -0
  62. casedev/resources/search/v1.py +1052 -0
  63. casedev/resources/templates/__init__.py +33 -0
  64. casedev/resources/templates/templates.py +102 -0
  65. casedev/resources/templates/v1.py +633 -0
  66. casedev/resources/vault/__init__.py +47 -0
  67. casedev/resources/vault/graphrag.py +256 -0
  68. casedev/resources/vault/objects.py +571 -0
  69. casedev/resources/vault/vault.py +764 -0
  70. casedev/resources/voice/__init__.py +61 -0
  71. casedev/resources/voice/streaming.py +160 -0
  72. casedev/resources/voice/transcription.py +327 -0
  73. casedev/resources/voice/v1/__init__.py +33 -0
  74. casedev/resources/voice/v1/speak.py +478 -0
  75. casedev/resources/voice/v1/v1.py +290 -0
  76. casedev/resources/voice/voice.py +166 -0
  77. casedev/resources/webhooks/__init__.py +33 -0
  78. casedev/resources/webhooks/v1.py +447 -0
  79. casedev/resources/webhooks/webhooks.py +102 -0
  80. casedev/resources/workflows/__init__.py +33 -0
  81. casedev/resources/workflows/v1.py +1053 -0
  82. casedev/resources/workflows/workflows.py +102 -0
  83. casedev/types/__init__.py +12 -0
  84. casedev/types/actions/__init__.py +8 -0
  85. casedev/types/actions/v1_create_params.py +22 -0
  86. casedev/types/actions/v1_create_response.py +33 -0
  87. casedev/types/actions/v1_execute_params.py +16 -0
  88. casedev/types/actions/v1_execute_response.py +31 -0
  89. casedev/types/compute/__init__.py +7 -0
  90. casedev/types/compute/v1/__init__.py +18 -0
  91. casedev/types/compute/v1/environment_create_params.py +12 -0
  92. casedev/types/compute/v1/environment_create_response.py +34 -0
  93. casedev/types/compute/v1/environment_delete_response.py +11 -0
  94. casedev/types/compute/v1/function_get_logs_params.py +12 -0
  95. casedev/types/compute/v1/function_list_params.py +12 -0
  96. casedev/types/compute/v1/invoke_run_params.py +21 -0
  97. casedev/types/compute/v1/invoke_run_response.py +39 -0
  98. casedev/types/compute/v1/run_list_params.py +18 -0
  99. casedev/types/compute/v1/secret_create_params.py +24 -0
  100. casedev/types/compute/v1/secret_create_response.py +24 -0
  101. casedev/types/compute/v1/secret_delete_group_params.py +18 -0
  102. casedev/types/compute/v1/secret_list_params.py +15 -0
  103. casedev/types/compute/v1/secret_retrieve_group_params.py +12 -0
  104. casedev/types/compute/v1/secret_update_group_params.py +16 -0
  105. casedev/types/compute/v1_deploy_params.py +114 -0
  106. casedev/types/compute/v1_deploy_response.py +30 -0
  107. casedev/types/compute/v1_get_usage_params.py +15 -0
  108. casedev/types/convert/__init__.py +8 -0
  109. casedev/types/convert/v1/__init__.py +3 -0
  110. casedev/types/convert/v1_process_params.py +15 -0
  111. casedev/types/convert/v1_process_response.py +19 -0
  112. casedev/types/convert/v1_webhook_params.py +32 -0
  113. casedev/types/convert/v1_webhook_response.py +13 -0
  114. casedev/types/format/__init__.py +5 -0
  115. casedev/types/format/v1/__init__.py +7 -0
  116. casedev/types/format/v1/template_create_params.py +32 -0
  117. casedev/types/format/v1/template_create_response.py +27 -0
  118. casedev/types/format/v1/template_list_params.py +12 -0
  119. casedev/types/format/v1_create_document_params.py +42 -0
  120. casedev/types/llm/__init__.py +5 -0
  121. casedev/types/llm/v1/__init__.py +6 -0
  122. casedev/types/llm/v1/chat_create_completion_params.py +42 -0
  123. casedev/types/llm/v1/chat_create_completion_response.py +49 -0
  124. casedev/types/llm/v1_create_embedding_params.py +27 -0
  125. casedev/types/ocr/__init__.py +6 -0
  126. casedev/types/ocr/v1_process_params.py +44 -0
  127. casedev/types/ocr/v1_process_response.py +32 -0
  128. casedev/types/search/__init__.py +15 -0
  129. casedev/types/search/v1_answer_params.py +45 -0
  130. casedev/types/search/v1_answer_response.py +35 -0
  131. casedev/types/search/v1_contents_params.py +42 -0
  132. casedev/types/search/v1_contents_response.py +31 -0
  133. casedev/types/search/v1_research_params.py +23 -0
  134. casedev/types/search/v1_research_response.py +20 -0
  135. casedev/types/search/v1_retrieve_research_params.py +15 -0
  136. casedev/types/search/v1_search_params.py +56 -0
  137. casedev/types/search/v1_search_response.py +38 -0
  138. casedev/types/search/v1_similar_params.py +44 -0
  139. casedev/types/search/v1_similar_response.py +33 -0
  140. casedev/types/templates/__init__.py +8 -0
  141. casedev/types/templates/v1_execute_params.py +22 -0
  142. casedev/types/templates/v1_execute_response.py +31 -0
  143. casedev/types/templates/v1_list_params.py +32 -0
  144. casedev/types/templates/v1_search_params.py +18 -0
  145. casedev/types/vault/__init__.py +6 -0
  146. casedev/types/vault/object_create_presigned_url_params.py +22 -0
  147. casedev/types/vault/object_create_presigned_url_response.py +51 -0
  148. casedev/types/vault_create_params.py +20 -0
  149. casedev/types/vault_create_response.py +36 -0
  150. casedev/types/vault_ingest_response.py +26 -0
  151. casedev/types/vault_list_response.py +40 -0
  152. casedev/types/vault_search_params.py +27 -0
  153. casedev/types/vault_search_response.py +53 -0
  154. casedev/types/vault_upload_params.py +26 -0
  155. casedev/types/vault_upload_response.py +39 -0
  156. casedev/types/voice/__init__.py +7 -0
  157. casedev/types/voice/transcription_create_params.py +36 -0
  158. casedev/types/voice/transcription_retrieve_response.py +41 -0
  159. casedev/types/voice/v1/__init__.py +6 -0
  160. casedev/types/voice/v1/speak_create_params.py +59 -0
  161. casedev/types/voice/v1/speak_stream_params.py +58 -0
  162. casedev/types/voice/v1_list_voices_params.py +36 -0
  163. casedev/types/webhooks/__init__.py +6 -0
  164. casedev/types/webhooks/v1_create_params.py +20 -0
  165. casedev/types/webhooks/v1_create_response.py +33 -0
  166. casedev/types/workflows/__init__.py +19 -0
  167. casedev/types/workflows/v1_create_params.py +32 -0
  168. casedev/types/workflows/v1_create_response.py +29 -0
  169. casedev/types/workflows/v1_delete_response.py +13 -0
  170. casedev/types/workflows/v1_deploy_response.py +20 -0
  171. casedev/types/workflows/v1_execute_params.py +12 -0
  172. casedev/types/workflows/v1_execute_response.py +22 -0
  173. casedev/types/workflows/v1_list_executions_params.py +13 -0
  174. casedev/types/workflows/v1_list_executions_response.py +27 -0
  175. casedev/types/workflows/v1_list_params.py +18 -0
  176. casedev/types/workflows/v1_list_response.py +37 -0
  177. casedev/types/workflows/v1_retrieve_execution_response.py +31 -0
  178. casedev/types/workflows/v1_retrieve_response.py +35 -0
  179. casedev/types/workflows/v1_undeploy_response.py +13 -0
  180. casedev/types/workflows/v1_update_params.py +26 -0
  181. casedev/types/workflows/v1_update_response.py +17 -0
  182. casedev-0.1.0.dist-info/METADATA +454 -0
  183. casedev-0.1.0.dist-info/RECORD +185 -0
  184. casedev-0.1.0.dist-info/WHEEL +4 -0
  185. casedev-0.1.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,37 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List, Optional
4
+
5
+ from pydantic import Field as FieldInfo
6
+
7
+ from ..._models import BaseModel
8
+
9
+ __all__ = ["V1ListResponse", "Workflow"]
10
+
11
+
12
+ class Workflow(BaseModel):
13
+ id: Optional[str] = None
14
+
15
+ created_at: Optional[str] = FieldInfo(alias="createdAt", default=None)
16
+
17
+ deployed_at: Optional[str] = FieldInfo(alias="deployedAt", default=None)
18
+
19
+ description: Optional[str] = None
20
+
21
+ name: Optional[str] = None
22
+
23
+ trigger_type: Optional[str] = FieldInfo(alias="triggerType", default=None)
24
+
25
+ updated_at: Optional[str] = FieldInfo(alias="updatedAt", default=None)
26
+
27
+ visibility: Optional[str] = None
28
+
29
+
30
+ class V1ListResponse(BaseModel):
31
+ limit: Optional[int] = None
32
+
33
+ offset: Optional[int] = None
34
+
35
+ total: Optional[int] = None
36
+
37
+ workflows: Optional[List[Workflow]] = None
@@ -0,0 +1,31 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+
5
+ from pydantic import Field as FieldInfo
6
+
7
+ from ..._models import BaseModel
8
+
9
+ __all__ = ["V1RetrieveExecutionResponse"]
10
+
11
+
12
+ class V1RetrieveExecutionResponse(BaseModel):
13
+ id: Optional[str] = None
14
+
15
+ completed_at: Optional[str] = FieldInfo(alias="completedAt", default=None)
16
+
17
+ duration_ms: Optional[int] = FieldInfo(alias="durationMs", default=None)
18
+
19
+ error: Optional[str] = None
20
+
21
+ input: Optional[object] = None
22
+
23
+ output: Optional[object] = None
24
+
25
+ started_at: Optional[str] = FieldInfo(alias="startedAt", default=None)
26
+
27
+ status: Optional[str] = None
28
+
29
+ trigger_type: Optional[str] = FieldInfo(alias="triggerType", default=None)
30
+
31
+ workflow_id: Optional[str] = FieldInfo(alias="workflowId", default=None)
@@ -0,0 +1,35 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List, Optional
4
+
5
+ from pydantic import Field as FieldInfo
6
+
7
+ from ..._models import BaseModel
8
+
9
+ __all__ = ["V1RetrieveResponse"]
10
+
11
+
12
+ class V1RetrieveResponse(BaseModel):
13
+ id: Optional[str] = None
14
+
15
+ created_at: Optional[str] = FieldInfo(alias="createdAt", default=None)
16
+
17
+ deployed_at: Optional[str] = FieldInfo(alias="deployedAt", default=None)
18
+
19
+ deployment_url: Optional[str] = FieldInfo(alias="deploymentUrl", default=None)
20
+
21
+ description: Optional[str] = None
22
+
23
+ edges: Optional[List[object]] = None
24
+
25
+ name: Optional[str] = None
26
+
27
+ nodes: Optional[List[object]] = None
28
+
29
+ trigger_config: Optional[object] = FieldInfo(alias="triggerConfig", default=None)
30
+
31
+ trigger_type: Optional[str] = FieldInfo(alias="triggerType", default=None)
32
+
33
+ updated_at: Optional[str] = FieldInfo(alias="updatedAt", default=None)
34
+
35
+ visibility: Optional[str] = None
@@ -0,0 +1,13 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+
5
+ from ..._models import BaseModel
6
+
7
+ __all__ = ["V1UndeployResponse"]
8
+
9
+
10
+ class V1UndeployResponse(BaseModel):
11
+ message: Optional[str] = None
12
+
13
+ success: Optional[bool] = None
@@ -0,0 +1,26 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Iterable
6
+ from typing_extensions import Literal, Annotated, TypedDict
7
+
8
+ from ..._utils import PropertyInfo
9
+
10
+ __all__ = ["V1UpdateParams"]
11
+
12
+
13
+ class V1UpdateParams(TypedDict, total=False):
14
+ description: str
15
+
16
+ edges: Iterable[object]
17
+
18
+ name: str
19
+
20
+ nodes: Iterable[object]
21
+
22
+ trigger_config: Annotated[object, PropertyInfo(alias="triggerConfig")]
23
+
24
+ trigger_type: Annotated[Literal["manual", "webhook", "schedule", "vault_upload"], PropertyInfo(alias="triggerType")]
25
+
26
+ visibility: Literal["private", "org", "public"]
@@ -0,0 +1,17 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+
5
+ from pydantic import Field as FieldInfo
6
+
7
+ from ..._models import BaseModel
8
+
9
+ __all__ = ["V1UpdateResponse"]
10
+
11
+
12
+ class V1UpdateResponse(BaseModel):
13
+ id: Optional[str] = None
14
+
15
+ name: Optional[str] = None
16
+
17
+ updated_at: Optional[str] = FieldInfo(alias="updatedAt", default=None)
@@ -0,0 +1,454 @@
1
+ Metadata-Version: 2.3
2
+ Name: casedev
3
+ Version: 0.1.0
4
+ Summary: The official Python library for the casedev API
5
+ Project-URL: Homepage, https://github.com/CaseMark/casedev-python
6
+ Project-URL: Repository, https://github.com/CaseMark/casedev-python
7
+ Author-email: Casedev <support@casemark.com>
8
+ License: Apache-2.0
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: anyio<5,>=3.5.0
26
+ Requires-Dist: distro<2,>=1.7.0
27
+ Requires-Dist: httpx<1,>=0.23.0
28
+ Requires-Dist: pydantic<3,>=1.9.0
29
+ Requires-Dist: sniffio
30
+ Requires-Dist: typing-extensions<5,>=4.10
31
+ Provides-Extra: aiohttp
32
+ Requires-Dist: aiohttp; extra == 'aiohttp'
33
+ Requires-Dist: httpx-aiohttp>=0.1.9; extra == 'aiohttp'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Casedev Python API library
37
+
38
+ <!-- prettier-ignore -->
39
+ [![PyPI version](https://img.shields.io/pypi/v/casedev.svg?label=pypi%20(stable))](https://pypi.org/project/casedev/)
40
+
41
+ The Casedev Python library provides convenient access to the Casedev REST API from any Python 3.9+
42
+ application. The library includes type definitions for all request params and response fields,
43
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
44
+
45
+ It is generated with [Stainless](https://www.stainless.com/).
46
+
47
+ ## Documentation
48
+
49
+ The REST API documentation can be found on [docs.case.dev](https://docs.case.dev). The full API of this library can be found in [api.md](https://github.com/CaseMark/casedev-python/tree/main/api.md).
50
+
51
+ ## Installation
52
+
53
+ ```sh
54
+ # install from the production repo
55
+ pip install git+ssh://git@github.com/CaseMark/casedev-python.git
56
+ ```
57
+
58
+ > [!NOTE]
59
+ > Once this package is [published to PyPI](https://www.stainless.com/docs/guides/publish), this will become: `pip install casedev`
60
+
61
+ ## Usage
62
+
63
+ The full API of this library can be found in [api.md](https://github.com/CaseMark/casedev-python/tree/main/api.md).
64
+
65
+ ```python
66
+ import os
67
+ from casedev import Casedev
68
+
69
+ client = Casedev(
70
+ api_key=os.environ.get("CASEDEV_API_KEY"), # This is the default and can be omitted
71
+ # defaults to "production".
72
+ environment="local",
73
+ )
74
+
75
+ response = client.llm.v1.chat.create_completion(
76
+ messages=[
77
+ {
78
+ "role": "user",
79
+ "content": "Hello!",
80
+ }
81
+ ],
82
+ )
83
+ print(response.id)
84
+ ```
85
+
86
+ While you can provide an `api_key` keyword argument,
87
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
88
+ to add `CASEDEV_API_KEY="My API Key"` to your `.env` file
89
+ so that your API Key is not stored in source control.
90
+
91
+ ## Async usage
92
+
93
+ Simply import `AsyncCasedev` instead of `Casedev` and use `await` with each API call:
94
+
95
+ ```python
96
+ import os
97
+ import asyncio
98
+ from casedev import AsyncCasedev
99
+
100
+ client = AsyncCasedev(
101
+ api_key=os.environ.get("CASEDEV_API_KEY"), # This is the default and can be omitted
102
+ # defaults to "production".
103
+ environment="local",
104
+ )
105
+
106
+
107
+ async def main() -> None:
108
+ response = await client.llm.v1.chat.create_completion(
109
+ messages=[
110
+ {
111
+ "role": "user",
112
+ "content": "Hello!",
113
+ }
114
+ ],
115
+ )
116
+ print(response.id)
117
+
118
+
119
+ asyncio.run(main())
120
+ ```
121
+
122
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
123
+
124
+ ### With aiohttp
125
+
126
+ By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
127
+
128
+ You can enable this by installing `aiohttp`:
129
+
130
+ ```sh
131
+ # install from the production repo
132
+ pip install 'casedev[aiohttp] @ git+ssh://git@github.com/CaseMark/casedev-python.git'
133
+ ```
134
+
135
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
136
+
137
+ ```python
138
+ import os
139
+ import asyncio
140
+ from casedev import DefaultAioHttpClient
141
+ from casedev import AsyncCasedev
142
+
143
+
144
+ async def main() -> None:
145
+ async with AsyncCasedev(
146
+ api_key=os.environ.get("CASEDEV_API_KEY"), # This is the default and can be omitted
147
+ http_client=DefaultAioHttpClient(),
148
+ ) as client:
149
+ response = await client.llm.v1.chat.create_completion(
150
+ messages=[
151
+ {
152
+ "role": "user",
153
+ "content": "Hello!",
154
+ }
155
+ ],
156
+ )
157
+ print(response.id)
158
+
159
+
160
+ asyncio.run(main())
161
+ ```
162
+
163
+ ## Using types
164
+
165
+ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
166
+
167
+ - Serializing back into JSON, `model.to_json()`
168
+ - Converting to a dictionary, `model.to_dict()`
169
+
170
+ Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
171
+
172
+ ## Nested params
173
+
174
+ Nested parameters are dictionaries, typed using `TypedDict`, for example:
175
+
176
+ ```python
177
+ from casedev import Casedev
178
+
179
+ client = Casedev()
180
+
181
+ response = client.compute.v1.deploy(
182
+ entrypoint_name="entrypointName",
183
+ type="task",
184
+ config={},
185
+ )
186
+ print(response.config)
187
+ ```
188
+
189
+ ## Handling errors
190
+
191
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `casedev.APIConnectionError` is raised.
192
+
193
+ When the API returns a non-success status code (that is, 4xx or 5xx
194
+ response), a subclass of `casedev.APIStatusError` is raised, containing `status_code` and `response` properties.
195
+
196
+ All errors inherit from `casedev.APIError`.
197
+
198
+ ```python
199
+ import casedev
200
+ from casedev import Casedev
201
+
202
+ client = Casedev()
203
+
204
+ try:
205
+ client.vault.create(
206
+ name="My Vault",
207
+ )
208
+ except casedev.APIConnectionError as e:
209
+ print("The server could not be reached")
210
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
211
+ except casedev.RateLimitError as e:
212
+ print("A 429 status code was received; we should back off a bit.")
213
+ except casedev.APIStatusError as e:
214
+ print("Another non-200-range status code was received")
215
+ print(e.status_code)
216
+ print(e.response)
217
+ ```
218
+
219
+ Error codes are as follows:
220
+
221
+ | Status Code | Error Type |
222
+ | ----------- | -------------------------- |
223
+ | 400 | `BadRequestError` |
224
+ | 401 | `AuthenticationError` |
225
+ | 403 | `PermissionDeniedError` |
226
+ | 404 | `NotFoundError` |
227
+ | 422 | `UnprocessableEntityError` |
228
+ | 429 | `RateLimitError` |
229
+ | >=500 | `InternalServerError` |
230
+ | N/A | `APIConnectionError` |
231
+
232
+ ### Retries
233
+
234
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
235
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
236
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
237
+
238
+ You can use the `max_retries` option to configure or disable retry settings:
239
+
240
+ ```python
241
+ from casedev import Casedev
242
+
243
+ # Configure the default for all requests:
244
+ client = Casedev(
245
+ # default is 2
246
+ max_retries=0,
247
+ )
248
+
249
+ # Or, configure per-request:
250
+ client.with_options(max_retries=5).vault.create(
251
+ name="My Vault",
252
+ )
253
+ ```
254
+
255
+ ### Timeouts
256
+
257
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
258
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
259
+
260
+ ```python
261
+ from casedev import Casedev
262
+
263
+ # Configure the default for all requests:
264
+ client = Casedev(
265
+ # 20 seconds (default is 1 minute)
266
+ timeout=20.0,
267
+ )
268
+
269
+ # More granular control:
270
+ client = Casedev(
271
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
272
+ )
273
+
274
+ # Override per-request:
275
+ client.with_options(timeout=5.0).vault.create(
276
+ name="My Vault",
277
+ )
278
+ ```
279
+
280
+ On timeout, an `APITimeoutError` is thrown.
281
+
282
+ Note that requests that time out are [retried twice by default](https://github.com/CaseMark/casedev-python/tree/main/#retries).
283
+
284
+ ## Advanced
285
+
286
+ ### Logging
287
+
288
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
289
+
290
+ You can enable logging by setting the environment variable `CASEDEV_LOG` to `info`.
291
+
292
+ ```shell
293
+ $ export CASEDEV_LOG=info
294
+ ```
295
+
296
+ Or to `debug` for more verbose logging.
297
+
298
+ ### How to tell whether `None` means `null` or missing
299
+
300
+ In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
301
+
302
+ ```py
303
+ if response.my_field is None:
304
+ if 'my_field' not in response.model_fields_set:
305
+ print('Got json like {}, without a "my_field" key present at all.')
306
+ else:
307
+ print('Got json like {"my_field": null}.')
308
+ ```
309
+
310
+ ### Accessing raw response data (e.g. headers)
311
+
312
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
313
+
314
+ ```py
315
+ from casedev import Casedev
316
+
317
+ client = Casedev()
318
+ response = client.vault.with_raw_response.create(
319
+ name="My Vault",
320
+ )
321
+ print(response.headers.get('X-My-Header'))
322
+
323
+ vault = response.parse() # get the object that `vault.create()` would have returned
324
+ print(vault.id)
325
+ ```
326
+
327
+ These methods return an [`APIResponse`](https://github.com/CaseMark/casedev-python/tree/main/src/casedev/_response.py) object.
328
+
329
+ The async client returns an [`AsyncAPIResponse`](https://github.com/CaseMark/casedev-python/tree/main/src/casedev/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
330
+
331
+ #### `.with_streaming_response`
332
+
333
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
334
+
335
+ To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
336
+
337
+ ```python
338
+ with client.vault.with_streaming_response.create(
339
+ name="My Vault",
340
+ ) as response:
341
+ print(response.headers.get("X-My-Header"))
342
+
343
+ for line in response.iter_lines():
344
+ print(line)
345
+ ```
346
+
347
+ The context manager is required so that the response will reliably be closed.
348
+
349
+ ### Making custom/undocumented requests
350
+
351
+ This library is typed for convenient access to the documented API.
352
+
353
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
354
+
355
+ #### Undocumented endpoints
356
+
357
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
358
+ http verbs. Options on the client will be respected (such as retries) when making this request.
359
+
360
+ ```py
361
+ import httpx
362
+
363
+ response = client.post(
364
+ "/foo",
365
+ cast_to=httpx.Response,
366
+ body={"my_param": True},
367
+ )
368
+
369
+ print(response.headers.get("x-foo"))
370
+ ```
371
+
372
+ #### Undocumented request params
373
+
374
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
375
+ options.
376
+
377
+ #### Undocumented response properties
378
+
379
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
380
+ can also get all the extra fields on the Pydantic model as a dict with
381
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
382
+
383
+ ### Configuring the HTTP client
384
+
385
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
386
+
387
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
388
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
389
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
390
+
391
+ ```python
392
+ import httpx
393
+ from casedev import Casedev, DefaultHttpxClient
394
+
395
+ client = Casedev(
396
+ # Or use the `CASEDEV_BASE_URL` env var
397
+ base_url="http://my.test.server.example.com:8083",
398
+ http_client=DefaultHttpxClient(
399
+ proxy="http://my.test.proxy.example.com",
400
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
401
+ ),
402
+ )
403
+ ```
404
+
405
+ You can also customize the client on a per-request basis by using `with_options()`:
406
+
407
+ ```python
408
+ client.with_options(http_client=DefaultHttpxClient(...))
409
+ ```
410
+
411
+ ### Managing HTTP resources
412
+
413
+ By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
414
+
415
+ ```py
416
+ from casedev import Casedev
417
+
418
+ with Casedev() as client:
419
+ # make requests here
420
+ ...
421
+
422
+ # HTTP client is now closed
423
+ ```
424
+
425
+ ## Versioning
426
+
427
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
428
+
429
+ 1. Changes that only affect static types, without breaking runtime behavior.
430
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
431
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
432
+
433
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
434
+
435
+ We are keen for your feedback; please open an [issue](https://www.github.com/CaseMark/casedev-python/issues) with questions, bugs, or suggestions.
436
+
437
+ ### Determining the installed version
438
+
439
+ If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
440
+
441
+ You can determine the version that is being used at runtime with:
442
+
443
+ ```py
444
+ import casedev
445
+ print(casedev.__version__)
446
+ ```
447
+
448
+ ## Requirements
449
+
450
+ Python 3.9 or higher.
451
+
452
+ ## Contributing
453
+
454
+ See [the contributing documentation](https://github.com/CaseMark/casedev-python/tree/main/./CONTRIBUTING.md).