sloria / environs

simplified environment variable parsing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Override .env variables with real enviroment variables

ericsouza opened this issue · comments

Is there any way to override the env vars from .env with real enviroments as dynaconf does?

I'm trying to run a flask application inside docker container with a postgres db at same network binding a volume to my source code so I can have hot restart, the problem is that in .env I have the database_url as localhost, but inside the container it should be the database container service

Hi, tell me if I understood you correctly. This is the test script:

from environs import Env

env = Env()
env.read_env()

print(env('TEST'))

If I provide a .env like the following:

TEST=test

I get as output:

test

However, if I provide the app with an environment variable (TEST=test_env), the ones you would provide in the docker --env or docker-compose environment, it gets replaced:

test_env

To make sure you always use the .env you can override the environment variables with

env.read_env(override=True)

And the result is:

test

Hey, thanks for the answer, I found out that was a problem with my VS Code debug configuration for flask apps