Answers for "python dotenv dotenv_values"

2

use python dotenv

pip install -U python-dotenv

#### And in your script
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
Posted by: Guest on November-22-2020
0

using dotenv_values

from dotenv import dotenv_values

# This function does not touch the os's environment rather it parses the .env file and returns a dict object
# containing parsed values

################################################################################################
# Example .env file
'''
# .env file
USER=foo
SECRET_KEY=v%)9n7kg^65(4-uir6!pa@oqqsdn8agv9h8_#ohn*55$th-gff
DOMAIN=tester.org
EMAIL=admin@${DOMAIN}
'''
################################################################################################

#Loading .env file values to config variable

config = dotenv_values(".env")

# above load is similar to executing the following in python
#config = {"USER":"foo","SECRET_KEY":"v%)9n7kg^65(4-uir6!pa@oqqsdn8agv9h8_#ohn*55$th-gff","EMAIL": "[email protected]"}

#therfore accessing values we query the keys

print(config.get("DOMAIN"))
#OUTPUT : [email protected]
Posted by: Guest on September-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language