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

logo

license python pypi release

black isort ruff mypy semantic_release poetry numpydoc

dependabot CI CD CodeQL Dependency Review hooks wheel

coverage codeclimate downloads stars wakatime

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.

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.

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.6.23.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

poetry_plugin_dotenv-0.6.23-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: poetry_plugin_dotenv-0.6.23.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for poetry_plugin_dotenv-0.6.23.tar.gz
Algorithm Hash digest
SHA256 9acf04c422b688845aea33d84674547713c32273982a54dd39b7a00873f80865
MD5 c09d56c92f1b87edd4c269124f010929
BLAKE2b-256 045e5031499d4a71a856f799257cb393f347c4ffb14e30c5fbb8a2a0f20cdb5f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for poetry_plugin_dotenv-0.6.23-py3-none-any.whl
Algorithm Hash digest
SHA256 939fb32724e5b8e2a359c80a2ea2127a37a2c7ab762ad2027fc4b65900a3e934
MD5 7e4f515e9f571d712093b8e9a3561924
BLAKE2b-256 aa43fd228dd64b6c1a4e1b9347cd6bc834287a45c1b7f9fb9bd20acc369998f8

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