Skip to main content

A configuration management library

Project description

catenaconf logo

CatenaConf

Codecov Package version PyPI - Python Version

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.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: catenaconf-0.1.2.tar.gz
  • Upload date:
  • Size: 10.6 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.tar.gz
Algorithm Hash digest
SHA256 5111f38d21477ad7a41e5d068cd8069919499a909d44345479ed4cfc0665f6ed
MD5 c22f36dc3bd42b09d1bb82e000e3d7e4
BLAKE2b-256 7bca845ec6f8f2f94b384d5a23e4dd8fe4ee6fde782dfed4fa97f7bd1eef8596

See more details on using hashes here.

File details

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

File metadata

  • Download URL: catenaconf-0.1.2-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-py3-none-any.whl
Algorithm Hash digest
SHA256 ad19604533ac05e038289254b8c71d524e3d511e8b229ea4d81eedc8d5f861f1
MD5 f4f353ebfcb91b6ba13bd7dd2fdc9ae3
BLAKE2b-256 47765b9e23c66fe7e6563fce2df4f7c7b15e3718e45b3d81ff419a7a6164a1d9

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