Package: dominodatalab
This library provides bindings for the Domino APIs.  It ships with the Domino Standard Environment (DSE).See this documentation for details about the APIs:Latest public Domino
APIsLegacy APIsThe latest released version ofpython-dominois1.3.0.Version compatibility matrixThepython-dominolibrary is compatible with different versions of
Domino:Domino VersionsPython-Domino3.6.x or lower0.3.54.1.0 or higher1.0.0or Higher5.3.0 or higher[1.2.0]https://github.com/dominodatalab/python-domino/archive/refs/tags/Release-1.2.0.zip) or Higher5.5.0 or higher1.2.2or Higher5.10.0 or higher1.3.0or HigherDevelopmentThe currentpython-dominois based on Python 3.9, which is therefore recommended for development.Pipenvis also recommended to manage the dependencies.To use the Python binding in a Domino workbook session, includedominodatalabin your project's requirements.txt file.
This makes the Python binding available for each new workbook session (or batch run) started within the project.To install dependencies fromsetup.pyfor development:pipenv install -e ".[dev]"Use the same process for Airflow and data:pipenv install -e ".[data]" ".[airflow]"Set up the connectionYou can set up the connection by creating a new instance ofDomino:_class_ Domino(project, api_key=None, host=None, domino_token_file=None, auth_token=None)project:A project identifier (in the form of ownerusername/projectname).api_proxy:(Optional) Location of the Domino API reverse proxy as host:port.If set, this proxy is used to intercept any Domino API requests and insert an authentication token.This is the preferred method of authentication.
Alternatively, set theDOMINO_API_PROXYenvironment variable.
In Domino 5.4.0 or later, this variable is set inside a Domino run container.NOTE: This mechanism does not work when connecting to an HTTPS endpoint; it is meant to be used inside Domino runs.api_key:(Optional) An API key to authenticate with.If not provided, the library expects to find one in theDOMINO_USER_API_KEYenvironment variable.
If you are using the Python package in code that is already running in Domino, theDOMINO_API_USER_KEYvariable is set automatically to be the key for the user who started the run.host:(Optional) A host URL.If not provided, the library expects to find one in theDOMINO_API_HOSTenvironment variable.domino_token_file:(Optional) Path to the Domino token file
containing the auth token.If not provided, the library expects to find one in theDOMINO_TOKEN_FILEenvironment variable.
If you are using Python package in code that is already running in Domino, theDOMINO_TOKEN_FILEis set automatically to be the token file for the user who started the run.auth_token:(Optional) Authentication token.AuthenticationDomino looks for the authentication method in the following order and uses the first one it finds:api_proxyauth_tokendomino_token_fileapi_keyDOMINO_API_PROXYDOMINO_TOKEN_FILEDOMINO_USER_API_KEYThe API proxy is the preferred method of authentication.
SeeUse the API Proxy to Authenticate Calls to the Domino API.Additional environment variablesDOMINO_LOG_LEVELThe default log level isINFO.
You can change the log level by settingDOMINO_LOG_LEVEL, for example toDEBUG.DOMINO_VERIFY_CERTIFICATEFor testing purposes and issues with SSL certificates, setDOMINO_VERIFY_CERTIFICATEtofalse.
Be sure to unset this variable when not in use.MethodsProjectsSeeexample_projects_usage.pyfor example code.project_create(project_name, owner_username=None)Create a new project with given project name.project_name:The name of the project.owner_username:(Optional) The owner username for the project.
This parameter is useful when you need to create a project under an
organization.collaborators_get()Get the list of collaborators on a project.collaborators_add(username_or_email, message="")Add collaborators to a project.username_or_email:Name or email of the Domino user to add as
collaborator to the current project.message:Optional - Message related to the user’s role or purpose
to the project.Project tagsProject tags are an easy way to add freeform metadata to a project. Tags
help colleagues and consumers organize and find the Domino projects that
interest them. Tags can be used to describe the subject explored by a
project, the packages and libraries it uses, or the source of the data
within.Seeexample_projects_usage.pyfor example code.tags_list(*project_id)List a project’s tags.project_id:The project identifier.tag_details(tag_id)Get details about a tag.tag_id:The tag identifier.tags_add(tags, *project_id)Create a tag, if it does not exist, and add it to a project.tags (list):One or more tag names.project_id:(Defaults to current project ID) The project
identifier.tag_get_id(tag_name, *project_id)Get the tag ID using the tag string name.tag_name (string):The tag name.project_id:(Defaults to current project id) The project ID.tags_remove(tag_name, project_id=None)Remove a tag from a project.tag_name (string):The tag name.project_id:(Defaults to current project id) The project ID.ExecutionsSee these code example files:start_run_and_check_status.pyexport_runs.pyruns_list()List the executions on the selected project.runs_start(command, isDirect, commitId, title, tier, publishApiEndpoint)Start a new execution on the selected project.command:The command to execution as an array of strings where
members of the array represent arguments of the command. For
example:["main.py", "hi mom"]isDirect:(Optional) Whether this command should be passed
directly to a shell.commitId:(Optional) ThecommitIdto launch from. If not
provided, the project launches from the latest commit.title:(Optional) A title for the execution.tier:(Optional) The hardware tier to use for the execution. This
is the human-readable name of the hardware tier, such as "Free",
"Small", or "Medium". If not provided, the project’s default tier is
used.publishApiEndpoint:(Optional) Whether to publish an API endpoint
from the resulting output.runs_start_blocking(command, isDirect, commitId, title, tier, publishApiEndpoint, poll_freq=5, max_poll_time=6000)Start a new execution on the selected project and make a blocking
request that waits until job is finished.command:The command to execution as an array of strings where
members of the array represent arguments of the command. For
example:["main.py", "hi mom"]isDirect:(Optional) Whether this command should be passed
directly to a shell.commitId:(Optional) ThecommitIdto launch from. If not
provided, the project launches from the latest commit.title:(Optional) A title for the execution.tier:(Optional) The hardware tier to use for the execution. Will
use project’s default tier if not provided. If not provided, the
project’s default tier is used.publishApiEndpoint:(Optional) Whether to publish an API endpoint
from the resulting output.poll_freq:(Optional) Number of seconds between polling of the
Domino server for status of the task that is running.max_poll_time:(Optional) Maximum number of seconds to wait for
a task to complete. If this threshold is exceeded, an exception is
raised.retry_count:(Optional) Maximum number of polling retries (in
case of transient HTTP errors). If this threshold is exceeded, an
exception is raised.run_stop(runId, saveChanges=True):Stop an existing execution in the selected project.runId:String that identifies the execution.saveChanges:(Defaults to True) If false, execution results are
discarded.runs_stdout(runId)Getstdoutemitted by a particular execution.runId:string that identifies the executionFiles and blobsSee these code example files:upload_file.pyupload_and_run_file_and_download_results.pyfiles_list(commitId, path)List the files in a folder in the Domino project.commitId:ThecommitIdto list files from.path:(Defaults to "/") The path to list from.files_upload(path, file)Upload a Python file object into the specified path inside the project.
Seeexamples/upload_file.pyfor an example. All parameters are
required.path:The path to save the file to. For example,/README.mdwrites to the root directory of the project while/data/numbers.csvsaves the file to a sub folder nameddata. If
the specified folder does not yet exist, it is created.file:A Python file object. For example:f = open("authors.txt","rb")blobs_get(key)DeprecatedRetrieve a file from the Domino server by blob key. Use blobs_get_v2(path, commit_id, project_id) instead.key:The key of the file to fetch from the blob server.blobs_get_v2(path, commit_id, project_id)Retrieve a file from the Domino server in a project from its path and commit id.path:The path to the file in the Domino project.commit_id:ID of the commit to retrieve the file from.project_id:ID of the project to retrieve the file from.Appsapp_publish(unpublishRunningApps=True, hardwareTierId=None)Publish an app within a project, or republish an existing app.unpublishRunningApps:(Defaults to True) Check for an active app
instance in the current project and unpublish it before
re/publishing.hardwareTierId:(Optional) Launch the app on the specified
hardware tier.app_unpublish()Stop the running app in the project.Jobsjob_start(command, commit_id=None, hardware_tier_name=None, environment_id=None, on_demand_spark_cluster_properties=None, compute_cluster_properties=None, external_volume_mounts=None, title=None):Start a new job (execution) in the project.command (string):Command to execute in Job. For example:domino.job_start(command="main.py arg1 arg2")commit_id (string):(Optional) ThecommitIdto launch from. If
not provided, the job launches from the latest commit.hardware_tier_name (string):(Optional) The hardware tier NAME
to launch job in. If not provided, the project’s default tier is
used.environment_id (string):(Optional) The environment ID with which
to launch the job. If not provided, the project’s default
environment is used.on_demand_spark_cluster_properties (dict):(Optional) On
demand spark cluster properties. The following properties can be
provided in the Spark cluster:{
    "computeEnvironmentId": "<Environment ID configured with spark>"
    "executorCount": "<Number of Executors in cluster>"
     (optional defaults to 1)
    "executorHardwareTierId": "<Hardware tier ID for Spark Executors>"
     (optional defaults to last used historically if available)
    "masterHardwareTierId":  "<Hardware tier ID for Spark master"
     (optional defaults to last used historically if available)
    "executorStorageMB": "<Executor's storage in MB>"
     (optional defaults to 0; 1GB is 1000MB Here)
}param compute_cluster_properties (dict):(Optional) The
compute-cluster properties definition contains parameters for
launching any Domino supported compute cluster for a job. Use this
to launch a job that uses a compute-cluster instead of the
deprecatedon_demand_spark_cluster_propertiesfield. Ifon_demand_spark_cluster_propertiesandcompute_cluster_propertiesare both present,on_demand_spark_cluster_propertiesis ignored.compute_cluster_propertiescontains the following fields:{
    "clusterType": <string, one of "Ray", "Spark", "Dask", "MPI">,
    "computeEnvironmentId": <string, The environment ID for the cluster's nodes>,
    "computeEnvironmentRevisionSpec": <one of "ActiveRevision", "LatestRevision",
    {"revisionId":"<environment_revision_id>"} (optional)>,
    "masterHardwareTierId": <string, the Hardware tier ID for the cluster's master node (required unless clusterType is MPI)>,
    "workerCount": <number, the total workers to spawn for the cluster>,
    "workerHardwareTierId": <string, The Hardware tier ID for the cluster workers>,
    "workerStorage": <{ "value": <number>, "unit": <one of "GiB", "MB"> },
    The disk storage size for the cluster's worker nodes (optional)>
    "maxWorkerCount": <number, The max number of workers allowed. When
    this configuration exists, autoscaling is enabled for the cluster and
    "workerCount" is interpreted as the min number of workers allowed in the cluster
    (optional)>
}external_volume_mounts (List[string]):(Optional) External
volume mount IDs to mount to execution. If not provided, the job
launches with no external volumes mounted.*title (string): (Optional) Title for Job.job_stop(job_id, commit_results=True):Stop the Job (execution) in the project.job_id (string):Job identifier.commit_results (boolean):(Defaults totrue) Iffalse, the
job results are not committed.job_status(job_id):Get the status of a job.job_id (string):Job identifier.job_start_blocking(poll_freq=5, max_poll_time=6000, **kwargs):Start a job and poll until the job is finished. Additionally, this
method supports all the parameters in thejob_startmethod.poll_freq:Poll frequency interval in seconds.max_poll_time:Max poll time in seconds.DatasetsA Domino dataset is a collection of files that are available in user
executions as a filesystem directory. A dataset always reflects the most
recent version of the data. You can modify the contents of a dataset
through the Domino UI or through workload executions.SeeDomino
Datasetsfor more details, andexample_dataset.pyfor example code.datasets_list(project_id=None)Provide a JSON list of all the available datasets.project_id (string):(Defaults to None) The project identifier.
Each project can hold up to 5 datasets.datasets_ids(project_id)List the IDs the datasets for a particular project.project_id:The project identifier.datasets_names(project_id)List the names the datasets for a particular project.project_id:The project identifier.datasets_details(dataset_id)Provide details about a dataset.dataset_id:The dataset identifier.datasets_create(dataset_name, dataset_description)Create a new dataset.dataset_name:Name of the new dataset. NOTE: The name must be
unique.dataset_description:Description of the dataset.datasets_update_details(dataset_id, dataset_name=None, dataset_description=None)Update a dataset’s name or description.dataset_id:The dataset identifier.dataset_name:(Optional) New name of the dataset.dataset_description:(Optional) New description of the dataset.datasets_remove(dataset_ids)Delete a set of datasets.dataset_ids (list[string]):List of IDs of the datasets to
delete. NOTE: Datasets are first marked for deletion, then deleted
after a grace period (15 minutes, configurable). A Domino admin may
also need to complete this process before the name can be reused.datasets_upload_files(dataset_id, local_path_to_file_or_directory, file_upload_setting, max_workers, target_chunk_size, target_relative_path)Uploads a file or entire directory to a dataset.dataset_id:The dataset identifier.local_path_to_file_or_directory:The path to the file or directory in local machine.file_upload_setting:The setting to resolve naming conflict, must be one ofOverwrite,Rename,Ignore(default).max_workers:The max amount of threads (default: 10).target_chunk_size:The max chunk size for multipart upload (default: 8MB).target_relative_path:The path on the dataset to upload the file or directory to. Note that the path must exist or the upload will fail.AirflowThepython-dominoclient comes bundled with anOperatorfor use withApache Airflowas an extra.When installing the client from PyPI, add theairflowflag to extras:pip install "dominodatalab[airflow]"Similarly, when installing the client from GitHub, use the following
command:pip install -e git+https://github.com/dominodatalab/python-domino.git@1.0.6#egg="dominodatalab[airflow]"See alsoexample_airflow_dag.pyfor example code.DominoOperatorfrom domino.airflow import DominoOperatorAllows a user to schedule Domino executions via Airflow. Follows the
same function signature asdomino.runs_startwith two extra arguments:startup_delay: Optional[int] = 10| Add a startup delay to your job, useful if you want to delay execution until after other work finishes.include_setup_log: Optional[bool] = True| Determine whether or not to publish the setup log of the job as the log prefix beforestdout.DominoSparkOperatorfrom domino.airflow import DominoSparkOperatorAllows a user to schedule Domino executions via the v4 API, which
supportsonDemandSparkClusters. Follows the same function signature asdomino.job_start, with the addition ofstartup_delayfrom above.Examplefrom 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")Manual installationBecausepython-dominoships with the DSE, normally you do not need to install it.This section provides instructions for installing it in another environment or updating it to a newer version.Starting from version1.0.6,python-dominois available on PyPI asdominodatalab:pip install dominodatalabIf you are adding install instructions forpython-dominoto yourDomino EnvironmentDockerfile Instructions field, you must addRUNto the beginning:RUN pip install dominodatalabTo install a specific version of the library from PyPI, such as1.0.6:pip install dominodatalab==1.0.6To install a specific version of the library from GitHub, such as1.0.6:pip install https://github.com/dominodatalab/python-domino/archive/1.0.6.zipLicenseThis library is made available under the Apache 2.0 License. This is an
open-source project ofDomino Data Lab.