This project has been archived by its maintainers, and is no longer receiving any updates.
⚠️ Warning
This package has been deprecated and is no longer maintained,
poetry-dotenvhas moved topoetry-plugin-dotenv
🔮 Overview
poetry-plugin-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-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.
Metadata
Release files for poetry-dotenv 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poetry_dotenv-0.4.0.tar.gz | 22.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poetry_dotenv-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / poetry_dotenv-0.4.0.tar.gz
| Download URL | poetry_dotenv-0.4.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e68aaf7d8a44fb89ab1d1d49f799d7bacbc365ed9b0ae9b46a68c816fa1a53b
|
|
BLAKE2b-256 checksum How to use checksums |
31fa157c9512491d0945fd085eda83dd36f4d0053025ce14271d3ead16406ea6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0
|
Release files / poetry_dotenv-0.4.0-py3-none-any.whl
| Download URL | poetry_dotenv-0.4.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9e71fdd25ed9c49b3ad39cc12f5887d49f2f3806c0e4cf3f8a1d54304856b18
|
|
BLAKE2b-256 checksum How to use checksums |
c38f687c6572a8b8b1a78abe3d19cbac30eaba882c4f320085af00c60a284a5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0
|