Datalore 2024.2 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.

There are two basic cases of creating an environment variable:

  • For a notebook

    You want to create an environment variable for a particular notebook you are working in right now. This will automatically attach the new environment variable to the notebook.

  • For a workspace

    You add an environment variable to a workspace where you want to use it in multiple notebooks. The procedure does not attach the new environment variable to the notebooks. You attach it later when working in the editor.

Find more details on creating environment variables in this article.

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

Find more information on managing environment variables in these articles:

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

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
    Last modified: 24 April 2024