Environments & Variables
Environment allows you to set environment variables and docker image to use when running apps.
Please see the Environment API Reference for more details. You can also create Environments directly from the Web interface.

Overview

Apps often contain variables such as database keys and passwords, which you do not want embedding in your source code and visible to the outside world.
In addition, you'll often want to include custom dependencies and packages outside those in our default Docker image.
Datapane lets you specify your variables and Docker images through Environments.

Creating an environment

You can create a new environment from Python, the CLI or the web interface. Adding multiple versions of environments with the same name will create new versions.
Python
CLI
1
import datapane as dp
2
3
dp.Environment.create(
4
name="env1",
5
environment={"foo": "bar", "bat": "ball"},
6
docker_image="image_name",
7
project="project_name"
8
)
Copied!
1
$ datapane environment create env2 --environment foo=bar --docker-image image_name --project project_name
Copied!

Parameters

Parameter
Description
Required
name
The name of your environment
True
environment
A dictionary of key:value pairs for your variables
True
docker-image
Your image name on DockerHub
False
project
Project this environment is part of (default is home)
False

Loading an environment

To tell your app which environment and Docker image to use, specify the environment in your datapane.yaml file.
1
environment: my-environment
Copied!
To access variables inside your Python script, use os.environ.getas follows:
1
import datapane as dp
2
import os
3
4
env = dp.Environment.get(name="my-environment", owner = "john")
5
var = os.environ.get("foo")
Copied!

Get Parameters

Parameter
Description
Required
name
The name of your environment
True
project
The project of the environment. This defaults to the home or shared project if not found in home, so should be set explicitly if you want other people to run the app with an environment you created.
False
If you want other people inside your organisation to run your apps with an environment which you created, you should specify the project in this method. When someone runs your script, it will try and look for the environment in the default project and may fail.
1
foo = dp.Environment.get(name='foo', project='project_name')
Copied!