poetry-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
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
# 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file poetry_dotenv-0.2.7.tar.gz.
File metadata
- Download URL: poetry_dotenv-0.2.7.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.13.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc0c0da959cee071b5f2550f9c6af196855cc13cee54165a5f0d6fd1e93cc3d2
|
|
| MD5 |
71c9a6c47da8379d85ad9000b0241d3d
|
|
| BLAKE2b-256 |
f4e988f8ed32d5a14ec5d1e7cf824d936721f2a485b7ac5b60e2c81ec94ab611
|
File details
Details for the file poetry_dotenv-0.2.7-py3-none-any.whl.
File metadata
- Download URL: poetry_dotenv-0.2.7-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.13.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35d518d37e02ff3b808acfacb19d2f11bd4a078d96f6c792ade6816253b0f862
|
|
| MD5 |
0141818bcbf5c958273e486739b8a4ea
|
|
| BLAKE2b-256 |
ce2272368078f3fb04c214db8cd84351eff3e46e27ef818e28d7a82f6914c027
|