Trouble deciding whether to use autoenv or python dotenv

Viewed 2078

I've been exposed to both of these tools , but they seem to serve the same purpose. My question is are they different and if so, how?

In my research it seems to me that autoenv is global in scope while dotenv is a bit more application specific. While this seems an advantage in many cases, I wonder if it could also create unforeseen problems.

Second what would be the pros / cons of using one over the other (or should I use each in different situations?)

I've read through documentation for each, but have been unable to find an article comparing the two. It is relatively recent that I've developed a stronger grasp on environment variables in general so apologies if I missed something obvious in the documentation.

I'm primarily developing web apps with Flask and deploying on Heroku if that would influence my choice.

Thanks in advance.

1 Answers

autoenv, is meant for the cli, to enable environments when you cd into a directory containing an .env file.

Fx. if you need some of the environment variables on your local development environment whenever you cd to the directory, you would use autoenv or the more mature alternative direnv.

dotenv is used in python to find an .env file in the running directory or parent directories and load their variables, this is good for services as they usually don't have a shell running.

So for your heroku deployments you should use dotenv.

If you however are putting in config vars straight in the heroku settings, you don't need either, you would simply use os.getenv:

from os import getenv
print(getenv('MY_ENVIRONMENT_VARIABLE'))
Related