Skip to main content

Expand system variables Unix style

Project description

expandvars

Expand system variables Unix style

PyPI version Build Status codecov

Inspiration

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:

[default]
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.

Usage

from expandvars import expandvars

print(expandvars("$PATH:$HOME/bin:${SOME_UNDEFINED_PATH:-/default/path}"))
# /bin:/sbin:/usr/bin:/usr/sbin:/home/you/bin:/default/path

Examples

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

Contributing

To contribute, setup environment following way:

# Clone repo
git clone https://github.com/sayanarijit/expandvars && cd expandvars

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

# Install project
pip install -e '.[testing]'

# Optional install black, ipython
pip install black ipython isort

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

Uploaded Source

Built Distributions

expandvars-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

expandvars-0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file expandvars-0.2.tar.gz.

File metadata

  • Download URL: expandvars-0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for expandvars-0.2.tar.gz
Algorithm Hash digest
SHA256 2c711ce003bc755a3e58ff36901592a675654be94eeb721c625a0e37d4c3e790
MD5 ad9c7ada7a3ba5b54dc6c61cf314a9a5
BLAKE2b-256 452544c70bdb69f3571b44fb9129a6a4c7a119a1515e02f6ebb169fdfdb3bc55

See more details on using hashes here.

File details

Details for the file expandvars-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: expandvars-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for expandvars-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9efc28b45f2027a78c616d04e82692333851aeaecac1a2337560c1214c66c86
MD5 a0b880353dc04130c06cffa51aa85073
BLAKE2b-256 8ee8671da366397c53d715a9a79715353a204ae744a039835cd563d246c316fb

See more details on using hashes here.

File details

Details for the file expandvars-0.2-py3-none-any.whl.

File metadata

  • Download URL: expandvars-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

File hashes

Hashes for expandvars-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 68efc0b8096ffae7b9ff3670f153fd9f09c65ebffd0078a8be73b136efff6912
MD5 28e950be0e445f2a55b66625edfced7d
BLAKE2b-256 327ac69e478db93dbdc861e4335362a89533428784b7f43f695cd3eec7ce3488

See more details on using hashes here.

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