{"id":51030759,"url":"https://github.com/tqdm/envwrap","last_synced_at":"2026-06-22T00:02:03.469Z","repository":{"id":361916162,"uuid":"1241057138","full_name":"tqdm/envwrap","owner":"tqdm","description":"Override parameter defaults via environment variables \u0026 config files","archived":false,"fork":false,"pushed_at":"2026-06-07T18:54:13.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-10T21:04:34.512Z","etag":null,"topics":["appdir","appdirs","config","defaults","env","environment","partial","platformdirs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tqdm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-16T22:54:30.000Z","updated_at":"2026-06-07T18:51:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tqdm/envwrap","commit_stats":null,"previous_names":["tqdm/envwrap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tqdm/envwrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tqdm%2Fenvwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tqdm%2Fenvwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tqdm%2Fenvwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tqdm%2Fenvwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tqdm","download_url":"https://codeload.github.com/tqdm/envwrap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tqdm%2Fenvwrap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34629658,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["appdir","appdirs","config","defaults","env","environment","partial","platformdirs"],"created_at":"2026-06-22T00:02:02.876Z","updated_at":"2026-06-22T00:02:03.463Z","avatar_url":"https://github.com/tqdm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# envwrap\n\n[![CI](https://github.com/tqdm/envwrap/actions/workflows/test.yml/badge.svg)](https://github.com/tqdm/envwrap/actions/workflows/test.yml)\n[![coveralls](https://img.shields.io/coveralls/github/tqdm/envwrap/main?logo=coveralls)](https://coveralls.io/github/tqdm/envwrap)\n[![codecov](https://codecov.io/gh/tqdm/envwrap/graph/badge.svg?token=PEWICBIPVW)](https://codecov.io/gh/tqdm/envwrap)\n[![codacy](https://app.codacy.com/project/badge/Grade/6ca7a441560444489fd5c5b1548ab0de)](https://app.codacy.com/gh/tqdm/envwrap/dashboard)\n\n[![releases](https://img.shields.io/pypi/v/envwrap.svg?label=changelog)](https://github.com/tqdm/envwrap/releases)\n[![pypi/envwrap](https://img.shields.io/pypi/pyversions/envwrap.svg?logo=python\u0026logoColor=white)](https://pypi.org/project/envwrap)\n[![conda-forge::envwrap](https://img.shields.io/conda/v/conda-forge/envwrap.svg?label=conda-forge\u0026logo=conda-forge)](https://anaconda.org/conda-forge/envwrap)\n\nOverride parameter defaults via environment variables \u0026 config files.\n\n```py\nimport envwrap\n\n@envwrap.envwrap(\"name\", \"app\")\ndef func(a=1):\n    ...\n```\n\nPrecedence (descending):\n\n- call (`func(a=3)`)\n- environment (`NAME_APP_FUNC_A=2`, `NAME_FUNC_A=2`, `NAME_APP_A=2`, `NAME_A=2`)\n  - `UPPER_CASE` env vars -\u003e `lower_case` param names\n  - other cases aren't supported because Windows ignores case\n- config file:\n  - ./`{name}.{toml,yaml,yml,json,ini,cfg}::{app.func.a,func.a,app.a,a}`\n  - [platformdirs](https://platformdirs.readthedocs.io/en/latest/parameters.html).{user,site}_config_path(name, False)/\n    - `{app}.{toml,yaml,yml,json,ini,cfg}::{func.a,a}`\n    - `{name}.{toml,yaml,yml,json,ini,cfg}::{app.func.a,func.a,app.a,a}`\n  - ./`pyproject.toml::tool.name.{app.func.a,func.a,app.a,a}`\n- signature (`def foo(a=1)`)\n\n## Installation\n\nAny one of:\n\n- `pip install envwrap`\n- `conda install -c conda-forge envwrap`\n- `pip install \"git+https://github.com/tqdm/envwrap@main\"`\n\n\u003e [!TIP]\n\u003e Note that [`tqdm`](https://github.com/tqdm/tqdm) ships with a basic [`tqdm.utils.envwrap`](https://tqdm.github.io/docs/tqdm.utils/#envwrap), which falls back to the original env-var-only (no config file support) implementation if `import envwrap` fails.\n\n## Advanced Usage\n\n### CLI integration\n\n```py\n\"\"\"CLI example program using envwrap for configuration management.\n\nUsage:\n  myapp.py [options] \u003carg1\u003e [\u003carg2\u003e]\n\nOptions:\n  -h, --help    Show this help message and exit.\n  -o=\u003cvalue\u003e, --option=\u003cvalue\u003e  An option [default: foo].\n\nArguments:\n  \u003carg1\u003e         An argument.\n  \u003carg2\u003e         An integer argument [default: 2:int].\n\nDefaults above may be overridden by environment variables or config files:\n- `MYAPP[_CLI]_*`\n- `{.,~/.config/myapp,/etc/xdg/myapp}/myapp[/cli].{toml,yml,json,ini}::[cli.]*`\n- `pyproject.toml::tool.myapp[.cli]*`\n\"\"\"\nimport argopt, shtab, envwrap\n\nONLY_PASS_VALID = True # trim envwrap defaults based on parser's valid actions\n\nif __name__ == \"__main__\":\n    parser = argopt.argopt(__doc__)\n    shtab.add_argument_to(parser)\n\n    defaults = envwrap.get_defaults(\"myapp\", \"\", \"cli\")\n    if ONLY_PASS_VALID:\n        valid = {i.dest for i in parser._actions}\n        defaults = {k: defaults[k] for k in defaults.keys() \u0026 valid}\n\n    parser.set_defaults(**defaults)\n    args = parser.parse_args()\n    print(args)\n```\n\n### Live-reload\n\nTo force re-reading config files \u0026 environment variables without restarting the process:\n\n```py\nenvwrap.get_defaults.cache_clear()\n```\n\n### Debugging\n\nA CLI tool can print defaults. For example, with this config:\n\n```toml\n# config file: foo.toml\n[test]\na = 1337\nb = 2\n```\n\n```sh\npython -m envwrap --help\nFOO_A=42 python -m envwrap foo test\n```\n\nwill print:\n\n```py\n\u003e\u003e\u003e @envwrap.envwrap('foo', '')\n\u003e\u003e\u003e def test(...):\n...    ...\nwill use defaults:\n{'a': '42', 'b': 2, ...}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftqdm%2Fenvwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftqdm%2Fenvwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftqdm%2Fenvwrap/lists"}