How To Access Environment Variables With Python
Jul 8, 2021
When you are programming in most cases you need to have privacy with some variables, be it the database variables such as user, password, host etc. These are variables that have sensitive data that you usually need to store in an .env, example:
# File .env# DATABASEDB_NAME=...DB_USER=...DB_PASSWORD=...DB_HOST=...
How do I get these values?
Easily, There is a third-party module that makes life much easier for us, such as: https://pypi.org/project/python-decouple/
pip install python-decouple
All it need is install and uses
from decouple import config
How do I use it?
Once you have imported, just call config function like this:
Thank you!!!!!.