Datalore 2023.6 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

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

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.

  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

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.

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

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

  3. Select the item from the list.

    Selecting environment variable
to attach

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.

  4. 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.

Accessing notebook identification environment variables

    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

    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: 05 January 2024