Skip to main content

Expand system variables Unix style

Project description


Expand system variables Unix style

PyPI version CircleCI codecov


This module is inspired by GNU bash's variable expansion features. It can be used as an alternative to Python's os.path.expandvars function.

A good use case is reading config files with the flexibility of reading values from environment variables using advanced features like returning a default value if some variable is not defined. For example:

my_secret_access_code = "${ACCESS_CODE:-default_access_code}"

NOTE: Although it copies most of the common behaviours, it doesn't follow it strictly. For example, it doesn't work with arrays.


from expandvars import expandvars

# /bin:/sbin:/usr/bin:/usr/sbin:/home/you/bin:/default/path


For now, refer to the test cases to see how it behaves.


To contribute, setup environment following way:

# Clone repo
git clone && cd expandvars

# Create virtualenv
virtualenv .venv && source .venv/bin/activate

# Install library in edit mode along with other handy dev tools
pip install -r dev-requirements.txt
  • Follow general git guidelines.
  • Keep it simple. Use black to format code.
  • Test your changes locally by running pytest.
  • If you are familiar with tox, you may want to use it for testing in different python versions.

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

expandvars-0.5.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

expandvars-0.5.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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