Warning:  Due to planned infrastructure maintenance, the EBRAINS Wiki and EBRAINS Support system will be unavailable for up to three days starting Monday, 14 July. During this period, both services will be inaccessible, and any emails sent to the support address will not be received.

Attention: We are currently experiencing some issues with the EBRAINS Drive. Please bear with us as we fix this issue. We apologise for any inconvenience caused.


Creating and accessing environment variables

Version 4.1 by mmorgan on 2021/07/08 15:59

Notebooks can be opened from a link in a collab or other web page.

Some notebooks may need to be passed parameters, e.g. to indicate the context they are run in. For this, you can use the URL query parameters to add environment variables to a Jupyter Notebook.

For example, here is a link to a notebook:

https://lab.ebrains.eu/user-redirect/lab/tree/shared/example_path/notebook.ipynb

To add environment variables that are accessible within that notebook (in this case LAB_MY_VARIABLE) use this URL:

https://lab.ebrains.eu/user-redirect/lab/tree/shared/example_path/notebook.ipynb?LAB_MY_VARIABLE=Hello

You can add as many variables as you want but the query string needs to be properly formatted. You can find more info about the query string format here.

Note: For the query parameters to be accessible in the notebook they need to be prefixed with LAB_ e.g. LAB_MY_VARIABLE=4 

You can then access the environment variable from the notebook as in this code snippet:

import os
os.environ.get('LAB_MY_VARIABLE')