Skip to content

Commit f69d6d8

Browse files
authored
chore: Update usage example to be consistent with docs (#130)
The autogenerated example is inconsistent with our hosted docs. Remove this section and copy the usage snippet from the docs. Also, add a note for the new page range feature.
1 parent 63faad6 commit f69d6d8

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

README.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,43 @@ pip install unstructured-client
3535
```
3636
<!-- End SDK Installation [installation] -->
3737

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

4140
### Example
4241

4342
```python
43+
import os
44+
4445
import unstructured_client
4546
from unstructured_client.models import operations, shared
4647

47-
s = unstructured_client.UnstructuredClient(
48-
api_key_auth="YOUR_API_KEY",
48+
client = unstructured_client.UnstructuredClient(
49+
api_key_auth=os.getenv("UNSTRUCTURED_API_KEY"),
50+
server_url=os.getenv("UNSTRUCTURED_API_URL"),
4951
)
5052

53+
filename = "PATH_TO_FILE"
54+
with open(filename, "rb") as f:
55+
data = f.read()
5156

52-
res = s.general.partition(request=operations.PartitionRequest(
57+
req = operations.PartitionRequest(
5358
partition_parameters=shared.PartitionParameters(
5459
files=shared.Files(
55-
content='0x2cC94b2FEF'.encode(),
56-
file_name='your_file_here',
60+
content=data,
61+
file_name=filename,
5762
),
58-
split_pdf_page_range=[
59-
1,
60-
10,
61-
],
63+
# --- Other partition parameters ---
6264
strategy=shared.Strategy.AUTO,
65+
languages=['eng'],
6366
),
64-
))
65-
66-
if res.elements is not None:
67-
# handle response
68-
pass
67+
)
6968

69+
try:
70+
res = client.general.partition(request=req)
71+
print(res.elements[0])
72+
except Exception as e:
73+
print(e)
7074
```
71-
<!-- End SDK Example Usage [usage] -->
72-
7375
Refer to the [API parameters page](https://docs.unstructured.io/api-reference/api-services/api-parameters) for all available parameters.
7476

7577
### Configuration
@@ -92,6 +94,21 @@ req = shared.PartitionParameters(
9294
split_pdf_concurrency_level=8
9395
)
9496
```
97+
98+
#### Sending specific page ranges
99+
100+
When `split_pdf_page=True` (the default), you can optionally specify a page range to send only a portion of your PDF to be extracted. The parameter takes a list of two integers to specify the range, inclusive. A ValueError is thrown if the page range is invalid.
101+
102+
Example:
103+
```python
104+
req = shared.PartitionParameters(
105+
files=files,
106+
strategy="fast",
107+
languages=["eng"],
108+
split_pdf_page_range=[10,15],
109+
)
110+
```
111+
95112
<!-- Start Retries [retries] -->
96113
## Retries
97114

@@ -178,6 +195,7 @@ s = unstructured_client.UnstructuredClient(client=http_client)
178195
```
179196
<!-- End Custom HTTP Client [http-client] -->
180197

198+
<!-- No SDK Example Usage [usage] -->
181199
<!-- No SDK Available Operations -->
182200
<!-- No Pagination -->
183201
<!-- No Error Handling -->

0 commit comments

Comments
 (0)