Skip to main content

A configuration management library

Project description

catenaconf logo

CatenaConf

PyPI - Format build passing License

Introduction

CatenaConf is a lightweight Python library designed for managing and operating configurations. It extends the Python dictionary type to manage configurations using key-value pairs and provides flexible operation functionalities.

Features

  • Lightweight: Depends only on the Python standard library, without any third-party dependencies.
  • Based on Python dictionaries to create configurations.
  • Access and modify configuration values via attributes.
  • Flexible update and merge mechanisms.
  • Ability to reference other configuration values within configuration values.

Installation

Install using pip:

pip install catenaconf

Usage

Creating Configuration

from catenaconf import Catenaconf

config = {
    "database": {
        "host": "localhost",
        "port": 3306
    }
}

cfg = Catenaconf.create(config)
  • Use the Catenaconf.create method to create a configuration from a dictionary.
  • The method returns a KvConfig instance.

Updating Configuration

Catenaconf.update(cfg, "database.user", "root") # Adds a user key-value pair in database
Catenaconf.update(cfg, "database", {"root": "root"}) # Replaces the value of database with {"root": "root"}
Catenaconf.update(cfg, "database", {"root": "root"}, merge=True) # Adds a root key-value pair in database
  • Use the Catenaconf.update method to update the configuration.
  • The first parameter is the KvConfig instance to be updated, the second parameter specifies the location of the value to be updated, the third parameter is the new value, and the fourth parameter (merge) indicates whether to merge or not.
  • merge parameter: Defaults to True. When set to True, if both the new value and the existing value are dictionaries, they will be merged instead of replacing the existing value. When set to False, the new value will directly replace the existing value.

Merging Configurations

config1 = {"database": {"host": "localhost"}}
config2 = {"database": {"port": 3306}}

merged_cfg = Catenaconf.merge(config1, config2)
  • Use the Catenaconf.merge method to merge multiple configurations.
  • Returns a merged KvConfig instance.

References and Resolving References

config = {
    "info": {
        "path": "/data",
        "filename": "a.txt"
    },
    "backup_path": "@{info.path}/backup/@{info.filename}"
}

cfg = Catenaconf.create(config)
Catenaconf.resolve(cfg)
  • Use the @{} format to reference other configuration values.
  • Use the Catenaconf.resolve method to resolve references within the configuration.

Converting to Dictionary

dict_config = Catenaconf.to_container(cfg, resolve=True)
dict_config = Catenaconf.to_container(cfg, resolve=False) # References within will not be resolved
  • Use the Catenaconf.to_container method to convert a KvConfig instance into a regular dictionary.
  • resolve parameter: Defaults to True. When set to True, internal references are resolved. When set to False, internal references are not resolved.

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

catenaconf-0.1.2.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

catenaconf-0.1.2.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file catenaconf-0.1.2.1.tar.gz.

File metadata

  • Download URL: catenaconf-0.1.2.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for catenaconf-0.1.2.1.tar.gz
Algorithm Hash digest
SHA256 66e85ef123d5f7ed1a1e004926c1dd0ee098104983ad7a16f4840f1bcb714035
MD5 a4b496d2f56928424c129ef72b628b18
BLAKE2b-256 e05b91fd34001b7a234f8e77cd0d0ae77f39737d2ba7f44019010506b94adb73

See more details on using hashes here.

File details

Details for the file catenaconf-0.1.2.1-py3-none-any.whl.

File metadata

  • Download URL: catenaconf-0.1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for catenaconf-0.1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1de625bd1bbbca26d7c1120b6859023ea3b0b1f5adae169926cd3bf8876cdf5d
MD5 f0b2ccb34faf292ea47e0780526ebe20
BLAKE2b-256 423c8acc64a5a30beff2134fcdccf17ab753281201210b25f9ac910a35cd06de

See more details on using hashes here.

Supported by

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