Run automation apps by SDK
With the AI Hub software development kit (SDK), you can write a Python script to upload files and process them with an automation app.
This guide covers the simplest way to run an automation app. In most cases, running a deployment is preferred over running apps directly.
Deployments offer additional features including upstream and downstream integrations, deployment metrics, human review workflows, and secret and configuration management.
To learn about deployments, see Creating deployments. To learn about running deployments programmatically, see the run deployment endpoint. You can also use the API runner tool to generate code samples for running deployments by API.
About the API runner tool...
The AI Hub interface includes an API runner that generates code samples for running deployments by API. The API runner supports a variety of languages, though the generated code samples include basic, required parameters only. Additional parameters are listed in the run deployment API reference.
-
From Workspaces, select the Deploy tab and open the deployment you want to run.
-
Click Run with API. The API runner pane opens.
-
Select a language and variant.
-
Follow the guidance in the interface, selecting your API token, workspace, and other details.
This guide includes a complete script to use as a model for creating your own workflow.
Import modules and initialize the client
Import key Python modules.
Initialize a client that lets you interact with the API through Python objects and methods.
Parameter reference
Upload files to a batch
You can create a batch of files to use as input for your app run. You can add and remove files from the batch, but the batch ID remains constant so you can repeatedly use all files in the batch as app input. For more information, see the batches endpoint.
Below the code you wrote to initialize the client, create a batch with client.batches.create()
and upload files to it with client.batches.add_file()
.
Parameter reference
Process files through an automation app
After uploading your files to a batch, you can process them using an automation app. With the SDK, you can run the app, check the status of your app run, and when the run is complete, get the results. For more information, see the runs endpoints.
This section of the script runs the app with the batch you created as input, checks the status of the app run, and gets the results.
Parameter reference
For more information about customizing an app run, see the run app endpoint.
Complete script
This script combines all the snippets from above and contains all the code needed to run an automation app using the SDK.
The script performs these tasks:
-
Creates a batch object and uploads files to the batch.
-
Runs an automation app using the batch as input.
-
Polls the app run status until the run is complete.
-
Returns app run results as a Python dictionary. See the get run results endpoint for an example of app run results.