{"id":17954431,"url":"https://github.com/sayanarijit/expandvars","last_synced_at":"2025-04-13T09:43:59.388Z","repository":{"id":34863112,"uuid":"185258169","full_name":"sayanarijit/expandvars","owner":"sayanarijit","description":"Expand system variables Unix style","archived":false,"fork":false,"pushed_at":"2025-03-23T11:02:49.000Z","size":93,"stargazers_count":30,"open_issues_count":4,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T01:11:24.911Z","etag":null,"topics":["bash","expand","python","unix","variables"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sayanarijit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-06T19:23:40.000Z","updated_at":"2025-03-23T11:02:50.000Z","dependencies_parsed_at":"2024-06-18T20:00:46.879Z","dependency_job_id":"41ffce78-d26b-46a3-89d7-5607f4d5542f","html_url":"https://github.com/sayanarijit/expandvars","commit_stats":{"total_commits":55,"total_committers":7,"mean_commits":7.857142857142857,"dds":0.2909090909090909,"last_synced_commit":"e8c7cf9c37b115d539a84410baa5fb56aa4b85d8"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fexpandvars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fexpandvars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fexpandvars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayanarijit%2Fexpandvars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayanarijit","download_url":"https://codeload.github.com/sayanarijit/expandvars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248693987,"owners_count":21146904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","expand","python","unix","variables"],"created_at":"2024-10-29T10:16:26.708Z","updated_at":"2025-04-13T09:43:59.366Z","avatar_url":"https://github.com/sayanarijit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expandvars\n\nExpand system variables Unix style\n\n[![PyPI version](https://img.shields.io/pypi/v/expandvars.svg)](https://pypi.org/project/expandvars)\n[![codecov](https://codecov.io/gh/sayanarijit/expandvars/branch/master/graph/badge.svg)](https://codecov.io/gh/sayanarijit/expandvars)\n\n## Inspiration\n\nThis module is inspired by [GNU bash's variable expansion features](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html). It can be used as an alternative to Python's [os.path.expandvars](https://docs.python.org/3/library/os.path.html#os.path.expandvars) function.\n\nA 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.\nFor example:\n\n```toml\n[default]\nmy_secret_access_code = \"${ACCESS_CODE:-default_access_code}\"\nmy_important_variable = \"${IMPORTANT_VARIABLE:?}\"\nmy_updated_path = \"$PATH:$HOME/.bin\"\nmy_process_id = \"$$\"\nmy_nested_variable = \"${!NESTED}\"\n```\n\n\u003e NOTE: Although this module copies most of the common behaviours of bash,\n\u003e it doesn't follow bash strictly. For example, it doesn't work with arrays.\n\n## Installation\n\n### Pip\n\n```\npip install expandvars\n```\n\n### Conda\n\n```\nconda install -c conda-forge expandvars\n```\n\n## Usage\n\n```python\nfrom expandvars import expandvars\n\nprint(expandvars(\"$PATH:${HOME:?}/bin:${SOME_UNDEFINED_PATH:-/default/path}\"))\n# /bin:/sbin:/usr/bin:/usr/sbin:/home/you/bin:/default/path\n```\n\n## Examples\n\nFor now, [refer to the test cases](https://github.com/sayanarijit/expandvars/blob/master/tests) to see how it behaves.\n\n## TIPs\n\n### nounset=True\n\nIf you want to enable strict parsing by default, (similar to `set -u` / `set -o nounset` in bash), pass `nounset=True`.\n\n```python\n# All the variables must be defined.\nexpandvars(\"$VAR1:${VAR2}:$VAR3\", nounset=True)\n\n# Raises UnboundVariable error.\n```\n\n\u003e NOTE: Another way is to use the `${VAR?}` or `${VAR:?}` syntax. See the examples in tests.\n\n### EXPANDVARS_RECOVER_NULL=\"foo\"\n\nIf you want to temporarily disable strict parsing both for `nounset=True` and the `${VAR:?}` syntax, set environment variable `EXPANDVARS_RECOVER_NULL=somevalue`.\nThis helps with certain use cases where you need to temporarily disable strict parsing of critical env vars, e.g. in testing environment, without modifying the code.\n\ne.g.\n\n```bash\nEXPANDVARS_RECOVER_NULL=foo myapp --config production.ini \u0026\u0026 echo \"All fine.\"\n```\n\n\u003e WARNING: Try to avoid `export EXPANDVARS_RECOVER_NULL` because that will disable strict parsing permanently until you log out.\n\n### Customization\n\nYou can customize the variable symbol and data used for the expansion by using the more general `expand` function.\n\n```python\nfrom expandvars import expand\n\nprint(expand(\"%PATH:$HOME/bin:%{SOME_UNDEFINED_PATH:-/default/path}\", environ={\"PATH\": \"/example\"}, var_symbol=\"%\"))\n# /example:$HOME/bin:/default/path\n```\n\n## Contributing\n\nTo contribute, setup environment following way:\n\nThen\n\n```bash\n# Clone repo\ngit clone https://github.com/sayanarijit/expandvars \u0026\u0026 cd expandvars\n\n# Setup virtualenv\npython -m venv .venv\nsource ./.venv/bin/activate\n\n# Install as editable including test dependencies\npip install -e \".[tests]\"\n```\n\n- Follow [general git guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project).\n- Keep it simple. Run `black .` to auto format the code.\n- Test your changes locally by running `pytest` (pass `--cov --cov-report html` for browsable coverage report).\n- If you are familiar with [tox](https://tox.readthedocs.io), you may want to use it for testing in different python versions.\n\n## Alternatives\n\n- [environs](https://github.com/sloria/environs) - simplified environment variable parsing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fexpandvars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayanarijit%2Fexpandvars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayanarijit%2Fexpandvars/lists"}