Environment variables
About 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.
Collaboration and permissions
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
Example: Using an environment variable to pass a GitHub token
In the example below, information about the notebook owner's GitHub account is requested using an API 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 :
Create, attach, and manage environment variables for a specific notebook
The procedures below explain how to use environment variables for a specific notebook in the editor.
Create and attach an environment variable to a notebook
This procedure explains how to create an environment variable for a specific notebook. This will automatically attach the new environment variable to this particular notebook and add it to the resources of the respective workspace.
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.
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.
Attach an environment variable to the notebook
This procedure explains how to attach an environment variable from workspace resources to a specific notebook.
In the editor, click Environment on the left-hand menu.
On the Environment variables tab, click Select environment variable to attach to expand the list.
Select the item from the list.
Edit environment variables in the notebook editor
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.
Detach an environment variable from 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 Detach variable from the menu.
Use notebook identification as environment variables
SOURCE_ID and OWNER_ID are two environment variables that correspond to the URL of the respective notebook and contain the notebook ID and the notebook owner's ID. You can access them via coding in the notebook, init.sh, or terminal.
Create, attach, and manage environment variables as workspace resources
The procedures below explain how to use environment variables on workspace level, using the interface of the Home page.
Create environment variables in a 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.
Manage environment variables in a 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.