A a simple python configuration management and object instantiation tool
Project description
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
-
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")
-
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.
-
Instantiate classes from config
Use the
instantiate_class_from_configto build objects dynamically (IMPORTANT: the value for the keytypedefines 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file konfigurator-0.2.1.tar.gz.
File metadata
- Download URL: konfigurator-0.2.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b0d4c07e6fe4571ba10301fa70bbfd50201ce64db16417277802ef4930d5e8
|
|
| MD5 |
416bc7d5af06c65a3db8df0f8b5210f9
|
|
| BLAKE2b-256 |
09738c8ec47225f78e556ad377f608af417164e2237fadd39ea508cb07d69369
|
File details
Details for the file konfigurator-0.2.1-py3-none-any.whl.
File metadata
- Download URL: konfigurator-0.2.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7347b948c65a45a41f993f5be870a3d4d6f533947d4eec002646cb0d83eb615
|
|
| MD5 |
fe353ed6ac7682d170afc15a09d01a44
|
|
| BLAKE2b-256 |
61cf54eb4a43534bf6329b0c745c4ce2fb1bd49c9be32de8cff413a1688ae650
|