prelude-python-sdk 0.1.0a3__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 (44) hide show
  1. prelude_python_sdk/__init__.py +83 -0
  2. prelude_python_sdk/_base_client.py +2041 -0
  3. prelude_python_sdk/_client.py +422 -0
  4. prelude_python_sdk/_compat.py +221 -0
  5. prelude_python_sdk/_constants.py +14 -0
  6. prelude_python_sdk/_exceptions.py +108 -0
  7. prelude_python_sdk/_files.py +123 -0
  8. prelude_python_sdk/_models.py +788 -0
  9. prelude_python_sdk/_qs.py +150 -0
  10. prelude_python_sdk/_resource.py +43 -0
  11. prelude_python_sdk/_response.py +826 -0
  12. prelude_python_sdk/_streaming.py +333 -0
  13. prelude_python_sdk/_types.py +219 -0
  14. prelude_python_sdk/_utils/__init__.py +56 -0
  15. prelude_python_sdk/_utils/_logs.py +25 -0
  16. prelude_python_sdk/_utils/_proxy.py +62 -0
  17. prelude_python_sdk/_utils/_reflection.py +42 -0
  18. prelude_python_sdk/_utils/_streams.py +12 -0
  19. prelude_python_sdk/_utils/_sync.py +81 -0
  20. prelude_python_sdk/_utils/_transform.py +392 -0
  21. prelude_python_sdk/_utils/_typing.py +120 -0
  22. prelude_python_sdk/_utils/_utils.py +414 -0
  23. prelude_python_sdk/_version.py +4 -0
  24. prelude_python_sdk/lib/.keep +4 -0
  25. prelude_python_sdk/py.typed +0 -0
  26. prelude_python_sdk/resources/__init__.py +47 -0
  27. prelude_python_sdk/resources/transactional.py +230 -0
  28. prelude_python_sdk/resources/verification.py +311 -0
  29. prelude_python_sdk/resources/watch.py +297 -0
  30. prelude_python_sdk/types/__init__.py +14 -0
  31. prelude_python_sdk/types/transactional_send_params.py +33 -0
  32. prelude_python_sdk/types/transactional_send_response.py +39 -0
  33. prelude_python_sdk/types/verification_check_params.py +23 -0
  34. prelude_python_sdk/types/verification_check_response.py +25 -0
  35. prelude_python_sdk/types/verification_create_params.py +98 -0
  36. prelude_python_sdk/types/verification_create_response.py +28 -0
  37. prelude_python_sdk/types/watch_feed_back_params.py +34 -0
  38. prelude_python_sdk/types/watch_feed_back_response.py +12 -0
  39. prelude_python_sdk/types/watch_predict_params.py +44 -0
  40. prelude_python_sdk/types/watch_predict_response.py +29 -0
  41. prelude_python_sdk-0.1.0a3.dist-info/METADATA +386 -0
  42. prelude_python_sdk-0.1.0a3.dist-info/RECORD +44 -0
  43. prelude_python_sdk-0.1.0a3.dist-info/WHEEL +4 -0
  44. prelude_python_sdk-0.1.0a3.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,23 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Literal, Required, TypedDict
6
+
7
+ __all__ = ["VerificationCheckParams", "Target"]
8
+
9
+
10
+ class VerificationCheckParams(TypedDict, total=False):
11
+ code: Required[str]
12
+ """The OTP code to validate."""
13
+
14
+ target: Required[Target]
15
+ """The target. Currently this can only be an E.164 formatted phone number."""
16
+
17
+
18
+ class Target(TypedDict, total=False):
19
+ type: Required[Literal["phone_number"]]
20
+ """The type of the target. Currently this can only be "phone_number"."""
21
+
22
+ value: Required[str]
23
+ """An E.164 formatted phone number to verify."""
@@ -0,0 +1,25 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+ from typing_extensions import Literal
5
+
6
+ from .._models import BaseModel
7
+
8
+ __all__ = ["VerificationCheckResponse", "Metadata"]
9
+
10
+
11
+ class Metadata(BaseModel):
12
+ correlation_id: Optional[str] = None
13
+
14
+
15
+ class VerificationCheckResponse(BaseModel):
16
+ id: Optional[str] = None
17
+ """The verification identifier."""
18
+
19
+ metadata: Optional[Metadata] = None
20
+ """The metadata for this verification."""
21
+
22
+ request_id: Optional[str] = None
23
+
24
+ status: Optional[Literal["success", "failure", "expired"]] = None
25
+ """The status of the check."""
@@ -0,0 +1,98 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Literal, Required, TypedDict
6
+
7
+ __all__ = ["VerificationCreateParams", "Target", "Metadata", "Options", "Signals"]
8
+
9
+
10
+ class VerificationCreateParams(TypedDict, total=False):
11
+ target: Required[Target]
12
+ """The target. Currently this can only be an E.164 formatted phone number."""
13
+
14
+ metadata: Metadata
15
+ """The metadata for this verification.
16
+
17
+ This object will be returned with every response or webhook sent that refers to
18
+ this verification.
19
+ """
20
+
21
+ options: Options
22
+ """Verification options"""
23
+
24
+ signals: Signals
25
+ """The signals used for anti-fraud."""
26
+
27
+
28
+ class Target(TypedDict, total=False):
29
+ type: Required[Literal["phone_number"]]
30
+ """The type of the target. Currently this can only be "phone_number"."""
31
+
32
+ value: Required[str]
33
+ """An E.164 formatted phone number to verify."""
34
+
35
+
36
+ class Metadata(TypedDict, total=False):
37
+ correlation_id: str
38
+ """A user-defined identifier to correlate this verification with."""
39
+
40
+
41
+ class Options(TypedDict, total=False):
42
+ app_realm: str
43
+ """The Android SMS Retriever API hash code that identifies your app.
44
+
45
+ This allows you to automatically retrieve and fill the OTP code on Android
46
+ devices.
47
+ """
48
+
49
+ locale: str
50
+ """
51
+ A BCP-47 formatted locale string with the language the text message will be sent
52
+ to. If there's no locale set, the language will be determined by the country
53
+ code of the phone number. If the language specified doesn't exist, it defaults
54
+ to US English.
55
+ """
56
+
57
+ sender_id: str
58
+ """The Sender ID to use for this message.
59
+
60
+ The Sender ID needs to be enabled by Prelude.
61
+ """
62
+
63
+ template_id: str
64
+ """The identifier of a verification settings template.
65
+
66
+ It is used to be able to switch behavior for specific use cases. Contact us if
67
+ you need to use this functionality.
68
+ """
69
+
70
+
71
+ class Signals(TypedDict, total=False):
72
+ app_version: str
73
+ """The version of your application."""
74
+
75
+ device_id: str
76
+ """The unique identifier for the user's device.
77
+
78
+ For Android, this corresponds to the `ANDROID_ID` and for iOS, this corresponds
79
+ to the `identifierForVendor`.
80
+ """
81
+
82
+ device_model: str
83
+ """The model of the user's device."""
84
+
85
+ device_platform: Literal["android", "ios", "web"]
86
+ """The type of the user's device."""
87
+
88
+ ip: str
89
+ """The IP address of the user's device."""
90
+
91
+ is_trusted_user: str
92
+ """
93
+ This signal should provide a higher level of trust, indicating that the user is
94
+ genuine. For more details, refer to [Signals](/guides/prevent-fraud#signals).
95
+ """
96
+
97
+ os_version: str
98
+ """The version of the user's device operating system."""
@@ -0,0 +1,28 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+ from typing_extensions import Literal
5
+
6
+ from .._models import BaseModel
7
+
8
+ __all__ = ["VerificationCreateResponse", "Metadata"]
9
+
10
+
11
+ class Metadata(BaseModel):
12
+ correlation_id: Optional[str] = None
13
+
14
+
15
+ class VerificationCreateResponse(BaseModel):
16
+ id: Optional[str] = None
17
+ """The verification identifier."""
18
+
19
+ metadata: Optional[Metadata] = None
20
+ """The metadata for this verification."""
21
+
22
+ method: Optional[Literal["message"]] = None
23
+ """The method used for verifying this phone number."""
24
+
25
+ request_id: Optional[str] = None
26
+
27
+ status: Optional[Literal["success", "retry", "blocked"]] = None
28
+ """The status of the verification."""
@@ -0,0 +1,34 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Literal, Required, TypedDict
6
+
7
+ __all__ = ["WatchFeedBackParams", "Feedback", "Target"]
8
+
9
+
10
+ class WatchFeedBackParams(TypedDict, total=False):
11
+ feedback: Required[Feedback]
12
+ """
13
+ You should send a feedback event back to Watch API when your user demonstrates
14
+ authentic behavior.
15
+ """
16
+
17
+ target: Required[Target]
18
+ """The target. Currently this can only be an E.164 formatted phone number."""
19
+
20
+
21
+ class Feedback(TypedDict, total=False):
22
+ type: Required[Literal["CONFIRM_TARGET"]]
23
+ """
24
+ `CONFIRM_TARGET` should be sent when you are sure that the user with this target
25
+ (e.g. phone number) is trustworthy.
26
+ """
27
+
28
+
29
+ class Target(TypedDict, total=False):
30
+ type: Required[Literal["phone_number"]]
31
+ """The type of the target. Currently this can only be "phone_number"."""
32
+
33
+ value: Required[str]
34
+ """An E.164 formatted phone number to verify."""
@@ -0,0 +1,12 @@
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__ = ["WatchFeedBackResponse"]
8
+
9
+
10
+ class WatchFeedBackResponse(BaseModel):
11
+ id: Optional[str] = None
12
+ """A unique identifier for your feedback request."""
@@ -0,0 +1,44 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Literal, Required, TypedDict
6
+
7
+ __all__ = ["WatchPredictParams", "Target", "Signals"]
8
+
9
+
10
+ class WatchPredictParams(TypedDict, total=False):
11
+ target: Required[Target]
12
+ """The target. Currently this can only be an E.164 formatted phone number."""
13
+
14
+ signals: Signals
15
+ """
16
+ It is highly recommended that you provide the signals to increase prediction
17
+ performance.
18
+ """
19
+
20
+
21
+ class Target(TypedDict, total=False):
22
+ type: Required[Literal["phone_number"]]
23
+ """The type of the target. Currently this can only be "phone_number"."""
24
+
25
+ value: Required[str]
26
+ """An E.164 formatted phone number to verify."""
27
+
28
+
29
+ class Signals(TypedDict, total=False):
30
+ device_id: str
31
+ """The unique identifier for the user's device.
32
+
33
+ For Android, this corresponds to the `ANDROID_ID` and for iOS, this corresponds
34
+ to the `identifierForVendor`.
35
+ """
36
+
37
+ device_model: str
38
+ """The model of the user's device."""
39
+
40
+ device_type: str
41
+ """The type of the user's device."""
42
+
43
+ ip: str
44
+ """The IPv4 address of the user's device"""
@@ -0,0 +1,29 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Optional
4
+ from typing_extensions import Literal
5
+
6
+ from .._models import BaseModel
7
+
8
+ __all__ = ["WatchPredictResponse", "Reasoning"]
9
+
10
+
11
+ class Reasoning(BaseModel):
12
+ cause: Optional[Literal["none", "smart_antifraud", "repeat_number", "invalid_line"]] = None
13
+ """A label explaining why the phone number was classified as not trustworthy"""
14
+
15
+ score: Optional[float] = None
16
+ """
17
+ Indicates the risk of the phone number being genuine or involved in fraudulent
18
+ patterns. The higher the riskier.
19
+ """
20
+
21
+
22
+ class WatchPredictResponse(BaseModel):
23
+ id: Optional[str] = None
24
+ """A unique identifier for your prediction request."""
25
+
26
+ prediction: Optional[Literal["allow", "block"]] = None
27
+ """A label indicating the trustworthiness of the phone number."""
28
+
29
+ reasoning: Optional[Reasoning] = None
@@ -0,0 +1,386 @@
1
+ Metadata-Version: 2.3
2
+ Name: prelude-python-sdk
3
+ Version: 0.1.0a3
4
+ Summary: The official Python library for the Prelude API
5
+ Project-URL: Homepage, https://github.com/prelude-so/python-sdk
6
+ Project-URL: Repository, https://github.com/prelude-so/python-sdk
7
+ Author-email: Prelude <hello@prelude.so>
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.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.8
24
+ Requires-Dist: anyio<5,>=3.5.0
25
+ Requires-Dist: cached-property; python_version < '3.8'
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.7
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Prelude Python API library
34
+
35
+ [![PyPI version](https://img.shields.io/pypi/v/prelude-python-sdk.svg)](https://pypi.org/project/prelude-python-sdk/)
36
+
37
+ The Prelude Python library provides convenient access to the Prelude REST API from any Python 3.8+
38
+ application. The library includes type definitions for all request params and response fields,
39
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
40
+
41
+ It is generated with [Stainless](https://www.stainlessapi.com/).
42
+
43
+ ## Documentation
44
+
45
+ The REST API documentation can be found on [docs.prelude.so](https://docs.prelude.so). The full API of this library can be found in [api.md](https://github.com/prelude-so/python-sdk/tree/main/api.md).
46
+
47
+ ## Installation
48
+
49
+ ```sh
50
+ # install from PyPI
51
+ pip install --pre prelude-python-sdk
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ The full API of this library can be found in [api.md](https://github.com/prelude-so/python-sdk/tree/main/api.md).
57
+
58
+ ```python
59
+ import os
60
+ from prelude_python_sdk import Prelude
61
+
62
+ client = Prelude(
63
+ api_token=os.environ.get("API_TOKEN"), # This is the default and can be omitted
64
+ )
65
+
66
+ verification = client.verification.create(
67
+ target={
68
+ "type": "phone_number",
69
+ "value": "+30123456789",
70
+ },
71
+ )
72
+ print(verification.id)
73
+ ```
74
+
75
+ While you can provide a `api_token` keyword argument,
76
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
77
+ to add `API_TOKEN="My API Token"` to your `.env` file
78
+ so that your API Token is not stored in source control.
79
+
80
+ ## Async usage
81
+
82
+ Simply import `AsyncPrelude` instead of `Prelude` and use `await` with each API call:
83
+
84
+ ```python
85
+ import os
86
+ import asyncio
87
+ from prelude_python_sdk import AsyncPrelude
88
+
89
+ client = AsyncPrelude(
90
+ api_token=os.environ.get("API_TOKEN"), # This is the default and can be omitted
91
+ )
92
+
93
+
94
+ async def main() -> None:
95
+ verification = await client.verification.create(
96
+ target={
97
+ "type": "phone_number",
98
+ "value": "+30123456789",
99
+ },
100
+ )
101
+ print(verification.id)
102
+
103
+
104
+ asyncio.run(main())
105
+ ```
106
+
107
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
108
+
109
+ ## Using types
110
+
111
+ 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:
112
+
113
+ - Serializing back into JSON, `model.to_json()`
114
+ - Converting to a dictionary, `model.to_dict()`
115
+
116
+ 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`.
117
+
118
+ ## Handling errors
119
+
120
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `prelude_python_sdk.APIConnectionError` is raised.
121
+
122
+ When the API returns a non-success status code (that is, 4xx or 5xx
123
+ response), a subclass of `prelude_python_sdk.APIStatusError` is raised, containing `status_code` and `response` properties.
124
+
125
+ All errors inherit from `prelude_python_sdk.APIError`.
126
+
127
+ ```python
128
+ import prelude_python_sdk
129
+ from prelude_python_sdk import Prelude
130
+
131
+ client = Prelude()
132
+
133
+ try:
134
+ client.verification.create(
135
+ target={
136
+ "type": "phone_number",
137
+ "value": "+30123456789",
138
+ },
139
+ )
140
+ except prelude_python_sdk.APIConnectionError as e:
141
+ print("The server could not be reached")
142
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
143
+ except prelude_python_sdk.RateLimitError as e:
144
+ print("A 429 status code was received; we should back off a bit.")
145
+ except prelude_python_sdk.APIStatusError as e:
146
+ print("Another non-200-range status code was received")
147
+ print(e.status_code)
148
+ print(e.response)
149
+ ```
150
+
151
+ Error codes are as followed:
152
+
153
+ | Status Code | Error Type |
154
+ | ----------- | -------------------------- |
155
+ | 400 | `BadRequestError` |
156
+ | 401 | `AuthenticationError` |
157
+ | 403 | `PermissionDeniedError` |
158
+ | 404 | `NotFoundError` |
159
+ | 422 | `UnprocessableEntityError` |
160
+ | 429 | `RateLimitError` |
161
+ | >=500 | `InternalServerError` |
162
+ | N/A | `APIConnectionError` |
163
+
164
+ ### Retries
165
+
166
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
167
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
168
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
169
+
170
+ You can use the `max_retries` option to configure or disable retry settings:
171
+
172
+ ```python
173
+ from prelude_python_sdk import Prelude
174
+
175
+ # Configure the default for all requests:
176
+ client = Prelude(
177
+ # default is 2
178
+ max_retries=0,
179
+ )
180
+
181
+ # Or, configure per-request:
182
+ client.with_options(max_retries=5).verification.create(
183
+ target={
184
+ "type": "phone_number",
185
+ "value": "+30123456789",
186
+ },
187
+ )
188
+ ```
189
+
190
+ ### Timeouts
191
+
192
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
193
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
194
+
195
+ ```python
196
+ from prelude_python_sdk import Prelude
197
+
198
+ # Configure the default for all requests:
199
+ client = Prelude(
200
+ # 20 seconds (default is 1 minute)
201
+ timeout=20.0,
202
+ )
203
+
204
+ # More granular control:
205
+ client = Prelude(
206
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
207
+ )
208
+
209
+ # Override per-request:
210
+ client.with_options(timeout=5.0).verification.create(
211
+ target={
212
+ "type": "phone_number",
213
+ "value": "+30123456789",
214
+ },
215
+ )
216
+ ```
217
+
218
+ On timeout, an `APITimeoutError` is thrown.
219
+
220
+ Note that requests that time out are [retried twice by default](https://github.com/prelude-so/python-sdk/tree/main/#retries).
221
+
222
+ ## Advanced
223
+
224
+ ### Logging
225
+
226
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
227
+
228
+ You can enable logging by setting the environment variable `PRELUDE_LOG` to `debug`.
229
+
230
+ ```shell
231
+ $ export PRELUDE_LOG=debug
232
+ ```
233
+
234
+ ### How to tell whether `None` means `null` or missing
235
+
236
+ 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`:
237
+
238
+ ```py
239
+ if response.my_field is None:
240
+ if 'my_field' not in response.model_fields_set:
241
+ print('Got json like {}, without a "my_field" key present at all.')
242
+ else:
243
+ print('Got json like {"my_field": null}.')
244
+ ```
245
+
246
+ ### Accessing raw response data (e.g. headers)
247
+
248
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
249
+
250
+ ```py
251
+ from prelude_python_sdk import Prelude
252
+
253
+ client = Prelude()
254
+ response = client.verification.with_raw_response.create(
255
+ target={
256
+ "type": "phone_number",
257
+ "value": "+30123456789",
258
+ },
259
+ )
260
+ print(response.headers.get('X-My-Header'))
261
+
262
+ verification = response.parse() # get the object that `verification.create()` would have returned
263
+ print(verification.id)
264
+ ```
265
+
266
+ These methods return an [`APIResponse`](https://github.com/prelude-so/python-sdk/tree/main/src/prelude_python_sdk/_response.py) object.
267
+
268
+ The async client returns an [`AsyncAPIResponse`](https://github.com/prelude-so/python-sdk/tree/main/src/prelude_python_sdk/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
269
+
270
+ #### `.with_streaming_response`
271
+
272
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
273
+
274
+ 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.
275
+
276
+ ```python
277
+ with client.verification.with_streaming_response.create(
278
+ target={
279
+ "type": "phone_number",
280
+ "value": "+30123456789",
281
+ },
282
+ ) as response:
283
+ print(response.headers.get("X-My-Header"))
284
+
285
+ for line in response.iter_lines():
286
+ print(line)
287
+ ```
288
+
289
+ The context manager is required so that the response will reliably be closed.
290
+
291
+ ### Making custom/undocumented requests
292
+
293
+ This library is typed for convenient access to the documented API.
294
+
295
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
296
+
297
+ #### Undocumented endpoints
298
+
299
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
300
+ http verbs. Options on the client will be respected (such as retries) will be respected when making this
301
+ request.
302
+
303
+ ```py
304
+ import httpx
305
+
306
+ response = client.post(
307
+ "/foo",
308
+ cast_to=httpx.Response,
309
+ body={"my_param": True},
310
+ )
311
+
312
+ print(response.headers.get("x-foo"))
313
+ ```
314
+
315
+ #### Undocumented request params
316
+
317
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
318
+ options.
319
+
320
+ #### Undocumented response properties
321
+
322
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
323
+ can also get all the extra fields on the Pydantic model as a dict with
324
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
325
+
326
+ ### Configuring the HTTP client
327
+
328
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
329
+
330
+ - Support for proxies
331
+ - Custom transports
332
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
333
+
334
+ ```python
335
+ from prelude_python_sdk import Prelude, DefaultHttpxClient
336
+
337
+ client = Prelude(
338
+ # Or use the `PRELUDE_BASE_URL` env var
339
+ base_url="http://my.test.server.example.com:8083",
340
+ http_client=DefaultHttpxClient(
341
+ proxies="http://my.test.proxy.example.com",
342
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
343
+ ),
344
+ )
345
+ ```
346
+
347
+ You can also customize the client on a per-request basis by using `with_options()`:
348
+
349
+ ```python
350
+ client.with_options(http_client=DefaultHttpxClient(...))
351
+ ```
352
+
353
+ ### Managing HTTP resources
354
+
355
+ 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.
356
+
357
+ ## Versioning
358
+
359
+ 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:
360
+
361
+ 1. Changes that only affect static types, without breaking runtime behavior.
362
+ 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)_.
363
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
364
+
365
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
366
+
367
+ We are keen for your feedback; please open an [issue](https://www.github.com/prelude-so/python-sdk/issues) with questions, bugs, or suggestions.
368
+
369
+ ### Determining the installed version
370
+
371
+ 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.
372
+
373
+ You can determine the version that is being used at runtime with:
374
+
375
+ ```py
376
+ import prelude_python_sdk
377
+ print(prelude_python_sdk.__version__)
378
+ ```
379
+
380
+ ## Requirements
381
+
382
+ Python 3.8 or higher.
383
+
384
+ ## Contributing
385
+
386
+ See [the contributing documentation](https://github.com/prelude-so/python-sdk/tree/main/./CONTRIBUTING.md).