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.

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

Uploaded Source

Built Distribution

expandvars-0.1.4-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expandvars-0.1.4.tar.gz
  • Upload date:
  • Size: 2.4 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.1.4.tar.gz
Algorithm Hash digest
SHA256 763adb6bf4ac926e7bd9ca9e4dabc74e8fe12bac4a90979af2ed05911cd57933
MD5 eeff45c81e090c1eed298d3e890c4a89
BLAKE2b-256 db7da8b25ef015283ef5b9d0c72a7e744916445def7e6a386b902417330dd39f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expandvars-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 2.1 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.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3ff7231535bfa7294c4c614e5de8d8ce7730014bb16ef22bfafa5eaafd31ae39
MD5 619a704d4dcd3d32c61307b9d15e0598
BLAKE2b-256 fd1c025a642c2712cc9fb8153e72d2401b1149d0ad5e9fc9fb2ecbeac359b5f0

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