Environment variables
Create sets of environment variables for your notebooks. Such variables can store passwords, API tokens, and other kinds of sensitive data for your notebooks to integrate with other services.
You can set up an environment variable for just one specific notebook or create one in a specific workspace and add it to any associated notebook.
This is how collaborators can manage environment variables:
Environment variable owners (creators) can manage them on the workspace and notebook level
Workspace collaborators with editor rights can attach already existing environment variables to, and detach them from, notebooks
Workspace collaborators with viewer right can view environment variables
Environment variables are the new alternative to Secrets (soon deprecated). To preserve your secrets, migrate them to environment variables.
Click the avatar in the upper-right corner of the screen.
Select Account settings from the menu.
Switch to the Secrets tab.
Click the ellipsis for the secret you want to migrate.
Select Migrate secret to environment variable.
In the example below, information about the notebook owner's GitHub account is requested using an API token.
r = requests.get('https://api.github.com/user',
auth=('user_name', os.environ["github_token"]))
The token is passed in an environment variable with the github_token key. Users with edit permissions rights can use the code below to view the secured value :
print(os.environ["github_token"])
tip
Datalore will suggest importing the
os
module as you start coding.
The procedures below explain how to use environment variables for a specific notebook in the editor.
In the editor, click Environment on the left-hand menu.
In the Environment tool, switch to the Environment variables tab.
Create an environment variable:
Click the New variable button to open the Create environment variable dialog.
Provide a name for the new environment variable.
Provide a key name. This is what will be referenced in the notebook code.
Provide a key value. This is the protected value that only you can manage.
(Optional) Click Add key-value pair to provide another record.
Click Create variable to finish your work in the dialog.
Attach the created environment variable to the notebook:
On the Environment variables tab, click Select environment variable to attach to expand the list.
Select the item from the list.
The created environment variable is added to the respective workspace. You can attach it to any other notebook from this workspace. Refer to Manage environment variables in a workspace to learn how to manage environment variables on the workspace level.
You can edit environment variables attached to a notebook.
Open the Environment tool.
Switch to the Environment variables tab. You can view the environment variables attached to this notebook.
Click the ellipsis for the item you want to edit.
Select Edit variable from the menu to open the Edit environment variable
In the dialog, make the required changes and click the Update variable button.
Open the Environment tool.
Switch to the Environment variables tab. You can view the environment variables attached to this notebook.
Click the ellipsis for the item you want to edit.
Select Detach variable from the menu.
The procedures below explain how to use environment variables in a selected workspace.
On the Home page, select the workspace where you want to create an environment variable.
From the left-hand menu, select Environment variables. Here, you can view the environment variables created earlier.
Click the Add variable button in the upper-right corner of the window.
In the Create environment variable, do the following:
Provide a name for the new environment variable.
Provide a key name. This is what will be referenced in the notebook code.
Provide a key value. This is the protected value that only you can manage.
(Optional) Click the Add key-value pair button to provide another record.
Click the Create variable button to finish your work in the dialog.
The created environment variable is added to the Environment variables list. You can attach this environment variable to any notebook from this workspace.
On the Home page, gp to Environment variables.
Click the ellipsis for the environment variable you want to edit.
Do one of the following:
To edit the environment variable:
Select Edit variable from the menu to open the Edit environment variable dialog.
In the dialog, make the required changes and click the Update variable button.
To rename the environment variable:
Select Rename from the menu.
Enter a new name and press Enter.
To clone the item to other workspaces:
Select Select to other workspaces
In the Clone [environment_variable_name] to other workspaces dialog, expand the Workspaces dropdown list.
Select the workspaces where you want to clone the environment variable and click anywhere outside the dropdown.
Click the Clone button. This will close the dialog, followed by a success notification.
To delete the environment variable, select Delete from the menu.