Skip to main content

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

license python pypi release numpydoc

black isort wemake mypy semantic_release

dependabot CI CD CodeQL Dependency Review wheel

coverage codeclimate downloads stars

issues issues pr pr contributors commit

buymeacoffee standwithukraine standwithukraine

🔮 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.

logo
# .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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry_plugin_dotenv-0.5.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

poetry_plugin_dotenv-0.5.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file poetry_plugin_dotenv-0.5.0.tar.gz.

File metadata

  • Download URL: poetry_plugin_dotenv-0.5.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.6.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.3

File hashes

Hashes for poetry_plugin_dotenv-0.5.0.tar.gz
Algorithm Hash digest
SHA256 01ea92168ce7c163e02426070bdfa1fac0eba044e762c7a3feaafa6bea4e811e
MD5 a48bfa391f005d3e4dba73d24259ce23
BLAKE2b-256 de833160e46caaf766eaf3072d9f3b5821872801a21b9fff6bd1428b4d565aea

See more details on using hashes here.

Provenance

File details

Details for the file poetry_plugin_dotenv-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: poetry_plugin_dotenv-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.6.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.3

File hashes

Hashes for poetry_plugin_dotenv-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6d90d23536f75ac9ee240733f35d9db309169c51395cbdf0349edabebc6bd3a
MD5 317e3709ca9aa129636d203e4b4a6a1a
BLAKE2b-256 e8dd1f254c0e1752832959b75a93e657717ca707dce93d3e3b7a92f8ea3dce9a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page