Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 309 additions & 13 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
speakeasyVersion: 1.468.6
speakeasyVersion: 1.488.0
sources:
my-source:
sourceNamespace: my-source
sourceRevisionDigest: sha256:54175e5c24d314f86f33f72766514aae3730046ac37c53dc9096391d42db22e1
sourceBlobDigest: sha256:4a1f22c295063b53f9ffd80d429877a1857889cd4cd216808a5ad3077b0fde4d
sourceRevisionDigest: sha256:38de94b8fb4d2ee973b988986c3e0dcd2e2deaf6de38ef40ac58067728720315
sourceBlobDigest: sha256:2cc0f6d125e0a830dfd67e8fc18d001981832c93783af5c9da0d81841deea9f8
tags:
- latest
- speakeasy-sdk-regen-1736554181
- 1.0.58
- speakeasy-sdk-regen-1739216953
- 1.0.0
targets:
unstructured-python:
source: my-source
sourceNamespace: my-source
sourceRevisionDigest: sha256:54175e5c24d314f86f33f72766514aae3730046ac37c53dc9096391d42db22e1
sourceBlobDigest: sha256:4a1f22c295063b53f9ffd80d429877a1857889cd4cd216808a5ad3077b0fde4d
sourceRevisionDigest: sha256:38de94b8fb4d2ee973b988986c3e0dcd2e2deaf6de38ef40ac58067728720315
sourceBlobDigest: sha256:2cc0f6d125e0a830dfd67e8fc18d001981832c93783af5c9da0d81841deea9f8
codeSamplesNamespace: my-source-code-samples
codeSamplesRevisionDigest: sha256:7aff54e905b986e29c396c5d1b4142521dd48c2db25190d45ca0a3fb3d3b7346
codeSamplesRevisionDigest: sha256:1f17aac0d1c9f3ea69a6d6f4c74814935b8b8210034200d60883eb3662b54ee1
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
sources:
my-source:
inputs:
- location: https://api.unstructured.io/general/openapi.json
- location: https://platform.unstructuredapp.io/openapi.json
overlays:
- location: ./overlay_client.yaml
registry:
Expand Down
212 changes: 129 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ Please refer to the [Unstructured docs](https://docs.unstructured.io/api-referen
* [SDK Example Usage](#sdk-example-usage)
* [Configuration](#configuration)
* [File uploads](#file-uploads)
* [Resource Management](#resource-management)
* [Debugging](#debugging)

<!-- End Table of Contents [toc] -->

<!-- Start SDK Installation [installation] -->
## SDK Installation

> [!NOTE]
> **Python version upgrade policy**
>
> 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.

The SDK can be installed with either *pip* or *poetry* package managers.

### PIP
Expand All @@ -62,6 +68,37 @@ pip install unstructured-client
```bash
poetry add unstructured-client
```

### Shell and script usage with `uv`

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:

```shell
uvx --from unstructured-client python
```

It's also possible to write a standalone Python script without needing to set up a whole project like so:

```python
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "unstructured-client",
# ]
# ///

from unstructured_client import UnstructuredClient

sdk = UnstructuredClient(
# SDK arguments
)

# Rest of script here...
```

Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.
<!-- End SDK Installation [installation] -->


Expand All @@ -76,28 +113,27 @@ from unstructured_client import UnstructuredClient
from unstructured_client.models import shared
from unstructured_client.utils import BackoffStrategy, RetryConfig

with UnstructuredClient() as unstructured_client:
with UnstructuredClient() as uc_client:

res = unstructured_client.general.partition(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
res = uc_client.destinations.create_destination(request={
"create_destination_connector": {
"config": {
"account_key": "azure_account_key",
"account_name": "azure_account_name",
"anonymous": False,
"recursive": True,
"remote_url": "az://<path></path></container-name>",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
"name": "<value>",
"type": shared.DestinationConnectorType.ASTRADB,
},
},
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))

assert res.elements is not None
assert res.destination_connector_information is not None

# Handle response
print(res.elements)
print(res.destination_connector_information)

```

Expand All @@ -109,27 +145,26 @@ from unstructured_client.utils import BackoffStrategy, RetryConfig

with UnstructuredClient(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
) as unstructured_client:

res = unstructured_client.general.partition(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
) as uc_client:

res = uc_client.destinations.create_destination(request={
"create_destination_connector": {
"config": {
"account_key": "azure_account_key",
"account_name": "azure_account_name",
"anonymous": False,
"recursive": True,
"remote_url": "az://<path></path></container-name>",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
"name": "<value>",
"type": shared.DestinationConnectorType.ASTRADB,
},
})

assert res.elements is not None
assert res.destination_connector_information is not None

# Handle response
print(res.elements)
print(res.destination_connector_information)

```
<!-- End Retries [retries] -->
Expand All @@ -149,50 +184,45 @@ By default, an API error will raise a errors.SDKError exception, which has the f
| `.raw_response` | *httpx.Response* | The raw HTTP response |
| `.body` | *str* | The response content |

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:
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:

| Error Type | Status Code | Content Type |
| -------------------------- | ----------- | ---------------- |
| errors.HTTPValidationError | 422 | application/json |
| errors.ServerError | 5XX | application/json |
| errors.SDKError | 4XX | \*/\* |
| errors.SDKError | 4XX, 5XX | \*/\* |

### Example

```python
from unstructured_client import UnstructuredClient
from unstructured_client.models import errors, shared

with UnstructuredClient() as unstructured_client:
with UnstructuredClient() as uc_client:
res = None
try:

res = unstructured_client.general.partition(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
res = uc_client.destinations.create_destination(request={
"create_destination_connector": {
"config": {
"account_key": "azure_account_key",
"account_name": "azure_account_name",
"anonymous": False,
"recursive": True,
"remote_url": "az://<path></path></container-name>",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
"name": "<value>",
"type": shared.DestinationConnectorType.ASTRADB,
},
})

assert res.elements is not None
assert res.destination_connector_information is not None

# Handle response
print(res.elements)
print(res.destination_connector_information)

except errors.HTTPValidationError as e:
# handle e.data: errors.HTTPValidationErrorData
raise(e)
except errors.ServerError as e:
# handle e.data: errors.ServerErrorData
raise(e)
except errors.SDKError as e:
# handle exception
raise(e)
Expand Down Expand Up @@ -301,27 +331,26 @@ Generally, the SDK will work well with most IDEs out of the box. However, when u
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared

with UnstructuredClient() as unstructured_client:
with UnstructuredClient() as uc_client:

res = unstructured_client.general.partition(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
res = uc_client.destinations.create_destination(request={
"create_destination_connector": {
"config": {
"account_key": "azure_account_key",
"account_name": "azure_account_name",
"anonymous": False,
"recursive": True,
"remote_url": "az://<path></path></container-name>",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
"name": "<value>",
"type": shared.DestinationConnectorType.ASTRADB,
},
})

assert res.elements is not None
assert res.destination_connector_information is not None

# Handle response
print(res.elements)
print(res.destination_connector_information)
```

</br>
Expand All @@ -334,27 +363,26 @@ from unstructured_client import UnstructuredClient
from unstructured_client.models import shared

async def main():
async with UnstructuredClient() as unstructured_client:

res = await unstructured_client.general.partition_async(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
async with UnstructuredClient() as uc_client:

res = await uc_client.destinations.create_destination_async(request={
"create_destination_connector": {
"config": {
"account_key": "azure_account_key",
"account_name": "azure_account_name",
"anonymous": False,
"recursive": True,
"remote_url": "az://<path></path></container-name>",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
"name": "<value>",
"type": shared.DestinationConnectorType.ASTRADB,
},
})

assert res.elements is not None
assert res.destination_connector_information is not None

# Handle response
print(res.elements)
print(res.destination_connector_information)

asyncio.run(main())
```
Expand Down Expand Up @@ -431,22 +459,19 @@ Certain SDK methods accept file objects as part of a request body or multi-part

```python
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared

with UnstructuredClient() as unstructured_client:
with UnstructuredClient() as uc_client:

res = unstructured_client.general.partition(request={
res = uc_client.general.partition(request={
"partition_parameters": {
"files": {
"content": open("example.file", "rb"),
"file_name": "example.file",
},
"chunking_strategy": shared.ChunkingStrategy.BY_TITLE,
"split_pdf_page_range": [
1,
10,
],
"strategy": shared.Strategy.HI_RES,
},
})

Expand All @@ -458,6 +483,27 @@ with UnstructuredClient() as unstructured_client:
```
<!-- End File uploads [file-upload] -->

<!-- Start Resource Management [resource-management] -->
## Resource Management

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.

[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers

```python
from unstructured_client import UnstructuredClient
def main():
with UnstructuredClient() as uc_client:
# Rest of application here...


# Or when using async:
async def amain():
async with UnstructuredClient() as uc_client:
# Rest of application here...
```
<!-- End Resource Management [resource-management] -->

<!-- Start Debugging [debug] -->
## Debugging

Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,14 @@ Based on:
### Generated
- [python v0.29.0] .
### Releases
- [PyPI v0.29.0] https://pypi.org/project/unstructured-client/0.29.0 - .
- [PyPI v0.29.0] https://pypi.org/project/unstructured-client/0.29.0 - .

## 2025-02-12 00:09:11
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.488.0 (2.506.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v0.30.0] .
### Releases
- [PyPI v0.30.0] https://pypi.org/project/unstructured-client/0.30.0 - .
Loading
Loading