Quick Setup¶
Let's start with a quick setup. Suppose your project has a .env file with the following content:
Import the env object from stela and use it:
# settings.py
from stela import env
API_URL = env.API_URL # http://localhost:8000
DATABASE_URL_CONNECTION = env.DB_URL # db://fake_user:fake_password@local_db:0000/name
Now, create a .env.local file and add the real secret value:
# settings.py
from stela import env
API_URL = env.API_URL # http://localhost:8000
DATABASE_URL_CONNECTION = env.DB_URL # db://real_user:real_password@real_db:0000/name
This is because Stela will first load the content from .env file, and then will override the values with the content from .env.local file.
But how about the environments?¶
Ok, let's add another file: .env.remote:
And we export the STELA_ENV variable:
When we run the python code, we will get the following values:
from stela import env
API_URL = env.API_URL # https://remote.api.com
DATABASE_URL_CONNECTION = env.DB_URL # db://real_user:real_password@real_db:0000/name
What's happened here?
- Stela will load the content from
.envfile. - Then, it will load the content from
.env.localfile, overriding previous content, because Stela always looks for.env.*.localfiles - Finally, it will load the content from
.env.remotefile, overriding previous content, because STELA_ENV is set toremote.
Ok, but what if I just define the variable in the environment?¶
No problem! Stela will always look for environment variables first. So, if you export the DB_URL variable:
When you run the python code, you will get the following values:
from stela import env
API_URL = env.API_URL # https://remote.api.com
DATABASE_URL_CONNECTION = env.DB_URL # db://env_user:env_password@env_db:0000/name
This is because Stela will first look for environment variables, and then will load the content from .env files.
And that's it! Now you can use Stela to manage your settings in any python project.
Stela is highly customizable, so you can use it in any way you want. It can handle several use cases you can have handling your project settings.
For the next pages, let's see each one of these options with more details.