How to pass environment variables in Jupyter Notebook

(Sharing some personal suffering) One thing that gets me mad it’s to make several .csv/.txt files in my computer to perform some analysis. I personally prefer to connect directly in some RDBMS (Redshift) and get the data in some straightforward way and store the query inside the Jupiter Notebook. The main problem with this approach is: a high number of people put their passwords inside the notebooks/scripts and this is very unsafe. (You don’t need to believe me, check it by yourself) I was trying to pass the environment variables in a traditional way using export VARIABLE_NAME=xptoSomeValue  but after starting the Jupyter Notebook I get the following error:    

-————————————————————————– KeyError Traceback (most recent call last)

in () 2 import os 3 \----> 4 HOST \= os.environ\['REDSHIFT\_HOST'\] 5 PORT \= os.environ\['REDSHIFT\_PORT'\] 6 USER \= os.environ\['REDSHIFT\_USER'\] /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.pyc in \_\_getitem\_\_(self, key) 38 if hasattr(self.\_\_class\_\_, "\_\_missing\_\_"): 39 return self.\_\_class\_\_.\_\_missing\_\_(self, key) ---> 40 raise KeyError(key) 41 def \_\_setitem\_\_(self, key, item): self.data\[key\] \= item 42 def \_\_delitem\_\_(self, key): del self.data\[key\] KeyError: 'REDSHIFT\_HOST' For some reason, this approach didn't work. I make a small workaround to start using some environmental variables when I call of `jupyter notebook` command in that way: `env REDSHIFT_HOST='myRedshiftHost' REDSHIFT_USER='flavio.clesio' REDSHIFT_PORT='5439' REDSHIFT_DATA='myDatabase' REDSHIFT_PASS='myVeryHardPass' jupyter notebook` I hope it helps!