Skip to content
Merged
Changes from all 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
129 changes: 32 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<p>Python SDK for the Unstructured API</p>
</h2>

This is a Python client for the [Unstructured API](https://unstructured-io.github.io/unstructured/api.html).
This is a Python client for the [Unstructured API](https://docs.unstructured.io/api-reference/api-services/overview).

Please refer to the [Unstructured docs](https://docs.unstructured.io/api-reference/api-services/sdk) for a full guide to using the client.

<!-- Start SDK Installation [installation] -->
## SDK Installation
Expand All @@ -33,77 +35,40 @@ pip install unstructured-client
```
<!-- End SDK Installation [installation] -->

## Usage
Only the `files` parameter is required.

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

s = UnstructuredClient(api_key_auth="YOUR_API_KEY")
<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

filename = "_sample_docs/layout-parser-paper-fast.pdf"
### Example

with open(filename, "rb") as f:
# Note that this currently only supports a single file
files=shared.Files(
content=f.read(),
file_name=filename,
)
```python
import unstructured_client
from unstructured_client.models import operations, shared

req = shared.PartitionParameters(
files=files,
# Other partition params
strategy='ocr_only',
languages=["eng"],
s = unstructured_client.UnstructuredClient(
api_key_auth="YOUR_API_KEY",
)

try:
resp = s.general.partition(req)
print(resp.elements[0])
except SDKError as e:
print(e)
```

Result:

```
{
'type': 'UncategorizedText',
'element_id': 'fc550084fda1e008e07a0356894f5816',
'metadata': {
'filename': 'layout-parser-paper-fast.pdf',
'filetype': 'application/pdf',
'languages': ['eng'],
'page_number': 1
}
}
```

### UnstructuredClient

#### Change the base URL

If you are self hosting the API, or developing locally, you can change the server URL when setting up the client.
res = s.general.partition(request=operations.PartitionRequest(
partition_parameters=shared.PartitionParameters(
files=shared.Files(
content='0x2cC94b2FEF'.encode(),
file_name='your_file_here',
),
strategy=shared.Strategy.AUTO,
),
))

```python
# Using a local server
s = unstructured_client.UnstructuredClient(
server_url="http://localhost:8000",
api_key_auth=api_key,
)
if res.elements is not None:
# handle response
pass

# Using your own server
s = unstructured_client.UnstructuredClient(
server_url="https://your-server",
api_key_auth=api_key,
)
```
<!-- End SDK Example Usage [usage] -->

### PartitionParameters
Refer to the [API parameters page](https://docs.unstructured.io/api-reference/api-services/api-parameters) for all available parameters.

See the [general partition](/docs/models/shared/partitionparameters.md) page for all available parameters. 
### Configuration

#### Splitting PDF by pages

Expand All @@ -122,10 +87,8 @@ req = shared.PartitionParameters(
split_pdf_concurrency_level=8
)
```
<!-- No SDK Available Operations -->
<!-- No Pagination -->
<!-- No Error Handling -->
<!-- No Server Selection -->
<!-- Start Retries -->
<!-- End Retries -->

<!-- Start Custom HTTP Client [http-client] -->
## Custom HTTP Client
Expand All @@ -143,40 +106,12 @@ s = unstructured_client.UnstructuredClient(client=http_client)
```
<!-- End Custom HTTP Client [http-client] -->

<!-- No Retries -->
<!-- No SDK Available Operations -->
<!-- No Pagination -->
<!-- No Error Handling -->
<!-- No Server Selection -->
<!-- No Authentication -->

<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

### Example

```python
import unstructured_client
from unstructured_client.models import operations, shared

s = unstructured_client.UnstructuredClient(
api_key_auth="YOUR_API_KEY",
)


res = s.general.partition(request=operations.PartitionRequest(
partition_parameters=shared.PartitionParameters(
files=shared.Files(
content='0x2cC94b2FEF'.encode(),
file_name='your_file_here',
),
strategy=shared.Strategy.AUTO,
),
))

if res.elements is not None:
# handle response
pass

```
<!-- End SDK Example Usage [usage] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

### Maturity
Expand Down