Skip to main content

Expand system variables Unix style

Project description

expandvars

Expand system variables Unix style

PyPI version CircleCI 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 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.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distributions

expandvars-0.4-py3.6.egg (7.1 kB view details)

Uploaded Source

expandvars-0.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expandvars-0.4.tar.gz
  • Upload date:
  • Size: 4.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.4.tar.gz
Algorithm Hash digest
SHA256 2915c970c27f3509d9c0d6e60dd81201e6644610037784e0987cf127a030b19d
MD5 0726902ef049bb1a8b57b4b7af34abc7
BLAKE2b-256 061696838ca6f05466d56d6cfb2ed815aec7a988681ed252e811a662d2ef34b1

See more details on using hashes here.

File details

Details for the file expandvars-0.4-py3.6.egg.

File metadata

  • Download URL: expandvars-0.4-py3.6.egg
  • Upload date:
  • Size: 7.1 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.4-py3.6.egg
Algorithm Hash digest
SHA256 3f6d822d84eb44a35da142131e83543b97d90289a850e4a036c2ddac5fabf10d
MD5 ed964f356c5e8a9d45f6c63612bdfccd
BLAKE2b-256 e47a85a8d5d976c1f03113e74686486ca2c70d36b78b2fe086b8c7629c6dcbea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expandvars-0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b889b65dabeb221c0d2b29817856102ffaa457b1b0612d858c4f33497cc83ad0
MD5 b7d15555aae473b9e3172af93d7d3ee2
BLAKE2b-256 aafca6672aba5b0939cc3053ea61a773b39190e74f3b980f4270d3837c1198d4

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