poetry-plugin-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-plugin-dotenv
- is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry
commands are run.
Features
- 📦 Doesn't require any dependencies
- 📝 Supports templates, interpolating variables using POSIX variable expansions
- 🔮 Fully type safe
- 🥷🏻 100% tests coverage and "A" grade for maintainability
⚙️ Installation
poetry self add poetry-plugin-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
import os
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
# Loading environment variables from '.env'.
# Host: 'localhost'
# Name: 'prod'
# Username: 'admin'
# Password: 'admin'
# Engine 'postgresql://admin:admin@localhost/prod'
export POETRY_DOTENV_LOCATION=.env.dev && poetry run -vvv python main.py
# Loading environment variables from '.env.dev'.
# Host: 'localhost'
# Name: 'dev'
# Username: 'root'
# Password: 'root'
# Engine 'postgresql://root:root@localhost/dev'
export POETRY_DONT_LOAD_DOTENV=1 && poetry run -vvv python main.py
# Not loading environment variables.
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_plugin_dotenv-0.6.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 157b18fc31ec5e61030d1ba9b6e437e027d638821205ecb773897b7b12e81749 |
|
MD5 | 8d4be0c0319d18e8f58b0e8e1ce9bfe5 |
|
BLAKE2b-256 | 55c1d1e50e59b9393cd8b7e0deef052ac087f81e3954aba897427df8ac08a05e |
Hashes for poetry_plugin_dotenv-0.6.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb34a112ce7c1eac547d0b11d05cb5eba665f2bff49452ef8d1e88a7155573b |
|
MD5 | abf7c46f1df213fa8c5dee605dc6e386 |
|
BLAKE2b-256 | 1c4e1d668b32d0f6b7542c8044192ed966aafd5c9318af7102af95baa68fab95 |