
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
poetry-plugin-dotenv
Advanced tools
poetry-plugin-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run.
poetry-plugin-dotenv
- is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry
commands are run.
--directory
, which allows setting the working directory for the poetry
commandpoetry v1.5+
and poetry v2+
poetry self add poetry-plugin-dotenv@latest
[!TIP] New releases support only Python 3.9+. If you want to use
poetry-plugin-dotenv
with Python 3.8, please install version2.4.0
usingpoetry self add poetry-plugin-dotenv@2.4.0
By default, the plugin will load the .env
file from the current working directory or any higher-level directories.
ignore
Type: str
Default: false
Allowed values (as True): y / yes / t / on / 1 / true
Allowed values (as False): n / no / f / off / 0 / false
Prevents poetry
from loading the dotenv file.
location
Type: str
Default: .env
If your dotenv file is located elsewhere or has a different name, you can set this parameter.
The plugin can read project-specific default values for its options from a pyproject.toml
file.
By default, poetry-plugin-dotenv
looks for a pyproject.toml
file that includes either a [tool.dotenv]
or [tool.poetry.plugins.dotenv]
section.
Example pyproject.toml
:
[tool.dotenv]
ignore = "false"
location = ".env.dev"
[tool.poetry.plugins.dotenv]
ignore = "false"
location = ".env.dev"
[!WARNING] In upcoming poetry releases, the
[tool.poetry.plugins]
section will be deprecated. Please migrate to[tool.dotenv]
.
[!IMPORTANT] Due to
poetry
's default parser, all options in the plugin sections must be specified as strings.
As mentioned in the Features list, the schema for the plugin configuration is part of the JSON Schema Store, which enables auto-completion and validation in IDEs like Visual Studio Code and PyCharm.
poetry-plugin-dotenv
supports the following configuration options via environment variables:
POETRY_PLUGIN_DOTENV_LOCATION
POETRY_PLUGIN_DOTENV_IGNORE
[!IMPORTANT] As environment variables are always strings, options should always be set as strings.
A pyproject.toml
file can override default values. Options provided via environment variables override both.
# .env
DB__HOST=localhost
DB__DBNAME=local_lakehouse
DB__USER=volodymyr
DB__PASSWORD=super_secret_password
DB__ENGINE=postgresql://${DB__USER}:${DB__PASSWORD}@${DB__HOST}/${DB__DBNAME}
# .env.dev
DB__HOST=dev.host
DB__DBNAME=dev_lakehouse
DB__USER=svc_team
DB__PASSWORD=super_secret_password
DB__ENGINE=postgresql://${DB__USER}:${DB__PASSWORD}@${DB__HOST}/${DB__DBNAME}
# pyproject.toml
[tool.dotenv]
location = ".env.dev"
# main.py
from __future__ import annotations
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: .env
# Host: 'localhost'
# Name: 'local_lakehouse'
# Username: 'volodymyr'
# Password: 'super_secret_password'
# Engine: 'postgresql://volodymyr:super_secret_password@localhost/local_lakehouse'
# Set location section in pyproject.toml
poetry run -vvv python main.py
# Loading environment variables: .env.dev
# Host: 'dev.host'
# Name: 'dev_lakehouse'
# Username: 'svc_team'
# Password: 'super_secret_password'
# Engine: 'postgresql://svc_team:super_secret_password@dev.host/dev_lakehouse'
# Set ignore = "true" in pyproject.toml
poetry run -vvv python main.py
# Not loading environment variables. Ignored by configuration
# Environment variables not set!
export POETRY_PLUGIN_DOTENV_LOCATION=.env.dev && poetry run -vvv python main.py
# Loading environment variables: .env.dev
# Host: 'dev.host'
# Name: 'dev_lakehouse'
# Username: 'svc_team'
# Password: 'super_secret_password'
# Engine: 'postgresql://svc_team:super_secret_password@dev.host/dev_lakehouse'
export POETRY_PLUGIN_DOTENV_IGNORE=true && poetry run -vvv python main.py
# Not loading environment variables. Ignored by configuration
# Environment variables not set!
FAQs
poetry-plugin-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run.
We found that poetry-plugin-dotenv demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.