> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Wrapper for Domino API

The Python binding for the Domino API is available in PyPI:

```shell theme={null}
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](/cloud/platform-capabilities/core-concepts/compute-environments/add-packages-to-environments/use-requirements-txt). This makes the Python binding available for each new workbook session (or batch run) started within the project.

<Tip>
  Full documentation for this API is forthcoming. For more information now, see [Domino’s public Python bindings project](https://github.com/dominodatalab/python-domino).
</Tip>

**In existing deployments**

After installation, you can instantiate a library either with your API Key or Auth Token File.

**Token File:** To use Token File to instantiate Python Domino, pass the path to this token file, either through class constructor (`domino_token_file=<Path to Token file>`) or through an environment variable.

```python theme={null}
export DOMINO_TOKEN_FILE=PATH_TO_DOMINO_TOKEN_FILE
```

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:

```python theme={null}
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>
  * If both the API Key and Token files are present, default preference will be given to the Token file. To use the API Key file instead, clear the `DOMINO_TOKEN_FILE` environment variable.

  * See the [Domino Platform API Reference](/cloud/reference/api/domino-open-api) for more detail.
</Note>

The following is an example of usage:

```python theme={null}
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")
```

**In new deployments**

Domino updated the Python library to work with the API Proxy inside the execution. If the library is instantiated without any authentication arguments, it will detect the API Proxy (see the `DOMINO_API_PROXY` environment variable) and route the calls through it automatically. If you explicitly specify other means of authentication (`domino_token`, `domino_token_file`, `api_key`), it will work exactly like it did previously.

See [Use API Proxy to Authenticate Calls to the Domino API](/cloud/reference/api/domino-api-authentication).
