@@ -38,13 +38,19 @@ Please refer to the [Unstructured docs](https://docs.unstructured.io/api-referen
38
38
* [ SDK Example Usage] ( #sdk-example-usage )
39
39
* [ Configuration] ( #configuration )
40
40
* [ File uploads] ( #file-uploads )
41
+ * [ Resource Management] ( #resource-management )
41
42
* [ Debugging] ( #debugging )
42
43
43
44
<!-- End Table of Contents [toc] -->
44
45
45
46
<!-- Start SDK Installation [installation] -->
46
47
## SDK Installation
47
48
49
+ > [ !NOTE]
50
+ > ** Python version upgrade policy**
51
+ >
52
+ > Once a Python version reaches its [ official end of life date] ( https://devguide.python.org/versions/ ) , a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
53
+
48
54
The SDK can be installed with either * pip* or * poetry* package managers.
49
55
50
56
### PIP
@@ -62,6 +68,37 @@ pip install unstructured-client
62
68
``` bash
63
69
poetry add unstructured-client
64
70
```
71
+
72
+ ### Shell and script usage with ` uv `
73
+
74
+ You can use this SDK in a Python shell with [ uv] ( https://docs.astral.sh/uv/ ) and the ` uvx ` command that comes with it like so:
75
+
76
+ ``` shell
77
+ uvx --from unstructured-client python
78
+ ```
79
+
80
+ It's also possible to write a standalone Python script without needing to set up a whole project like so:
81
+
82
+ ``` python
83
+ # !/usr/bin/env -S uv run --script
84
+ # /// script
85
+ # requires-python = ">=3.9"
86
+ # dependencies = [
87
+ # "unstructured-client",
88
+ # ]
89
+ # ///
90
+
91
+ from unstructured_client import UnstructuredClient
92
+
93
+ sdk = UnstructuredClient(
94
+ # SDK arguments
95
+ )
96
+
97
+ # Rest of script here...
98
+ ```
99
+
100
+ Once that is saved to a file, you can run it with ` uv run script.py ` where
101
+ ` script.py ` can be replaced with the actual file name.
65
102
<!-- End SDK Installation [installation] -->
66
103
67
104
@@ -76,28 +113,27 @@ from unstructured_client import UnstructuredClient
76
113
from unstructured_client.models import shared
77
114
from unstructured_client.utils import BackoffStrategy, RetryConfig
78
115
79
- with UnstructuredClient() as unstructured_client :
116
+ with UnstructuredClient() as uc_client :
80
117
81
- res = unstructured_client.general.partition(request = {
82
- " partition_parameters" : {
83
- " files" : {
84
- " content" : open (" example.file" , " rb" ),
85
- " file_name" : " example.file" ,
118
+ res = uc_client.destinations.create_destination(request = {
119
+ " create_destination_connector" : {
120
+ " config" : {
121
+ " account_key" : " azure_account_key" ,
122
+ " account_name" : " azure_account_name" ,
123
+ " anonymous" : False ,
124
+ " recursive" : True ,
125
+ " remote_url" : " az://<path></path></container-name>" ,
86
126
},
87
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
88
- " split_pdf_page_range" : [
89
- 1 ,
90
- 10 ,
91
- ],
92
- " strategy" : shared.Strategy.HI_RES ,
127
+ " name" : " <value>" ,
128
+ " type" : shared.DestinationConnectorType.ASTRADB ,
93
129
},
94
130
},
95
131
RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
96
132
97
- assert res.elements is not None
133
+ assert res.destination_connector_information is not None
98
134
99
135
# Handle response
100
- print (res.elements )
136
+ print (res.destination_connector_information )
101
137
102
138
```
103
139
@@ -109,27 +145,26 @@ from unstructured_client.utils import BackoffStrategy, RetryConfig
109
145
110
146
with UnstructuredClient(
111
147
retry_config = RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ),
112
- ) as unstructured_client:
113
-
114
- res = unstructured_client.general.partition(request = {
115
- " partition_parameters" : {
116
- " files" : {
117
- " content" : open (" example.file" , " rb" ),
118
- " file_name" : " example.file" ,
148
+ ) as uc_client:
149
+
150
+ res = uc_client.destinations.create_destination(request = {
151
+ " create_destination_connector" : {
152
+ " config" : {
153
+ " account_key" : " azure_account_key" ,
154
+ " account_name" : " azure_account_name" ,
155
+ " anonymous" : False ,
156
+ " recursive" : True ,
157
+ " remote_url" : " az://<path></path></container-name>" ,
119
158
},
120
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
121
- " split_pdf_page_range" : [
122
- 1 ,
123
- 10 ,
124
- ],
125
- " strategy" : shared.Strategy.HI_RES ,
159
+ " name" : " <value>" ,
160
+ " type" : shared.DestinationConnectorType.ASTRADB ,
126
161
},
127
162
})
128
163
129
- assert res.elements is not None
164
+ assert res.destination_connector_information is not None
130
165
131
166
# Handle response
132
- print (res.elements )
167
+ print (res.destination_connector_information )
133
168
134
169
```
135
170
<!-- End Retries [retries] -->
@@ -149,50 +184,45 @@ By default, an API error will raise a errors.SDKError exception, which has the f
149
184
| ` .raw_response ` | * httpx.Response* | The raw HTTP response |
150
185
| ` .body ` | * str* | The response content |
151
186
152
- When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective * Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the ` partition_async ` method may raise the following exceptions:
187
+ When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective * Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the ` create_destination_async ` method may raise the following exceptions:
153
188
154
189
| Error Type | Status Code | Content Type |
155
190
| -------------------------- | ----------- | ---------------- |
156
191
| errors.HTTPValidationError | 422 | application/json |
157
- | errors.ServerError | 5XX | application/json |
158
- | errors.SDKError | 4XX | \* /\* |
192
+ | errors.SDKError | 4XX, 5XX | \* /\* |
159
193
160
194
### Example
161
195
162
196
``` python
163
197
from unstructured_client import UnstructuredClient
164
198
from unstructured_client.models import errors, shared
165
199
166
- with UnstructuredClient() as unstructured_client :
200
+ with UnstructuredClient() as uc_client :
167
201
res = None
168
202
try :
169
203
170
- res = unstructured_client.general.partition(request = {
171
- " partition_parameters" : {
172
- " files" : {
173
- " content" : open (" example.file" , " rb" ),
174
- " file_name" : " example.file" ,
204
+ res = uc_client.destinations.create_destination(request = {
205
+ " create_destination_connector" : {
206
+ " config" : {
207
+ " account_key" : " azure_account_key" ,
208
+ " account_name" : " azure_account_name" ,
209
+ " anonymous" : False ,
210
+ " recursive" : True ,
211
+ " remote_url" : " az://<path></path></container-name>" ,
175
212
},
176
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
177
- " split_pdf_page_range" : [
178
- 1 ,
179
- 10 ,
180
- ],
181
- " strategy" : shared.Strategy.HI_RES ,
213
+ " name" : " <value>" ,
214
+ " type" : shared.DestinationConnectorType.ASTRADB ,
182
215
},
183
216
})
184
217
185
- assert res.elements is not None
218
+ assert res.destination_connector_information is not None
186
219
187
220
# Handle response
188
- print (res.elements )
221
+ print (res.destination_connector_information )
189
222
190
223
except errors.HTTPValidationError as e:
191
224
# handle e.data: errors.HTTPValidationErrorData
192
225
raise (e)
193
- except errors.ServerError as e:
194
- # handle e.data: errors.ServerErrorData
195
- raise (e)
196
226
except errors.SDKError as e:
197
227
# handle exception
198
228
raise (e)
@@ -301,27 +331,26 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
301
331
from unstructured_client import UnstructuredClient
302
332
from unstructured_client.models import shared
303
333
304
- with UnstructuredClient() as unstructured_client :
334
+ with UnstructuredClient() as uc_client :
305
335
306
- res = unstructured_client.general.partition(request = {
307
- " partition_parameters" : {
308
- " files" : {
309
- " content" : open (" example.file" , " rb" ),
310
- " file_name" : " example.file" ,
336
+ res = uc_client.destinations.create_destination(request = {
337
+ " create_destination_connector" : {
338
+ " config" : {
339
+ " account_key" : " azure_account_key" ,
340
+ " account_name" : " azure_account_name" ,
341
+ " anonymous" : False ,
342
+ " recursive" : True ,
343
+ " remote_url" : " az://<path></path></container-name>" ,
311
344
},
312
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
313
- " split_pdf_page_range" : [
314
- 1 ,
315
- 10 ,
316
- ],
317
- " strategy" : shared.Strategy.HI_RES ,
345
+ " name" : " <value>" ,
346
+ " type" : shared.DestinationConnectorType.ASTRADB ,
318
347
},
319
348
})
320
349
321
- assert res.elements is not None
350
+ assert res.destination_connector_information is not None
322
351
323
352
# Handle response
324
- print (res.elements )
353
+ print (res.destination_connector_information )
325
354
```
326
355
327
356
</br >
@@ -334,27 +363,26 @@ from unstructured_client import UnstructuredClient
334
363
from unstructured_client.models import shared
335
364
336
365
async def main ():
337
- async with UnstructuredClient() as unstructured_client:
338
-
339
- res = await unstructured_client.general.partition_async(request = {
340
- " partition_parameters" : {
341
- " files" : {
342
- " content" : open (" example.file" , " rb" ),
343
- " file_name" : " example.file" ,
366
+ async with UnstructuredClient() as uc_client:
367
+
368
+ res = await uc_client.destinations.create_destination_async(request = {
369
+ " create_destination_connector" : {
370
+ " config" : {
371
+ " account_key" : " azure_account_key" ,
372
+ " account_name" : " azure_account_name" ,
373
+ " anonymous" : False ,
374
+ " recursive" : True ,
375
+ " remote_url" : " az://<path></path></container-name>" ,
344
376
},
345
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
346
- " split_pdf_page_range" : [
347
- 1 ,
348
- 10 ,
349
- ],
350
- " strategy" : shared.Strategy.HI_RES ,
377
+ " name" : " <value>" ,
378
+ " type" : shared.DestinationConnectorType.ASTRADB ,
351
379
},
352
380
})
353
381
354
- assert res.elements is not None
382
+ assert res.destination_connector_information is not None
355
383
356
384
# Handle response
357
- print (res.elements )
385
+ print (res.destination_connector_information )
358
386
359
387
asyncio.run(main())
360
388
```
@@ -431,22 +459,19 @@ Certain SDK methods accept file objects as part of a request body or multi-part
431
459
432
460
``` python
433
461
from unstructured_client import UnstructuredClient
434
- from unstructured_client.models import shared
435
462
436
- with UnstructuredClient() as unstructured_client :
463
+ with UnstructuredClient() as uc_client :
437
464
438
- res = unstructured_client .general.partition(request = {
465
+ res = uc_client .general.partition(request = {
439
466
" partition_parameters" : {
440
467
" files" : {
441
468
" content" : open (" example.file" , " rb" ),
442
469
" file_name" : " example.file" ,
443
470
},
444
- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
445
471
" split_pdf_page_range" : [
446
472
1 ,
447
473
10 ,
448
474
],
449
- " strategy" : shared.Strategy.HI_RES ,
450
475
},
451
476
})
452
477
@@ -458,6 +483,27 @@ with UnstructuredClient() as unstructured_client:
458
483
```
459
484
<!-- End File uploads [file-upload] -->
460
485
486
+ <!-- Start Resource Management [resource-management] -->
487
+ ## Resource Management
488
+
489
+ The ` UnstructuredClient ` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [ context manager] [ context-manager ] and reuse it across the application.
490
+
491
+ [ context-manager ] : https://docs.python.org/3/reference/datamodel.html#context-managers
492
+
493
+ ``` python
494
+ from unstructured_client import UnstructuredClient
495
+ def main ():
496
+ with UnstructuredClient() as uc_client:
497
+ # Rest of application here...
498
+
499
+
500
+ # Or when using async:
501
+ async def amain ():
502
+ async with UnstructuredClient() as uc_client:
503
+ # Rest of application here...
504
+ ```
505
+ <!-- End Resource Management [resource-management] -->
506
+
461
507
<!-- Start Debugging [debug] -->
462
508
## Debugging
463
509
0 commit comments