Skip to main content

Simple out-of-box configs

Project description

cfgmgr

Simple out of the box configurations for python projects

Basic usage

import cfgmgr

cfgmgr.make_config(env_prefix="CFG_", file_path="config.json", find_file=True)
some_val = cfgmgr.getkey('key')
cfgmgr.setkey('key', 'new_val')
config = cfgmgr.get()          # the global Config object itself

make_config

  • Initializes a global Config as per args specified
  • Pass in env_prefix to read values from environment variables
    • env_prefix will be prefixed to the keys before reading the environment variable
    • Ex. env_prefix="CFG_" will effectively translate cfgmgr.getkey('foo') to os.getenv('CFG_foo')
  • Values are resolved dynamically, so cfgmgr.getkey will respect environment variables set via os.environ (Useful in test cases)
  • file_path attempts to resolve the extension and defers to the corresponding loader
    • JSON and env are always supported. TOML is supported on Python 3.11+ (tomllib). YAML and dotenv are supported when their packages are installed — pip install cfg-mgr[yaml] / cfg-mgr[dotenv].
    • Custom Loaders can be implemented and registered via a decorator cfgmgr.fileloaders.register('.extension')
  • find_file, if True, will crawl upwards from cwd until it finds a match for file_path
  • include_key, if given, enables config includes: a config file may name another file under that key to be pulled in as a base. The including file overrides the included one; nested mappings are deep-merged. Include chains are followed recursively and cycles raise IncludeCycleError.

getkey and setkey

  • Getter and setter for individual keys on the global default Config object
  • getkey(key, default=None) returns the resolved value, or default if absent
  • setkey(key, value) sets an override (highest priority)
  • Both raise AttributeError if make_config has not been called prior to the call

get

  • Returns the global default Config object itself (a MutableMapping), or None if make_config has not been called
  • Use it for mapping-style access: cfgmgr.get()['key'], 'key' in cfgmgr.get(), iteration, etc.

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

cfg_mgr-1.0.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

cfg_mgr-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cfg_mgr-1.0.0.tar.gz.

File metadata

  • Download URL: cfg_mgr-1.0.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cfg_mgr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ef03534019c524dc953c49774eed824acefe731c5031c201cb87db7b113bd90a
MD5 c00893505e4436de66fa4fd6f1d131cb
BLAKE2b-256 8b80e4143055e5a7c3500f2345dd3e3482b10a486e8d8f19e512561fbdec2484

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfg_mgr-1.0.0.tar.gz:

Publisher: release.yml on raghavj98/cfgmgr

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

File details

Details for the file cfg_mgr-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cfg_mgr-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cfg_mgr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df17dfdfb48ab34cbf8a3c01a4d205e681ce53e1b4a5360e22df644bf1b0ebf5
MD5 4946e51754fb336a47b7c6dc43a900c5
BLAKE2b-256 94c3f5b3c4c5d46fefc298373b6852837a221c1bd52505dec599dd2cfc622093

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfg_mgr-1.0.0-py3-none-any.whl:

Publisher: release.yml on raghavj98/cfgmgr

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