# Host applications with DRApps
URL: https://docs.datarobot.com/en/docs/wb-apps/custom-apps/host-custom-app.html

> Host an application, such as a Streamlit app, in DataRobot using a DataRobot execution environment.

# Host applications with DRApps

DRApps is a simple command line interface (CLI) providing the tools required to host an application, such as a Streamlit app, in DataRobot using a DataRobot execution environment. This allows you to run apps without building your own Docker image. Applications don't provide any storage; however, you can access the full DataRobot API and other services. Alternatively, you can [upload an AI App (Classic)](https://docs.datarobot.com/en/docs/classic-ui/app-builder/custom-apps/app-upload-custom.html) or an [application (NextGen)](https://docs.datarobot.com/en/docs/classic-ui/app-builder/custom-apps/index.html) in a Docker container.

> [!NOTE] Paused applications
> Applications are paused after a period of inactivity. The first time you access a paused application, a loading screen appears while it restarts.

## Install the DRApps CLI tool

To install the DRApps CLI tool, run either of the following commands:

**Users:**
```
pip install git+https://github.com/datarobot/dr-apps
```

**Contributors:**
First, clone the [dr-apps repository](https://github.com/datarobot/dr-apps/tree/main), then, run:

```
python setup.py install
```


## Use the DRApps CLI

After you install the DRApps CLI tool, you can use the `drapps --help` command to access the following information:

```
$ drapps --help     
Usage: drapps [OPTIONS] COMMAND [ARGS]...

  CLI tools for applications.

  You can use drapps COMMAND --help for getting more info about a command.

Options:
  --help  Show this message and exit.

  Commands:
    create          Creates new custom application from docker image or...
    create-env      Creates an execution environment and a first version.
    external-share  Share a custom application with a user.
    logs            Provides logs for custom application.
    ls              Provides list of custom applications or execution...
    publish         Updates a custom application.
    revert-publish  Reverts updates to a custom application.
    terminate       Stops custom application and removes it from the list.
```

Additionally, you can use `--help` for each command listed on this page.

### create command

Creates a new application from  a pre-built image (the output of `docker build` and `docker save`). If the application is created from a project folder, the application image is created or the existing application is updated. For more information, use the `drapps create --help` command:

```
$ drapps create --help
Usage: drapps create [OPTIONS] APPLICATION_NAME

  Creates a new custom application from  a pre-built image (the output of docker build and docker save).

Options:
  -t, --token TEXT      Pubic API access token. You can use
                        DATAROBOT_API_TOKEN env instead.
  -E, --endpoint TEXT   DataRobot Public API endpoint. You can use
                        DATAROBOT_ENDPOINT instead. Default:
                        https://app.datarobot.com/api/v2
  -e, --base-env TEXT   Name or ID for execution environment.
  -p, --path DIRECTORY  Path to folder with files that should be uploaded.
  -i, --image FILE      Path to tar archive with custom application docker
                        images.
  --skip-wait           Do not wait for ready status.
  --help                Show this message and exit.
```

More detailed descriptions for each argument are provided in the table below:

| Argument | Description |
| --- | --- |
| APPLICATION_NAME | Enter the name of your application. This name is also used to generate the name of the application image, adding the Image suffix. |
| --token | Enter your API Key, found on the API keys and tools page of your DataRobot account. You can also provide your API Key using the DATAROBOT_API_TOKEN environment variable. |
| --endpoint | Enter the URL for the DataRobot Public API. The default value is https://app.datarobot.com/api/v2. You can also provide the URL to Public API using the DATAROBOT_ENDPOINT environment variable. |
| --base-env | Enter the UUID or name of execution environment used as base for your Streamlit app. The execution environment contains the libraries and packages required by your application. You can find list of available environments in the Custom Model Workshop on the Environments page. For a custom Streamlit application, use --base-env '[DataRobot] Python 3.9 Streamlit'. |
| --path | Enter the path to a folder used to create the application. Files from this folder are uploaded to DataRobot and used to create the application image. The application is started from this image. To use the current working directory, use --path .. |
| --image | Enter the path to an archive containing an application docker image. You can save your docker image to file with the docker save <image_name> > <file_name>.tar command. |
| --skip-wait | Enables exiting the script immediately after the application creation request is sent, without waiting until the application setup completes. |

### logs command

Returns the logs generated for an application. For more information, use the `drapps logs --help` command:

```
$ drapps logs --help
Usage: drapps logs [OPTIONS] APPLICATION_ID_OR_NAME

  Provides logs for custom application.

Options:
  -t, --token TEXT     Pubic API access token. You can use
                       DATAROBOT_API_TOKEN env instead.
  -E, --endpoint TEXT  DataRobot Public API endpoint. You can use
                       DATAROBOT_ENDPOINT instead. Default:
                       https://app.datarobot.com/api/v2
  -f, --follow         Output append data as new log records appear.
  --help               Show this message and exit.
```

| Argument | Description |
| --- | --- |
| APPLICATION_ID_OR_NAME | Enter the ID or the name of an application for which you want to view the logs. |
| --token | Enter your API Key, found on the API keys and tools page of your DataRobot account. You can also provide your API Key using the DATAROBOT_API_TOKEN environment variable. |
| --endpoint | Enter the URL for the DataRobot Public API. The default value is https://app.datarobot.com/api/v2. You can also provide the URL to Public API using the DATAROBOT_ENDPOINT environment variable. |
| --follow | Enables the script to continue checking for new log records to display as they appear. |

### ls command

Returns a list of applications or execution environments. For more information, use the `drapps ls --help` command:

```
$ drapps ls --help
Usage: drapps ls [OPTIONS] {apps|envs}

  Provides list of custom applications or execution environments.

Options:
  -t, --token TEXT     Pubic API access token. You can use
                       DATAROBOT_API_TOKEN env instead
  -E, --endpoint TEXT  DataRobot Public API endpoint. You can use
                       DATAROBOT_ENDPOINT instead. Default:
                       https://app.datarobot.com/api/v2
  --id-only            Output only ids
  --help               Show this message and exit.
```

| Argument | Description |
| --- | --- |
| --token | Enter your API Key, found on the API keys and tools page of your DataRobot account. You can also provide your API Key using the DATAROBOT_API_TOKEN environment variable. |
| --endpoint | Enter the URL for the DataRobot Public API. The default value is https://app.datarobot.com/api/v2. You can also provide the URL to Public API using the DATAROBOT_ENDPOINT environment variable. |
| --id-only | Enables showing only the IDs of the entity. This command can be useful with piping to terminate the command. |

### terminate command

Stops the application and removes it from the applications list. For more information, use the `drapps terminate --help` command:

```
$ drapps terminate --help
Usage: drapps terminate [OPTIONS] APPLICATION_ID_OR_NAME...

  Stops custom application and removes it from the list.

Options:
  -t, --token TEXT     Pubic API access token. You can use
                       DATAROBOT_API_TOKEN env instead
  -E, --endpoint TEXT  DataRobot Public API endpoint. You can use
                       DATAROBOT_ENDPOINT instead. Default:
                       https://app.datarobot.com/api/v2.
  --help               Show this message and exit.
```

| Argument | Description |
| --- | --- |
| APPLICATION_ID_OR_NAME | Enter a space separated list of IDs or names of the applications to be removed. |
| --token | Enter your API Key, found on the API keys and tools page of your DataRobot account. You can also provide your API Key using the DATAROBOT_API_TOKEN environment variable. |
| --endpoint | Enter the URL for the DataRobot Public API. The default value is https://app.datarobot.com/api/v2. You can also provide the URL to Public API using the DATAROBOT_ENDPOINT environment variable. |

### external-share command

Manages external users that can access an application. For more information, use the `drapps external-share --help` command:

```
$ drapps external-share  --help
Usage: drapps external-share [OPTIONS] APPLICATION_NAME

Options:
  -t, --token TEXT                Pubic API access token. You can use
                                  DATAROBOT_API_TOKEN env instead.
  -E, --endpoint TEXT             Data Robot Public API endpoint. You can use
                                  DATAROBOT_ENDPOINT instead. Default:
                                  https://app.datarobot.com/api/v2
  --set-external-sharing BOOLEAN
  --add-external-user TEXT
  --remove-external-user TEXT
  --help                          Show this message and exit.
```

| Argument | Description |
| --- | --- |
| -t, --token | (Text) Enter your API Key, found on the API keys and tools page of your DataRobot account. You can also provide your API Key using the DATAROBOT_API_TOKEN environment variable. |
| -E, --endpoint | (Text) Enter the URL for the DataRobot Public API. The default value is https://app.datarobot.com/api/v2. You can also provide the URL to Public API using the DATAROBOT_ENDPOINT environment variable. |
| --set-external-sharing | (Boolean) Determines whether or not external sharing is enabled for the application. |
| --add-external-user | (Text) Grants the specified user access to the application. |
| --remove-external-user | (Text) Revokes the specified user's access to the application. |
| --help | Displays the available arguments for the command. |

To enable external sharing for an app:

```
drapps external-share <USER_ID> --set-external-sharing True
```

To enable external sharing (by ID) for an account:

```
drapps external-share <USER_ID> --add-external-user user@datarobot.com
```

Enable external sharing (by name) for an account:

```
drapps external-share MyAwesomeApp --add-external-user user@email.com
```

To add two users from external sharing:

```
drapps external-share MyAwesomeApp --add-external-user user@email.com  --add-external-user person@email.com
```

Add one user and remove one from external sharing:

```
drapps external-share MyAwesomeApp --add-external-user user@email.com  --remove-external-user person@email.com
```

## Deploy an example app

First, clone the [dr-apps repository](https://github.com/datarobot/dr-apps/tree/main) so you can access example apps. You can then deploy an example Streamlit app using the following command from the root of the dr-apps repository:

```
drapps create -t <your_api_token> -e "[Experimental] Python 3.9 Streamlit" -p ./examples/demo-streamlit DemoApp
```

This example script works as follows:

1. Finds the execution environment through the/api/v2/executionEnvironments/endpoint by the name or UUID you provided, verifying if the environment can be used for the application and retrieving the ID of the latest environment version.
2. Finds or creates the application image through the/api/v2/customApplicationImages/endpoint, named by adding theImagesuffix to the provided application name (i.e.,CustomApp Image).
3. Creates a new version of an application image through thecustomApplicationImages/<appImageId>/versionsendpoint, uploading all files from the directory you provided and setting the execution environment version defined in the first step.
4. Starts a new application with the application image version created in the previous step.

When this script runs successfully, a link to the app on the [Applications](https://app.datarobot.com/applications) page appears in the terminal.

> [!NOTE] Application access
> To access the application, you must be logged into the DataRobot instance and account associated with the application.

## Feature considerations

Consider the following when creating an application:

- The root directory of the application must contain astart-app.shfile, used as the entry point for starting your application server.
- The web server of the application must listen on port8080.
- The required packages can be listed in arequirements.txtfile in the application's root directory for automatic installation during application setup.
- The application should authenticate with the DataRobot API through theDATAROBOT_API_TOKENenvironment variable using a key found in the DataRobotAPI keys and tools. The DataRobot package on PyPI already authenticates this way. This environment variable is added automatically to your running container by the application service.
- The application should access the DataRobot Public API URL for the current environment through theDATAROBOT_ENDPOINTenvironment variable. The DataRobot package on PyPI already uses this route. This environment variable is added automatically to your running container by the application service.

---
