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
If you would like to use the Python binding within a Domino workbook session simply include the following line to your project’s requirements.txt file. This will make the Python binding available for each new workbook session (or batch run) started within the project:
You can find Domino’s public Python bindings project here.
Once installed, you can instantiate library either with your API Key or Auth Token File.
Token File: To use Token File to instantiate Python domino, you need to pass the path to this token file, either via class constructor (domino_token_file=<Path to Token file>) or via environment variable.
If you using Python package in code running in 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’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:
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.
1. In case both API Key and Token file are present, default preference will be given to token file. To use API Key instead, unset the (DOMINO_TOKEN_FILE) environment variable
2. 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 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['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")