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-0.3.0.tar.gz (14.5 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-0.3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cfg_mgr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4379d1d0f4e0690087a5a7dbf48c28b14c6cb4bae40d05d2a06aca20471787c3
MD5 91df6c9ca31885901a954799458aabc4
BLAKE2b-256 0ff368cffc750c6d9c8b0d7435fd8cd73efbf5d4b396202aa49ff086a01e4254

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfg_mgr-0.3.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-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cfg_mgr-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 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-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12416bd5ddf9369dcaff777905e793f95e77fd56753666b8f68d057e054f5c66
MD5 6c23d295ebbb2ccce2ea0eb47d39d5b1
BLAKE2b-256 b2339c4610678503f5a63ddbdd0ee0a1f9374f39bc0442597df1a10d4f4c58ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfg_mgr-0.3.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