@@ -38,13 +38,19 @@ Please refer to the [Unstructured docs](https://docs.unstructured.io/api-referen
3838 * [ SDK Example Usage] ( #sdk-example-usage )
3939 * [ Configuration] ( #configuration )
4040 * [ File uploads] ( #file-uploads )
41+ * [ Resource Management] ( #resource-management )
4142 * [ Debugging] ( #debugging )
4243
4344<!-- End Table of Contents [toc] -->
4445
4546<!-- Start SDK Installation [installation] -->
4647## SDK Installation
4748
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+
4854The SDK can be installed with either * pip* or * poetry* package managers.
4955
5056### PIP
@@ -62,6 +68,37 @@ pip install unstructured-client
6268``` bash
6369poetry add unstructured-client
6470```
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.
65102<!-- End SDK Installation [installation] -->
66103
67104
@@ -76,28 +113,27 @@ from unstructured_client import UnstructuredClient
76113from unstructured_client.models import shared
77114from unstructured_client.utils import BackoffStrategy, RetryConfig
78115
79- with UnstructuredClient() as unstructured_client :
116+ with UnstructuredClient() as uc_client :
80117
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>" ,
86126 },
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 ,
93129 },
94130 },
95131 RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
96132
97- assert res.elements is not None
133+ assert res.destination_connector_information is not None
98134
99135 # Handle response
100- print (res.elements )
136+ print (res.destination_connector_information )
101137
102138```
103139
@@ -109,27 +145,26 @@ from unstructured_client.utils import BackoffStrategy, RetryConfig
109145
110146with UnstructuredClient(
111147 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>" ,
119158 },
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 ,
126161 },
127162 })
128163
129- assert res.elements is not None
164+ assert res.destination_connector_information is not None
130165
131166 # Handle response
132- print (res.elements )
167+ print (res.destination_connector_information )
133168
134169```
135170<!-- End Retries [retries] -->
@@ -149,50 +184,45 @@ By default, an API error will raise a errors.SDKError exception, which has the f
149184| ` .raw_response ` | * httpx.Response* | The raw HTTP response |
150185| ` .body ` | * str* | The response content |
151186
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:
153188
154189| Error Type | Status Code | Content Type |
155190| -------------------------- | ----------- | ---------------- |
156191| errors.HTTPValidationError | 422 | application/json |
157- | errors.ServerError | 5XX | application/json |
158- | errors.SDKError | 4XX | \* /\* |
192+ | errors.SDKError | 4XX, 5XX | \* /\* |
159193
160194### Example
161195
162196``` python
163197from unstructured_client import UnstructuredClient
164198from unstructured_client.models import errors, shared
165199
166- with UnstructuredClient() as unstructured_client :
200+ with UnstructuredClient() as uc_client :
167201 res = None
168202 try :
169203
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>" ,
175212 },
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 ,
182215 },
183216 })
184217
185- assert res.elements is not None
218+ assert res.destination_connector_information is not None
186219
187220 # Handle response
188- print (res.elements )
221+ print (res.destination_connector_information )
189222
190223 except errors.HTTPValidationError as e:
191224 # handle e.data: errors.HTTPValidationErrorData
192225 raise (e)
193- except errors.ServerError as e:
194- # handle e.data: errors.ServerErrorData
195- raise (e)
196226 except errors.SDKError as e:
197227 # handle exception
198228 raise (e)
@@ -301,27 +331,26 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
301331from unstructured_client import UnstructuredClient
302332from unstructured_client.models import shared
303333
304- with UnstructuredClient() as unstructured_client :
334+ with UnstructuredClient() as uc_client :
305335
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>" ,
311344 },
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 ,
318347 },
319348 })
320349
321- assert res.elements is not None
350+ assert res.destination_connector_information is not None
322351
323352 # Handle response
324- print (res.elements )
353+ print (res.destination_connector_information )
325354```
326355
327356</br >
@@ -334,27 +363,26 @@ from unstructured_client import UnstructuredClient
334363from unstructured_client.models import shared
335364
336365async 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>" ,
344376 },
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 ,
351379 },
352380 })
353381
354- assert res.elements is not None
382+ assert res.destination_connector_information is not None
355383
356384 # Handle response
357- print (res.elements )
385+ print (res.destination_connector_information )
358386
359387asyncio.run(main())
360388```
@@ -431,22 +459,19 @@ Certain SDK methods accept file objects as part of a request body or multi-part
431459
432460``` python
433461from unstructured_client import UnstructuredClient
434- from unstructured_client.models import shared
435462
436- with UnstructuredClient() as unstructured_client :
463+ with UnstructuredClient() as uc_client :
437464
438- res = unstructured_client .general.partition(request = {
465+ res = uc_client .general.partition(request = {
439466 " partition_parameters" : {
440467 " files" : {
441468 " content" : open (" example.file" , " rb" ),
442469 " file_name" : " example.file" ,
443470 },
444- " chunking_strategy" : shared.ChunkingStrategy.BY_TITLE ,
445471 " split_pdf_page_range" : [
446472 1 ,
447473 10 ,
448474 ],
449- " strategy" : shared.Strategy.HI_RES ,
450475 },
451476 })
452477
@@ -458,6 +483,27 @@ with UnstructuredClient() as unstructured_client:
458483```
459484<!-- End File uploads [file-upload] -->
460485
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+
461507<!-- Start Debugging [debug] -->
462508## Debugging
463509
0 commit comments