@@ -29,15 +29,23 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
29
29
30
30
## Basics
31
31
32
- <Note >
32
+ <Warning >
33
+ The TypeScript SDK has the following breaking changes in v0.11.0:
34
+ * Imports under the ` dist ` path have moved up a level
35
+ * Enums are now used for parameters with a set of options
36
+ * This includes ` chunkingStrategy ` , ` outputFormat ` , and ` strategy `
37
+ * All parameters to ` partition ` have moved to a ` partitionParameters ` object
38
+ </Warning >
39
+
40
+ <Warning >
33
41
Python SDK Deprecation Warning (>v0.22.0): The legacy method of passing ` shared.PartitionParameters `
34
42
directly to ` client.general.partition() ` is currently supported but may be deprecated and
35
43
could break in future releases. Users should migrate to the new ` shared.PartitionRequest ` object
36
44
to ensure compatibility with future updates.
37
- </Note >
45
+ </Warning >
38
46
39
47
<Note >
40
- Currently, the clients only support sending one file at a time.
48
+ Currently, the SDKs only support sending one file at a time.
41
49
</Note >
42
50
43
51
Let's start with a simple example in which you send a pdf document to be partitioned via the free Unstructured API:
@@ -77,30 +85,43 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
77
85
pass
78
86
```
79
87
``` javascript TypeScript
80
- import { openAsBlob } from " node:fs" ;
81
88
import { UnstructuredClient } from " unstructured-client" ;
82
- import { Strategy , ChunkingStrategy } from " unstructured-client/sdk/models/shared" ;
89
+ import { PartitionResponse } from " unstructured-client/sdk/models/operations" ;
90
+ import { Strategy } from " unstructured-client/sdk/models/shared" ;
91
+ import * as fs from " fs" ;
92
+
93
+ const key = " ${apiKey}" ;
83
94
84
95
const client = new UnstructuredClient ({
85
- security: { apiKeyAuth: " YOUR_API_KEY" },
86
- // You only need to provide your unique API URL if using the SaaS Unstructured API
87
- // serverURL: "YOUR_API_URL",
96
+ serverURL: " ${apiUrl}" ,
97
+ security: {
98
+ apiKeyAuth: key,
99
+ },
88
100
});
89
101
90
- async function run () {
91
- const res = await client .general .partition ({
92
- partitionParameters: {
93
- files: await openAsBlob (" sample-docs/layout-parser-paper.pdf" ),
94
- strategy: Strategy .Auto ,
95
- languages: [' eng' ],
96
- },
97
- });
98
-
99
- // Handle the response
100
- console .log (res)
101
- }
102
+ const filename = " PATH_TO_FILE" ;
103
+ const data = fs .readFileSync (filename);
102
104
103
- run ();
105
+ client .general .partition ({
106
+ partitionParameters: {
107
+ files: {
108
+ content: data,
109
+ fileName: filename,
110
+ },
111
+ strategy: Strategy .Fast ,
112
+ }
113
+ }).then ((res : PartitionResponse ) => {
114
+ if (res .statusCode == 200 ) {
115
+ console .log (res .elements );
116
+ }
117
+ }).catch ((e ) => {
118
+ if (e .statusCode ) {
119
+ console .log (e .statusCode );
120
+ console .log (e .body );
121
+ } else {
122
+ console .log (e);
123
+ }
124
+ });
104
125
```
105
126
``` python Python (SDK <=v0.22.0)
106
127
import unstructured_client
@@ -137,26 +158,36 @@ deployment of Unstructured API, you can access the API using the Python or TypeS
137
158
import { PartitionResponse } from " unstructured-client/dist/sdk/models/operations" ;
138
159
import * as fs from " fs" ;
139
160
140
- const key = " YOUR_API_KEY " ;
161
+ const key = " ${apiKey} " ;
141
162
142
163
const client = new UnstructuredClient ({
143
- security: { apiKeyAuth: " YOUR_API_KEY" },
144
- // You only need to provide your unique API URL if using the SaaS Unstructured API
145
- // serverURL: "YOUR_API_URL",
164
+ serverURL: " ${apiUrl}" ,
165
+ security: {
166
+ apiKeyAuth: key,
167
+ },
146
168
});
147
169
148
- const filename = " sample-docs/layout-parser-paper.pdf " ;
170
+ const filename = " PATH_TO_FILE " ;
149
171
const data = fs .readFileSync (filename);
150
172
151
173
client .general .partition ({
152
174
files: {
153
175
content: data,
154
176
fileName: filename,
155
177
},
156
- // Other partition params
157
- strategy: " auto" ,
158
- languages: [' eng' ],
159
- })
178
+ strategy: ' fast'
179
+ }).then ((res : PartitionResponse ) => {
180
+ if (res .statusCode == 200 ) {
181
+ console .log (res .elements );
182
+ }
183
+ }).catch ((e ) => {
184
+ if (e .statusCode ) {
185
+ console .log (e .statusCode );
186
+ console .log (e .body );
187
+ } else {
188
+ console .log (e);
189
+ }
190
+ });
160
191
```
161
192
</CodeGroup >
162
193
0 commit comments