Please see the Variable API Reference for more details.
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.
Parameter | Description | Required |
| The name of your variable | True |
| The value of your variable | True |
| The visibility setting ( | False |
A Variable object
Create a new user variable. Adding multiple versions of variables with the same name will create new versions.
By default, variables are private to the creator's account, but they can be shared across an organization. To set visibility, use the --visibility
flag (or visibility
field in Python) with OWNER_ONLY
or ORG
.
If you want other people inside your organisation to run your scripts, your variable must be ORG
, as scripts are executed under their user account.
~/> datapane variable add <variable_name> <variable_value>Created variable: <variable_name>
import datapane as dpv = dp.Variable.create(name, value, visibility='ORG')
None
A list of variable names and versions
~/> datapane variable listAvailable Variables:name versions-- ------ ----------0 foo 1​
Parameter | Description | Required |
| The name of your variable | True |
| The version of the variable to retrieve | False |
| 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 |
A single Variable object
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.
foo = dp.Variable.get(name='foo', owner='linus')
~/> datapane variable get fooAvailable Variable:name value visibility-- ------- ------- ------------0 foo bar OWNER_ONLY
import datapane as dp​v = dp.Variable.get(name='foo')
Get Value
To get the value that you save in foo, use:
foo_value = foo.value
Parameter | Description | Required |
| The name of your variable | True |
None
~/> datapane variable delete fooDeleted variable foo
​
​