Datalore 2023.5 Help

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

Migrate secrets to environment variables

Environment variables are the new alternative to Secrets (soon deprecated). To preserve your secrets, migrate them to environment variables.

  1. Click the avatar in the upper-right corner of the screen.

  2. Select Account settings from the menu.

  3. Switch to the Secrets tab.

  4. Click the ellipsis for the secret you want to migrate.

  5. Select Migrate secret to environment variable.

    Migrating a secret

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.

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"])

Procedures

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

  1. In the editor, click Environment on the left-hand menu.

  2. In the Environment tool, switch to the Environment variables tab.

    Environment variables tab
  3. Create an environment variable:

    1. Click the New variable button to open the Create environment variable dialog.

    2. Provide a name for the new environment variable.

    3. Provide a key name. This is what will be referenced in the notebook code.

    4. Provide a key value. This is the protected value that only you can manage.

    5. (Optional) Click Add key-value pair to provide another record.

    6. Click Create variable to finish your work in the dialog.

      Creating environment variable
  4. Attach the created environment variable to the notebook:

    1. On the Environment variables tab, click Select environment variable to attach to expand the list.

    2. Select the item from the list.

      Selecting environment variable
to attach

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.

Edit environment variables in the notebook editor

You can edit environment variables attached to a notebook.

  1. Open the Environment tool.

  2. Switch to the Environment variables tab. You can view the environment variables attached to this notebook.

  3. Click the ellipsis for the item you want to edit.

    Environment variable menu
  4. Select Edit variable from the menu to open the Edit environment variable

  5. In the dialog, make the required changes and click the Update variable button.

Detach an environment variable from a notebook

  1. Open the Environment tool.

  2. Switch to the Environment variables tab. You can view the environment variables attached to this notebook.

  3. Click the ellipsis for the item you want to edit.

    Environment variable menu
  4. Select Detach variable from the menu.

Create, attach, and manage environment variables in a workspace

The procedures below explain how to use environment variables in a selected workspace.

Create environment variables in a workspace

  1. On the Home page, select the workspace where you want to create an environment variable.

  2. From the left-hand menu, select Environment variables. Here, you can view the environment variables created earlier.

    Environment variables list
  3. Click the Add variable button in the upper-right corner of the window.

  4. In the Create environment variable, do the following:

    1. Provide a name for the new environment variable.

    2. Provide a key name. This is what will be referenced in the notebook code.

    3. Provide a key value. This is the protected value that only you can manage.

    4. (Optional) Click the Add key-value pair button to provide another record.

    5. Click the Create variable button to finish your work in the dialog.

      Creating environment variable

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

  1. On the Home page, gp to Environment variables.

  2. Click the ellipsis for the environment variable you want to edit.

    Environment variable menu
  3. Do one of the following:

    • To edit the environment variable:

      1. Select Edit variable from the menu to open the Edit environment variable dialog.

      2. In the dialog, make the required changes and click the Update variable button.

    • To rename the environment variable:

      1. Select Rename from the menu.

      2. Enter a new name and press Enter.

    • To clone the item to other workspaces:

      1. Select Select to other workspaces

      2. In the Clone [environment_variable_name] to other workspaces dialog, expand the Workspaces dropdown list.

      3. Select the workspaces where you want to clone the environment variable and click anywhere outside the dropdown.

      4. Click the Clone button. This will close the dialog, followed by a success notification.

    • To delete the environment variable, select Delete from the menu.

Last modified: 04 September 2023