Follow

Python Wrapper for Domino API

The Python binding for the Domino API is installable via pip:

pip install git+https://github.com/dominodatalab/python-domino.git

You can find Domino's public Python bindings project here.

Once installed, you'll need to get your API key from your account page. To get your API Key, log into Domino and click on your name on the right hand side of the top menu. Select Account Settings and select the API Key option from the left hand menu. Copy the API key to your clipboard.  

The Python library will read this key from environment variables, so set it as follows in your shell:

export DOMINO_USER_API_KEY=YOUR_API_KEY

If you are using the Python package in code that is already running in Domino, the DOMINO_API_USER_KEY variable will be set automatically to be the key for the user who started the run.

Note: documentation for the Domino REST API can be accessed here

Here is an example of usage:

from domino import Domino

# By and large your commands will run against a single project,
# so you must specify the full project name
domino = Domino("chris/canon")

# List all runs in the project, most-recently queued first
all_runs = domino.runs_list()['data']

latest_100_runs = all_runs[0:100]

print(latest_100_runs)

# all runs have a commitId (the snapshot of the project when the
# run starts) and, if the run completed, an "outputCommitId"
# (the snapshot of the project after the run completed)
most_recent_run = all_runs[0]

commitId = most_recent_run['outputCommitId']

# list all the files in the output commit ID -- only showing the
# entries under the results directory.  If not provided, will
# list all files in the project.  Or you can say path=“/“ to
# list all files
files = domino.files_list(commitId, path='results/')['data']

for file in files:
print file['path'], '->', file['url']

print(files)

# Get the content (i.e. blob) for the file you're interested in.
# blobs_get returns a connection rather than the content, because
# the content can get quite large and it’s up to you how you want
# to handle it
print(domino.blobs_get(files[0]['key']).read())

# Start a run of file main.py using the latest copy of that file
domino.runs_start(["main.py", "arg1", "arg2"])

# Start a "direct" command
domino.runs_start(["echo 'Hello, World!'"], isDirect=True)

# Start a run of a specific commit
domino.runs_start(["main.py"], commitId="aabbccddee")
Was this article helpful?
0 out of 0 found this helpful

Comments