Skip to main content

Override parameter defaults via environment variables & config files

Project description

envwrap

CI coveralls codecov codacy

Override parameter defaults via environment variables & config files.

import envwrap

@envwrap.envwrap("name", "app")
def func(a=1):
    ...

Precedence (descending):

  • call (func(a=3))
  • environment (NAME_APP_FUNC_A=2, NAME_FUNC_A=2, NAME_APP_A=2, NAME_A=2)
    • UPPER_CASE env vars -> lower_case param names
    • other cases aren't supported because Windows ignores case
  • config file:
    • ./{name}.{toml,yaml,yml,json,ini,cfg}::{app.func.a,func.a,app.a,a}
    • platformdirs.{user,site}_config_path(name, False)/
      • {app}.{toml,yaml,yml,json,ini,cfg}::{func.a,a}
      • {name}.{toml,yaml,yml,json,ini,cfg}::{app.func.a,func.a,app.a,a}
  • signature (def foo(a=1))

Advanced Usage

Live-reload

To force re-reading config files & environment variables without restarting the process:

envwrap.get_defaults.cache_clear()

Debugging

A CLI tool can print defaults. For example, with this config:

# config file: foo.toml
[test]
a = 1337
b = 2
python -m envwrap --help
FOO_A=42 python -m envwrap foo test

will print:

>>> @envwrap.envwrap('foo', '')
>>> def test(...):
...    ...
will use defaults:
{'a': '42', 'b': 2, ...}

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

envwrap-0.2.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

envwrap-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file envwrap-0.2.0.tar.gz.

File metadata

  • Download URL: envwrap-0.2.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for envwrap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 774137e586d787be9fc08baa16550659d3576c6e45b469d4d6f2b5ef2605608e
MD5 107c9da478c4f25a03614011b3da6840
BLAKE2b-256 76f057fcbcf9423d18a15c486705b9609193edb2d4ba29519600810a4519d663

See more details on using hashes here.

Provenance

The following attestation bundles were made for envwrap-0.2.0.tar.gz:

Publisher: test.yml on tqdm/envwrap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file envwrap-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: envwrap-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for envwrap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b6c643c0ee181f0c1b10100cd8d6eea35f87874bf5b8b81b689ea473dd858f4
MD5 9f07e76313dd89ba5a428c03facecee2
BLAKE2b-256 b08b1f5e25b82d0a65f36c91b734c5262f9c7d49775266da48a9740e46e62c06

See more details on using hashes here.

Provenance

The following attestation bundles were made for envwrap-0.2.0-py3-none-any.whl:

Publisher: test.yml on tqdm/envwrap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page