Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.ini file load environment variable

I am using Alembic for migrations implementation in a Flask project. There is a alembic.ini file where the database configs must be specified:

sqlalchemy.url = driver://user:password@host/dbname

Is there a way to specify the parameters from the environment variables? I've tried to load them in this way $(env_var) but with no success. Thanks!

like image 816
dimmg Avatar asked Jun 17 '16 20:06

dimmg


People also ask

How do I use an environment variable in an INI file?

environ as the dictionary you can use %(variable)s in the ini. Not that this is not specific to pyramid. paster. get_app as the next section shows (but my guess is get_app is the case).

Can you use environment variables in Yaml?

Environment variable substitution is supported in both the great_expectations. yml and config variables config_variables. yml config file.

How do I read .ini files?

How to Open and Edit INI Files. It's not a common practice for people to open or edit INI files, but they can be opened and changed with any text editor. Just double-clicking it will automatically open it in the Notepad application in Windows.

Can Python read INI files?

The Python script again reads the INI file to read the content of the INI file, and using the get() method, it retrieves all the written information. The get() method accepts two parameters: section and option .


1 Answers

I've solved the problem by setting sqlalchemy.url in env.py as @dirn suggested.

config.set_main_option('sqlalchemy.url', <db_uri>) did the trick, where <db_uri> can be loaded from environment or config file.

like image 129
dimmg Avatar answered Sep 22 '22 13:09

dimmg