pyyaml-env-tag
A custom YAML tag for referencing environment variables in YAML files.
What it is and what it does
pyyaml_env_tag extends pyyaml with a custom `!ENV` tag that substitutes environment variable values directly into YAML during parsing. Instead of loading static config files, you can reference environment variables by name, and the tag will resolve them to their actual values at parse time. The package automatically coerces values using YAML's implicit type system—so an environment variable set to the string `true` becomes a Python boolean, not a string.
The tag supports fallback chains and defaults: you can specify multiple environment variables to try in order, with a final default value if none are set. This is useful for configuration management where you want environment-specific overrides but sensible defaults when variables aren't defined. The package depends only on pyyaml and integrates by wrapping your chosen loader with the `add_env_tag()` helper.
Use it for:
- Load database credentials from environment variables in a YAML config file without post-processing
- Provide environment-specific configuration by setting different env vars before parsing
- Define fallback values for optional settings that may or may not be set in the environment
- Avoid hardcoding secrets in config files by referencing them as env vars at parse time
- Coerce environment string values to booleans, integers, or null in YAML without manual conversion
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds a custom YAML tag that lets you reference environment variables directly in YAML files, with support for fallbacks and type coercion.
Yes, if you need to inject environment variables into YAML configs at parse time. The package is lightweight, has no security issues, and is stable. The aging maintenance status (458 days since last release) is not a blocker for a small, focused tool, but monitor the repo if you depend on active development. Install if your workflow benefits from env-var-aware YAML loading; skip if you prefer post-processing or template-based substitution.
Install
pyyaml-env-tag on PyPI
pip
pip install pyyaml-env-taguv
uv add pyyaml-env-tagpoetry
poetry add pyyaml-env-tagInstalling pyyaml-env-tag
Before you install
Low install friction with a single pure-Python dependency. Maintenance status is aging—last release was 458 days ago—but the repo is active and marked Production/Stable.
License in practice
MIT license (permissive) means you can use this freely in commercial and private projects with minimal restrictions.
Quickstart
pip install pyyaml-env-tag
from pyyaml_env_tag import add_env_tag
import pyyaml
myLoader = add_env_tag(pyyaml.Loader)
pyyaml.load('key: !ENV MY_VAR', Loader=myLoader)
Verify before relying
- Whether environment variable parsing handles all YAML scalar types correctly in edge cases
- Performance characteristics when processing large YAML files with many env tags
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pyyaml |
| Maintenance | aging — 458 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 17,155,159/month — #1,131 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyyaml_env_tag-1.1-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pyaml-envParses YAML configuration files and resolves…
permissive · top 15,000 on PyPI
yaml-configReads configuration from YAML files and…
unclear · top 5,000 on PyPI
pyyaml-includeExtends PyYAML to include other YAML files into…
copyleft · top 5,000 on PyPI
load-dotenvAutomatically loads environment variables from…
permissive · top 15,000 on PyPI
yamlcoreAdds YAML 1.2 Core Schema support to PyYAML,…
permissive · top 15,000 on PyPI
yamlloaderProvides specialized loaders and dumpers for…
permissive · top 15,000 on PyPI
envsubstSubstitutes environment variables in strings…
permissive · top 15,000 on PyPI
bestconfigLoads configuration from multiple file formats…
permissive · top 15,000 on PyPI
envyamlParses YAML configuration files with…
permissive · top 5,000 on PyPI
aspy.yamlProvides order-preserving YAML loading and…
permissive · top 15,000 on PyPI