Import the Python Alpine API and some other useful packages.
In [1]:
import alpine as AlpineAPI
In [2]:
from pprint import pprint
import json
Have access to a workflow on your Alpine instance that you can run. You'll need a few pieces of information in order to log in and run the workflow. First, find the URL of the open workflow. It should look something like:
https://<AlpineHost>:<PortNum>/#workflows/<WorkflowID>
You'll also need your Alpine username and password.
I've stored my connection information in a configuration file named alpine_login.conf
that looks something like this:
{
"host": "AlpineHost",
"port": "PortNum",
"username": "fakename",
"password": "12345"
}
In [3]:
filename = "alpine_login.conf"
with open(filename, "r") as f:
data = f.read()
conn_info = json.loads(data)
host = conn_info["host"]
port = conn_info["port"]
username = conn_info["username"]
password = conn_info["password"]
Here are the names of a workspace and a workflow within it that we want to run.
In [4]:
test_workspace_name = "API Sample Workspace"
test_workflow_name = "Data ETL"
Create a session and log in the user.
In [5]:
session = AlpineAPI.APIClient(host, port, username, password)
Get information about the Alpine instance.
In [6]:
pprint(session.get_license())
In [7]:
pprint(session.get_version())
Find information about the logged-in user.
In [8]:
pprint(session.get_status())
Find information on all users.
In [9]:
len(session.user.get_list())
Out[9]:
Find your user ID and then use it to update your user data.
In [10]:
user_id = session.user.get_id(username)
In [11]:
pprint(session.user.update(user_id, title = "Assistant to the Regional Manager"))
A similar set of commands can be used to create and update workspaces and the membership of each workspace.
In [12]:
test_workspace_id = session.workspace.get_id(test_workspace_name)
session.workspace.member.add(test_workspace_id, user_id);
In [13]:
workflow_id = session.workfile.get_id(workfile_name = "Data ETL",
workspace_id = test_workspace_id)
process_id = session.workfile.process.run(workflow_id)
session.workfile.process.wait_until_finished(workflow_id = workflow_id,
process_id = process_id,
verbose = True,
query_time = 5)
Out[13]:
We can download results using the download_results
method. The workflow results contain a summary of the output of each operator as well as metadata about the workflow run.
In [14]:
flow_results = session.workfile.process.download_results(workflow_id, process_id)
pprint(flow_results, depth=2)
In [ ]: