Variables
Variables are secret, encrypted values which you can share between scripts.
Please see the Variable API Reference for more details. You can also create Variables directly from the Web interface.

Overview

Scripts 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. Datapane's Variable object provides a safe and secure way to create, store, and retrieve values which your scripts require. See the Python API Docs for more information on using Variables. You can also create Variables directly from the Web interface.

CLI

create

Parameters

Parameter
Description
Required
name
The name of your variable
True
value
The value of your variable
True

Response

A Variable object

Description & Example

Create a new user variable. Adding multiple versions of variables with the same name will create new versions.
CLI
Python
1
~/> datapane variable add <variable_name> <variable_value>
2
Created variable: <variable_name>
Copied!
1
import datapane as dp
2
v = dp.Variable.create(name, value, visibility='ORG')
Copied!

list

Parameters

None

Response

A list of variable names and versions

Description & Example

CLI
1
~/> datapane variable list
2
Available Variables:
3
name versions
4
-- ------ ----------
5
0 foo 1
6
Copied!

get

Parameters

Parameter
Description
Required
name
The name of your variable
True
version
The version of the variable to retrieve
False
owner
The owner of the variable. This defaults to the person running the script, so should be set explicitly if you want other people to run scripts with a user variable you created.
False

Response

A single Variable object

Description & Example

By default, get will retrieve the latest version of your variable.
If you want other people inside your organisation to run your scripts with a variable which you created, you must specify yourself as the owner in this method. When someone runs your script, it runs under their name, and if you do not set an explicitly specify the owner , it will try and look for the variable under their name and fail.
1
foo = dp.Variable.get(name='foo', owner='linus')
Copied!
CLI
Python
1
~/> datapane variable get foo
2
Available Variable:
3
name value visibility
4
-- ------- ------- ------------
5
0 foo bar OWNER_ONLY
Copied!
1
import datapane as dp
2
3
v = dp.Variable.get(name='foo')
Copied!
Get Value
To get the value that you save in foo, use:
1
foo_value = foo.value
Copied!

delete

Parameters

Parameter
Description
Required
name
The name of your variable
True

Response

None

Description & Example

CLI
1
~/> datapane variable delete foo
2
Deleted variable foo
Copied!
Last modified 4mo ago