Manage 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.
note
The new environment variable will also be added to the respective workspace. This means that you can then attach it to any notebook residing in that workspace.
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.
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:
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.
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.

Thanks for your feedback!