poetry-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run.
Project description
Overview
poetry-dotenv
- is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry
commands are run.
This plugin doesn't have any dependencies, but therefore it also supports features that python-dotenv
supports (e.g. templates, interpolating variables using POSIX
variable expansions etc).
Installation
poetry self add poetry-dotenv
Usage
By default, plugin will load the .env
file from the current working directory or "higher directories".
To prevent poetry
from loading the dotenv file, set the POETRY_DONT_LOAD_DOTENV
environment variable.
If your dotenv file is located in a different path or has a different name you may set the POETRY_DOTENV_LOCATION
environment variable.
# .env
DB__HOST=localhost
DB__DBNAME=prod
DB__USER=admin
DB__PASSWORD=admin
DB__ENGINE=postgresql://${DB__USER}:${DB__PASSWORD}@${DB__HOST}/${DB__DBNAME}
# .env.dev
DB__HOST=localhost
DB__DBNAME=dev
DB__USER=root
DB__PASSWORD=root
DB__ENGINE=postgresql://${DB__USER}:${DB__PASSWORD}@${DB__HOST}/${DB__DBNAME}
# main.py
if __name__ == "__main__":
try:
print(f"Host: {os.environ['DB__HOST']!r}")
print(f"Name: {os.environ['DB__DBNAME']!r}")
print(f"Username: {os.environ['DB__USER']!r}")
print(f"Password: {os.environ['DB__PASSWORD']!r}")
print(f"Engine: {os.environ['DB__ENGINE']!r}")
except KeyError:
print("Environment variables not set!")
poetry run -vvv python main.py
export POETRY_DOTENV_LOCATION=.env.dev && poetry run -vvv python main.py
export POETRY_DONT_LOAD_DOTENV=1 && poetry run -vvv python main.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for poetry_dotenv-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3783cb4e548e15bbfcb2ed96df4844f3c03a792ba2e2efced6c3faa6518059ec |
|
MD5 | e5a540ff0ae21cc1bb316bd2d71a878b |
|
BLAKE2b-256 | c725b859fe75be61b747309ff814297f96bdec0228a6b4fb118ccfeedb465bc3 |