Skip to content

Environment Variables

Environment variables can be configured in UbiOps and can be referred to inside your model code. Configuring environment variables can be useful for secure handling of credentials which you don't want to have hardcoded inside your model package, but also for parameters that you want to control or change without uploading a new model file.

Create an environment variable

Start by going to a model in the UbiOps WebApp. Click on the Advanced tab and then the Create variable icon. You can now create an environment variable by filling in its name and value.


You can set the environment variable to secret during creation. In this way, the value will not show up in API responses or logs. Use this when you have sensitive information like passwords in your environment variable.

Using an environment variable

After creating the environment variable, you can use it in your python model code. See the example below for accessing the variable named MY_VARIABLE.

import os

variable = os.environ['MY_VARIABLE']

For more information, take a look at the python documentation page.

Predefined environment variables

A couple of environment variable names are reserved for special functionality.

Variable name Function
ML_MODEL_FILE_NAME Sets a custom name for the file that contains the model class and request method. Defaults to 'model'.
ML_MODEL_CLASS_NAME Sets a custom name for the class in the model file that contains the request method. Defaults to 'Model'.
ML_LOG_REQUEST_RESULT Indicates whether the result of model requests will be logged. Can be 'true' or 'false', defaults to 'false'.