skillfed

expandvars

Expand system variables Unix style

expandvars v1.1.2 3.5M downloads/30d#2,619 on PyPI33
Permissive license MIT License Copyright (c) 2019 Arijit Basu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) AGING released

What it is and what it does

expandvars is a Python module that parses and expands environment variable references in strings using bash-like syntax. It goes beyond Python's built-in os.path.expandvars by supporting advanced features: default values (${VAR:-default}), error-on-undefined (${VAR:?}), variable indirection (${!VAR}), and strict mode (nounset=True). It has no runtime dependencies and is designed primarily for reading configuration files that need flexible environment variable interpolation.

The module copies most common bash behaviors but does not attempt full bash compliance—for example, it does not support arrays. You can customize the variable symbol, escape character, and expansion data via the lower-level expand() function. It also respects an EXPANDVARS_RECOVER_NULL environment variable to temporarily disable strict parsing in testing scenarios.

Use it for:

  • Parse TOML or INI config files that reference environment variables with fallback defaults.
  • Build file paths dynamically by expanding $HOME, $PATH, and custom environment variables in application startup.
  • Validate that required environment variables are set before running a service, using ${VAR:?} syntax.
  • Substitute secrets and credentials from environment into configuration templates without hardcoding.
  • Support nested variable references where one env var points to the name of another to resolve.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Expands Unix-style variable references in strings with bash-like syntax, supporting default values, error handling, and nested variable lookups as an alternative to Python's os.path.expandvars.

Yes. expandvars is a lightweight, dependency-free utility with permissive licensing and no known vulnerabilities. It solves a real problem—flexible environment variable expansion in config files—more elegantly than os.path.expandvars. Aging maintenance is not a concern for a stable, narrow-scope tool. Install if you need bash-style variable syntax in configuration or string interpolation.

Install

expandvars on PyPI

pip

pip install expandvars

uv

uv add expandvars

poetry

poetry add expandvars

Installing expandvars

Before you install

Low install friction with no runtime dependencies. Aging maintenance status (336 days since last release) but repository remains active with recent commits; stable for a utility of this scope.

License in practice

MIT License permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.

Quickstart

from expandvars import expandvars

result = expandvars("$PATH:${HOME:?}/bin:${UNDEFINED:-/default}")
print(result)

Requires Python 3.6.2 or later.

Verify before relying

  • Whether the package handles all edge cases in production config-file parsing workflows.
  • Performance characteristics when expanding very large strings or deeply nested variables.

Package facts

License MIT License Copyright (c) 2019 Arijit Basu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.6.2)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 336 days since the last release
Last repo commit
First released
Downloads 3,450,744/month — #2,619 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: expandvars-1.1.2-py3-none-any.whl

Keywords: expand, system, variables

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: Other AudienceLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: MacOSOperating System :: MicrosoftOperating System :: POSIXOperating System :: UnixProgramming Language :: Python :: 3Topic :: Software DevelopmentTopic :: Utilities

Tags

bash variable expansionenvironment variable substitutionunix style variable expansionconfig file variable interpolationshell parameter expansion python
config-parsingenvironment-variables

More Software Development packages