Skip to content

Commit 76f5fbf

Browse files
authored
Workflow Endpoint: Python SDK - run workflows with local sources (#714)
1 parent f4dd56b commit 76f5fbf

File tree

2 files changed

+106
-38
lines changed

2 files changed

+106
-38
lines changed

api-reference/workflow/overview.mdx

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,13 +1825,6 @@ the `POST` method to call the `/workflows/<workflow-id>/run` endpoint (for `curl
18251825

18261826
<AccordionGroup>
18271827
<Accordion title="Python SDK (remote source and remote destination)">
1828-
<Note>
1829-
If the target workflow was originally created programmatically by the Unstructured Python SDK or with a REST API client such as `curl` or Postman,
1830-
and the workflow uses a local source connector, you can run the workflow only with a REST API client such as `curl` or Postman,
1831-
as described later in this section.
1832-
You cannot run the workflow with the Python SDK or the Unstructured user interface (UI), even though the workflow is visible in the UI.
1833-
</Note>
1834-
18351828
```python
18361829
import os
18371830

@@ -1852,13 +1845,6 @@ the `POST` method to call the `/workflows/<workflow-id>/run` endpoint (for `curl
18521845
```
18531846
</Accordion>
18541847
<Accordion title="Python SDK (async) (remote source and remote destination)">
1855-
<Note>
1856-
If the target workflow was originally created programmatically by the Unstructured Python SDK or with a REST API client such as `curl` or Postman,
1857-
and the workflow uses a local source connector, you can run the workflow only with a REST API client such as `curl` or Postman,
1858-
as described later in this section.
1859-
You cannot run the workflow with the Python SDK or the Unstructured user interface (UI), even though the workflow is visible in the UI.
1860-
</Note>
1861-
18621848
```python
18631849
import os
18641850
import asyncio
@@ -1882,6 +1868,88 @@ the `POST` method to call the `/workflows/<workflow-id>/run` endpoint (for `curl
18821868
asyncio.run(run_workflow())
18831869
```
18841870
</Accordion>
1871+
<Accordion title="Python SDK (local source and local or remote destination)">
1872+
In the following code, replace `</path/to/input/file>` with a relative or absolute path to a local input file for Unstructured to process. You can add multiple files, with one entry per file.
1873+
1874+
```python
1875+
import os
1876+
1877+
from unstructured_client import UnstructuredClient
1878+
from unstructured_client.models.operations import RunWorkflowRequest
1879+
from unstructured_client.models.shared import InputFiles
1880+
1881+
input_files = []
1882+
1883+
for filename in [
1884+
"<path/to/input/file>",
1885+
"<path/to/input/file>"
1886+
]:
1887+
with open(filename, "rb") as f:
1888+
input_files.append(
1889+
InputFiles(
1890+
content=f.read(),
1891+
file_name=filename
1892+
)
1893+
)
1894+
1895+
with UnstructuredClient(api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")) as client:
1896+
response = client.workflows.run_workflow(
1897+
request={
1898+
"workflow_id": "<workflow-id>"
1899+
"body_run_workflow": {
1900+
"input_files": input_files
1901+
}
1902+
}
1903+
)
1904+
1905+
print(response.raw_response)
1906+
```
1907+
1908+
For a local destination, to access the processed files' data, [download a processed local file](#download-a-processed-local-file-from-a-job) from the workflow's job run.
1909+
</Accordion>
1910+
<Accordion title="Python SDK (async) (local source and local or remote destination)">
1911+
In the following code, replace `</path/to/input/file>` with a relative or absolute path to a local input file for Unstructured to process. You can add multiple files, with one entry per file.
1912+
1913+
```python
1914+
import os
1915+
import asyncio
1916+
1917+
from unstructured_client import UnstructuredClient
1918+
from unstructured_client.models.operations import RunWorkflowRequest
1919+
from unstructured_client.models.shared import InputFiles
1920+
1921+
async def run_workflow():
1922+
input_files = []
1923+
1924+
for filename in [
1925+
"<path/to/input/file>",
1926+
"<path/to/input/file>"
1927+
]:
1928+
with open(filename, "rb") as f:
1929+
input_files.append(
1930+
InputFiles(
1931+
content=f.read(),
1932+
file_name=filename
1933+
)
1934+
)
1935+
1936+
with UnstructuredClient(api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")) as client:
1937+
response = client.workflows.run_workflow(
1938+
request={
1939+
"workflow_id": "<workflow-id>"
1940+
"body_run_workflow": {
1941+
"input_files": input_files
1942+
}
1943+
}
1944+
)
1945+
1946+
print(response.raw_response)
1947+
1948+
asyncio.run(run_workflow())
1949+
```
1950+
1951+
For a local destination, to access the processed files' data, [download a processed local file](#download-a-processed-local-file-from-a-job) from the workflow's job run.
1952+
</Accordion>
18851953
<Accordion title="curl (remote source and remote destination)">
18861954
```bash
18871955
curl --request 'POST' --location \

api-reference/workflow/workflows.mdx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ specify the settings for the workflow, as follows:
116116
A workflow with a local source has the following limitations:
117117

118118
- The workflow cannot be set to run on a repeating schedule.
119-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
120-
even though the workflows is visible in the UI. However, you can
121-
run the workflow with REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
119+
- The workflow cannot be run from the Unstructured user interface (UI),
120+
even though the workflow is visible in the UI. However, you can
121+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
122122
</Note>
123123

124124
```python
@@ -198,9 +198,9 @@ specify the settings for the workflow, as follows:
198198
A workflow with a local source has the following limitations:
199199

200200
- The workflow cannot be set to run on a repeating schedule.
201-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
202-
even though the workflows is visible in the UI. However, you can
203-
run the workflow with REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
201+
- The workflow cannot be run from the Unstructured user interface (UI),
202+
even though the workflow is visible in the UI. However, you can
203+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
204204
</Note>
205205

206206
```python
@@ -363,9 +363,9 @@ specify the settings for the workflow, as follows:
363363
A workflow with a local source has the following limitations:
364364

365365
- The workflow cannot be set to run on a repeating schedule.
366-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
367-
even though the workflows is visible in the UI. However, you can
368-
run the workflow with REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
366+
- The workflow cannot be run from the Unstructured user interface (UI),
367+
even though the workflow is visible in the UI. However, you can
368+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
369369
</Note>
370370

371371
```python
@@ -449,9 +449,9 @@ specify the settings for the workflow, as follows:
449449
A workflow with a local source has the following limitations:
450450

451451
- The workflow cannot be set to run on a repeating schedule.
452-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
453-
even though the workflows is visible in the UI. However, you can
454-
run the workflow with REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
452+
- The workflow cannot be run from the Unstructured user interface (UI),
453+
even though the workflow is visible in the UI. However, you can
454+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` or Postman. [Learn how](/api-reference/workflow/overview#run-a-workflow).
455455
</Note>
456456

457457
```python
@@ -565,9 +565,9 @@ specify the settings for the workflow, as follows:
565565
A workflow with a local source has the following limitations:
566566

567567
- The workflow cannot be set to run on a repeating schedule.
568-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
569-
even though the workflows is visible in the UI. However, you can
570-
run the workflow with REST API clients such as `curl` (or Postman). [Learn how](/api-reference/workflow/overview#run-a-workflow).
568+
- The workflow cannot be run from the Unstructured user interface (UI),
569+
even though the workflow is visible in the UI. However, you can
570+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` (or Postman). [Learn how](/api-reference/workflow/overview#run-a-workflow).
571571
</Note>
572572

573573
```bash
@@ -602,9 +602,9 @@ specify the settings for the workflow, as follows:
602602
A workflow with a local source has the following limitations:
603603

604604
- The workflow cannot be set to run on a repeating schedule.
605-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
606-
even though the workflows is visible in the UI. However, you can
607-
run the workflow with REST API clients such as `curl` (or Postman). [Learn how](/api-reference/workflow/overview#run-a-workflow).
605+
- The workflow cannot be run from the Unstructured user interface (UI),
606+
even though the workflow is visible in the UI. However, you can
607+
run the workflow with the Unstructured Python SDK, or REST API clients such as `curl` (or Postman). [Learn how](/api-reference/workflow/overview#run-a-workflow).
608608
</Note>
609609

610610
```bash
@@ -680,9 +680,9 @@ specify the settings for the workflow, as follows:
680680
A workflow with a local source has the following limitations:
681681

682682
- The workflow cannot be set to run on a repeating schedule.
683-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
684-
even though the workflows is visible in the UI. However, you can
685-
run the workflow with REST API clients such as Postman (or `curl`). [Learn how](/api-reference/workflow/overview#run-a-workflow).
683+
- The workflow cannot be run from the Unstructured user interface (UI),
684+
even though the workflow is visible in the UI. However, you can
685+
run the workflow with the Unstructured Python SDK, or REST API clients such as Postman (or `curl`). [Learn how](/api-reference/workflow/overview#run-a-workflow).
686686
</Note>
687687

688688
1. In the method drop-down list, select **POST**.
@@ -728,9 +728,9 @@ specify the settings for the workflow, as follows:
728728
A workflow with a local source has the following limitations:
729729

730730
- The workflow cannot be set to run on a repeating schedule.
731-
- The workflow cannot be run with the Unstructured Python SDK or from the Unstructured user interface (UI),
732-
even though the workflows is visible in the UI. However, you can
733-
run the workflow with REST API clients such as Postman (or `curl`). [Learn how](/api-reference/workflow/overview#run-a-workflow).
731+
- The workflow cannot be run from the Unstructured user interface (UI),
732+
even though the workflow is visible in the UI. However, you can
733+
run the workflow with the Unstructured Python SDK, or REST API clients such as Postman (or `curl`). [Learn how](/api-reference/workflow/overview#run-a-workflow).
734734
</Note>
735735

736736
1. In the method drop-down list, select **POST**.

0 commit comments

Comments
 (0)