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 this module copies most of the common behaviours of bash, it doesn't follow bash 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.5.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

expandvars-0.5.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expandvars-0.5.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for expandvars-0.5.2.tar.gz
Algorithm Hash digest
SHA256 56cc1e64783ca9c79684071461b00f793c49b9f5c650de945cdcc32c2dad2203
MD5 cb54d8b7c75479730ebc9fb54ef9ed2c
BLAKE2b-256 2a2489910b88b81fb86fe020a0f2d273444cc748d459ff84b60443dfc0e93e3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expandvars-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for expandvars-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e1082ffcbbb8d85d2900d11d7bd47e0d7f0aac3491c3bb932c3fbc73aa50459b
MD5 7979a88d3ab644dfa84b2715a702bedd
BLAKE2b-256 e93b6b056a6aac009346cd1e2f0c658d0b14a06861a98bfaf2b86355815fa52f

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