The Python binding for the Domino API is available in PyPI:
pip install dominodatalab
If you want to use the Python binding in a Domino workbook session include dominodatalab
in your project’s requirements.txt file.
This makes the Python binding available for each new workbook session (or batch run) started within the project.
-e git+https://github.com/dominodatalab/python-domino.git#egg=domino
Tip
|
Full documentation for this API is forthcoming. For more information now, see Domino’s public Python bindings project. |
If you are using Python package in code that is already running in Domino, the DOMINO_TOKEN_FILE
will be set automatically to be the token file for the user who started the run.
API Key: You must get your API key from your account page. To get your API Key, log into Domino and click your name in the menu. Click Account Settings and select API Key. 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
|
|
The following 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")