title: How do I call environment variables outside of settings.py?
body: <p>I'm using <a href="https://pypi.org/project/python-dotenv" rel="nofollow noreferrer">python-dotenv</a> to set up environment variables and I got everything to work. I can now call my environment variables from <code>settings.py</code> that I defined in <code>.env</code>. That's cool and all but is there a way to call the environment variables from other files in subdirectories? Note that I'm not using django or any framework.</p>
  
  <pre><code># settings.py
  
  import os
  from dotenv import load_dotenv
  BASEDIR = os.path.abspath(os.path.dirname(__file__))
  load_dotenv(os.path.join(BASEDIR, '.env'))
  
  CLIENT_ID = os.getenv("CLIENT_ID")
  
  # This works!
  print(CLIENT_ID)
  </code></pre>
  
  <pre><code># other_file.py
  
  import os
  
  CLIENT_ID = os.getenv("CLIENT_ID")
  
  # This does not :(, prints None
  print(CLIENT_ID)
  </code></pre>
  
  <p>I'm sure I can load <code>.env</code> in every file where env variables are needed, but is there a more efficient way?</p>