Skip to main content

A a simple python configuration management and object instantiation tool

Project description

Tests

konfigurator

konfigurator is a lightweight Python configuration management utility that allows you to define, override, and instantiate configuration dictionaries and Python classes from simple config files or command-line arguments.

Further, it allows you to instantiate objects from classes using import paths. In this way, no global registry or any disclosure of your private code is needed.

The instantiation via import path is inspired by https://github.com/Farama-Foundation/HighwayEnv

Features

  • Load Python-based configuration files as dictionaries.
  • Override configuration parameters via command-line.
  • Instantiate Python classes from config dictionaries using import paths.

Installation

cd into repository and run

pip install .

To install in developer mode (with pre-commit and pytest) run

pip install -e .[dev,test]

Usage

  1. Load a configuration file

    Your configuration file is a pure python file (e.g., config.py) should define a dictionary named config:

    # config.py
    work_dir = "/tmp/my_work_dir"
    class_config_1: {
        "type": "my_module.MyClass",
        "name": "default_name"
    }
    

    You will be able to instantiate an object from the configuration class_config_1 (see ).

    Load this configuration in Python:

    from konfigurator import load_config
    
    config = load_config(config_path="config.py")
    
  2. Override from command-line and save result

    You can override nested config values via CLI and save the modified config to disk, e.g.:

    python script.py \
    --config config.py \
    --override experiment_dir=/tmp/experiment \
    --override class_config_1.name=overridden_name \
    --override class_config_1.type=5.0
    

    Currently, floats, ints, and booleans are converted into their respective type. Strings and other types remain strings.

  3. Instantiate classes from config

    Use the instantiate_class_from_config to build objects dynamically (IMPORTANT: the value for the key type defines the import path):

    from konfigurator import instantiate_object_from_config
    
    class_config_1: {
        "type": "my_module.MyClass",
        "name": "default_name"
    }
    
    my_obj = instantiate_object_from_config(class_config_1)
    

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

konfigurator-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

konfigurator-0.2.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file konfigurator-0.2.0.tar.gz.

File metadata

  • Download URL: konfigurator-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for konfigurator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e7e9db47dd8aefc45dac4780e7511e2b438613fb58f1f2c93c0ad64485f24b2
MD5 803de4f98476304db600fd97f43cfb06
BLAKE2b-256 31dc527d7fc67185e1820eca57796d0ea115e59203a4aeff28e2cdd2a27ee051

See more details on using hashes here.

File details

Details for the file konfigurator-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: konfigurator-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for konfigurator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a450c76b2b8f4635be182acf60e3d108ec605e38e6248ca43ba494ce07de4e4a
MD5 dae04b20d271f40179a83a634c3f5b51
BLAKE2b-256 82ca6d43213df51efc0436137c801f9b4ddb0a5ef2959d68831782c43d19dfea

See more details on using hashes here.

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