Skip to main content

Config-Segregate simplifies Config management by enabling efficient, customizable configurations through classifier-based loading.

Project description


Build Status PyPI Version Supported Python Version

Documentation


Config-Segregate

Config-Segregate is a Python library that simplifies the management of complex configuration files. It allows you to split configurations into multiple files, use different formats (JSON, YAML, TOML), and apply updates to a base configuration, reducing redundancy and making it easier to manage large configurations. Also, it works well with Pydantic.

Features

  • Modular Configurations: Split your configuration into multiple files, each in a different format if needed.
  • Base and Updates: Define a base configuration and apply updates from other files on top of it, supporting nested updates.
  • Support for JSON, YAML, and TOML: Easily load configurations in multiple formats.
  • Custom Readers: Extend the library by registering custom reader functions for additional file formats.
  • Segregation Options: Control how configurations are merged, with options to disable nested updates or remove specific keys.

Requirements

Python 3.8+

Installation

$ pip3 install config-segregate

Usage

Basic Example

Suppose you have a configuration file main_config.json that references a base configuration and another settings file:

{
    "__base__": "${{ base_config.json }}",
    "logging": {
        "level": "DEBUG",
        "settings": "${{ ./settings/settings.json }}"
    }
}

You can load this configuration using the load_config function:

from config_loader import load_config

config = load_config("path/to/main_config.json")
print(config)

This will load the main_config.json, resolve the referenced paths, apply updates from the file on top of the base configuration, and return the final merged configuration as a Python dictionary.

Segregation Options

You can control how configurations are merged using the __segregate_options__ key:

{
    "__base__": "${{ base_config.json }}",
    "__segregate_options__": {
        "disable_nested_update": true,
        "remove_keys": ["obsolete_key"]
    },
    "logging": {
        "level": "DEBUG"
    }
}

Custom Readers

To add support for custom file formats, register a custom reader function:

from config_loader import register_reader

def read_custom_file(path_to_file):
    with open(path_to_file) as custom_file:
        data = custom_file.read()
        # Process your custom data format here and return as a dictionary
        return process_custom_data(data)

register_reader(".custom", read_custom_file)

Now, you can load .custom files just like any other supported format:

config = load_config("path/to/config.custom")

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

config_segregate-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

config_segregate-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file config_segregate-0.1.0.tar.gz.

File metadata

  • Download URL: config_segregate-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Linux/6.5.0-1025-azure

File hashes

Hashes for config_segregate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70da79caba43e90e427197f02ff52598ec47fcf2794d43ce2ce16bac68127ecb
MD5 da2d61c10346bb2a0f27d19ac611431b
BLAKE2b-256 4726f0fb239400011330ea44f03757ede2759eb17acfdaeb07752cd9fd0f2870

See more details on using hashes here.

File details

Details for the file config_segregate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: config_segregate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.9 Linux/6.5.0-1025-azure

File hashes

Hashes for config_segregate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e1ecaf7fa5ce0fa7630f9c74d72edda8d12d243cc31389b7051d03d937ab598
MD5 0dd6e4634116141fad6da53011344a4d
BLAKE2b-256 feb58801b98a76a481ac6d275d1c605f1b4604d7a01893b0e2ad816ef1e1e014

See more details on using hashes here.

Supported by

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