23
23
<p >Python SDK for the Unstructured API</p >
24
24
</h2 >
25
25
26
- This is a Python client for the [ Unstructured API] ( https://unstructured-io.github.io/unstructured/api.html ) .
26
+ This is a Python client for the [ Unstructured API] ( https://docs.unstructured.io/api-reference/api-services/overview ) .
27
+
28
+ Please refer to the [ Unstructured docs] ( https://docs.unstructured.io/api-reference/api-services/sdk ) for a full guide to using the client.
27
29
28
30
<!-- Start SDK Installation [installation] -->
29
31
## SDK Installation
@@ -33,77 +35,40 @@ pip install unstructured-client
33
35
```
34
36
<!-- End SDK Installation [installation] -->
35
37
36
- ## Usage
37
- Only the ` files ` parameter is required.
38
-
39
- ``` python
40
- from unstructured_client import UnstructuredClient
41
- from unstructured_client.models import shared
42
- from unstructured_client.models.errors import SDKError
43
-
44
- s = UnstructuredClient(api_key_auth = " YOUR_API_KEY" )
38
+ <!-- Start SDK Example Usage [usage] -->
39
+ ## SDK Example Usage
45
40
46
- filename = " _sample_docs/layout-parser-paper-fast.pdf "
41
+ ### Example
47
42
48
- with open (filename, " rb" ) as f:
49
- # Note that this currently only supports a single file
50
- files= shared.Files(
51
- content = f.read(),
52
- file_name = filename,
53
- )
43
+ ``` python
44
+ import unstructured_client
45
+ from unstructured_client.models import operations, shared
54
46
55
- req = shared.PartitionParameters(
56
- files = files,
57
- # Other partition params
58
- strategy = ' ocr_only' ,
59
- languages = [" eng" ],
47
+ s = unstructured_client.UnstructuredClient(
48
+ api_key_auth = " YOUR_API_KEY" ,
60
49
)
61
50
62
- try :
63
- resp = s.general.partition(req)
64
- print (resp.elements[0 ])
65
- except SDKError as e:
66
- print (e)
67
- ```
68
-
69
- Result:
70
-
71
- ```
72
- {
73
- 'type': 'UncategorizedText',
74
- 'element_id': 'fc550084fda1e008e07a0356894f5816',
75
- 'metadata': {
76
- 'filename': 'layout-parser-paper-fast.pdf',
77
- 'filetype': 'application/pdf',
78
- 'languages': ['eng'],
79
- 'page_number': 1
80
- }
81
- }
82
- ```
83
-
84
- ### UnstructuredClient
85
-
86
- #### Change the base URL
87
51
88
- If you are self hosting the API, or developing locally, you can change the server URL when setting up the client.
52
+ res = s.general.partition(request = operations.PartitionRequest(
53
+ partition_parameters = shared.PartitionParameters(
54
+ files = shared.Files(
55
+ content = ' 0x2cC94b2FEF' .encode(),
56
+ file_name = ' your_file_here' ,
57
+ ),
58
+ strategy = shared.Strategy.AUTO ,
59
+ ),
60
+ ))
89
61
90
- ``` python
91
- # Using a local server
92
- s = unstructured_client.UnstructuredClient(
93
- server_url = " http://localhost:8000" ,
94
- api_key_auth = api_key,
95
- )
62
+ if res.elements is not None :
63
+ # handle response
64
+ pass
96
65
97
- # Using your own server
98
- s = unstructured_client.UnstructuredClient(
99
- server_url = " https://your-server" ,
100
- api_key_auth = api_key,
101
- )
102
66
```
67
+ <!-- End SDK Example Usage [usage] -->
103
68
104
- ### PartitionParameters
69
+ Refer to the [ API parameters page ] ( https://docs.unstructured.io/api-reference/api-services/api-parameters ) for all available parameters.
105
70
106
- See the [ general partition ] ( /docs/models/shared/partitionparameters.md ) page for all available parameters.
71
+ ### Configuration
107
72
108
73
#### Splitting PDF by pages
109
74
@@ -122,10 +87,8 @@ req = shared.PartitionParameters(
122
87
split_pdf_concurrency_level = 8
123
88
)
124
89
```
125
- <!-- No SDK Available Operations -->
126
- <!-- No Pagination -->
127
- <!-- No Error Handling -->
128
- <!-- No Server Selection -->
90
+ <!-- Start Retries -->
91
+ <!-- End Retries -->
129
92
130
93
<!-- Start Custom HTTP Client [http-client] -->
131
94
## Custom HTTP Client
@@ -143,40 +106,12 @@ s = unstructured_client.UnstructuredClient(client=http_client)
143
106
```
144
107
<!-- End Custom HTTP Client [http-client] -->
145
108
146
- <!-- No Retries -->
109
+ <!-- No SDK Available Operations -->
110
+ <!-- No Pagination -->
111
+ <!-- No Error Handling -->
112
+ <!-- No Server Selection -->
147
113
<!-- No Authentication -->
148
114
149
- <!-- Start SDK Example Usage [usage] -->
150
- ## SDK Example Usage
151
-
152
- ### Example
153
-
154
- ``` python
155
- import unstructured_client
156
- from unstructured_client.models import operations, shared
157
-
158
- s = unstructured_client.UnstructuredClient(
159
- api_key_auth = " YOUR_API_KEY" ,
160
- )
161
-
162
-
163
- res = s.general.partition(request = operations.PartitionRequest(
164
- partition_parameters = shared.PartitionParameters(
165
- files = shared.Files(
166
- content = ' 0x2cC94b2FEF' .encode(),
167
- file_name = ' your_file_here' ,
168
- ),
169
- strategy = shared.Strategy.AUTO ,
170
- ),
171
- ))
172
-
173
- if res.elements is not None :
174
- # handle response
175
- pass
176
-
177
- ```
178
- <!-- End SDK Example Usage [usage] -->
179
-
180
115
<!-- Placeholder for Future Speakeasy SDK Sections -->
181
116
182
117
### Maturity
0 commit comments