Skip to content

Commit 85b9c8a

Browse files
authored
Workflow Endpoint: Python SDK - how to download job output for workflow with local destination (#719)
1 parent 383d346 commit 85b9c8a

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

api-reference/workflow/overview.mdx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ the `POST` method to call the `/workflows/<workflow-id>/run` endpoint (for `curl
19341934
)
19351935

19361936
with UnstructuredClient(api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")) as client:
1937-
response = client.workflows.run_workflow(
1937+
response = client.workflows.run_workflow_async(
19381938
request={
19391939
"workflow_id": "<workflow-id>"
19401940
"body_run_workflow": {
@@ -2779,10 +2779,66 @@ response:
27792779
- The ID for the file to download is in the `output_node_files` array's `file_id` field.
27802780
- The ID for the workflow's output node is in the `output_node_files` array's `node_id` field.
27812781

2782-
Currently, you cannot use the Unstructured user interface (UI) or the Unstructured Python SDK to download a file from a job that uses a
2782+
Currently, you cannot use the Unstructured user interface (UI) to download a file from a job that uses a
27832783
workflow with a local source and a local destination.
27842784

27852785
<AccordionGroup>
2786+
<Accordion title="Python SDK">
2787+
```python
2788+
import os
2789+
import json
2790+
2791+
from unstructured_client import UnstructuredClient
2792+
from unstructured_client.models.operations import DownloadJobOutputRequest
2793+
2794+
client = UnstructuredClient(
2795+
api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")
2796+
)
2797+
2798+
response = client.jobs.download_job_output(
2799+
request=DownloadJobOutputRequest(
2800+
job_id="<job-id>",
2801+
file_id="<file-id>",
2802+
node_id="<node-id>"
2803+
)
2804+
)
2805+
2806+
output_path = "</path/to/save/json/output/file>"
2807+
2808+
with open(output_path, "w") as f:
2809+
json.dump(response.any, f, indent=4)
2810+
```
2811+
</Accordion>
2812+
<Accordion title="Python SDK (async)">
2813+
```python
2814+
import os
2815+
import json
2816+
import asyncio
2817+
2818+
from unstructured_client import UnstructuredClient
2819+
from unstructured_client.models.operations import DownloadJobOutputRequest
2820+
2821+
async def download_job_output():
2822+
client = UnstructuredClient(
2823+
api_key_auth=os.getenv("UNSTRUCTURED_API_KEY")
2824+
)
2825+
2826+
response = client.jobs.download_job_output_async(
2827+
request=DownloadJobOutputRequest(
2828+
job_id="<job-id>",
2829+
file_id="<file-id>",
2830+
node_id="<node-id>"
2831+
)
2832+
)
2833+
2834+
output_path = "</path/to/save/json/output/file>"
2835+
2836+
with open(output_path, "w") as f:
2837+
json.dump(response.any, f, indent=4)
2838+
2839+
asyncio.run(download_job_output())
2840+
```
2841+
</Accordion>
27862842
<Accordion title="curl">
27872843
```bash
27882844
curl --request 'GET' --location \

0 commit comments

Comments
 (0)