Skip to main content

Merge your config files and set parameters from the command line in a simple way.

Project description

CLI Config

CLI Config: Lightweight library that provides routines to merge nested configs and set parameters from command line. It is also provide processing functions that can change the whole configuration before and after each config merge, config saving and config loading. It also contains many routines to manipulate the config as flatten or nested dicts.

Documentation: here

Release PythonVersion License

Ruff_logo Black_logo

Ruff Flake8 Pydocstyle MyPy PyLint

Tests Coverage Documentation Status

Installation

In a new virtual environment, simply install the package with:

pip install cliconfig

This package is OS independent and supported on Linux, macOS and Windows.

Minimal usage

Make default config file(s) in your project (configs are merged from left to right):

# main.py
from cliconfig import make_config

config = make_config('default1.yaml', 'default2.yaml')
config_dict = config.dict  # native python dict

Then launch your script with additional config(s) file(s) and parameters by command line. The additional configs are merge on the default ones then the parameters are set.

python main.py --config first.yaml,second.yaml --param2=-2 --letters.letter2='B'

By default, these additional configs cannot add new parameters to the default config (for security and retro-compatibility reasons).

See Quick Start section of the documentation for more details.

With processing

The library provide powerfull tools to modify the configuration called "processings". One of the possibility they add is to merge multiple configurations, copy a parameter on another, enforce type and more. To do so, simply adding the corresponding tags to your parameter names (on config files or CLI parameters).

For instance with these config files:

---  # main.yaml
path_1@merge_add: sub1.yaml
path_2@merge_add: sub2.yaml
config3.select@select: "config3.param1"

--- # sub1.yaml
config1:
  param@copy@type:int: config2.param
  param2@type:int: 1

--- # sub2.yaml
config2.param@type:None|int: 2
config3:
  param1: 0
  param2: 1

Here main.yaml is interpreted like:

path_1: sub1.yaml
path_2: sub2.yaml
config1:
  param: 2  # the value of config2.param
  param2: 1
config2:
  param: 2
config3:
  select: "config3.param1"
  param1: 0
  # param2 is deleted because it is not in the selection

Then, all the parameters in config1 and config2 have enforced types (config2.param can also be None) and changing config2.param will also update config1.param accordingly (which is protected by direct update).

See Processing section of the documentation for details on processing and how to create your own.

How to contribute

For development, install the package dynamically and dev requirements with:

pip install -e .
pip install -r requirements-dev.txt

Everyone can contribute to CLI Config, and we value everyone’s contributions. Please see our contributing guidelines for more information 🤗

License

Copyright (C) 2023 Valentin Goldité

This program is free software: you can redistribute it and/or modify it under the terms of the MIT License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This project is free to use for COMMERCIAL USE, MODIFICATION, DISTRIBUTION and PRIVATE USE as long as the original license is include as well as this copy right notice at the top of the modified files.

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

cliconfig-0.6.0.tar.gz (75.6 kB view details)

Uploaded Source

Built Distribution

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

cliconfig-0.6.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file cliconfig-0.6.0.tar.gz.

File metadata

  • Download URL: cliconfig-0.6.0.tar.gz
  • Upload date:
  • Size: 75.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for cliconfig-0.6.0.tar.gz
Algorithm Hash digest
SHA256 2820dc015bc9db07f4cb9f8cc85833f84bd010888c318149ad1724c562df5670
MD5 7f990dac91d500ab33087fb250552a5e
BLAKE2b-256 3443035096398b9931fe3e485a243ca26feeb75774de5e4652cc88ef53fc0cd3

See more details on using hashes here.

File details

Details for the file cliconfig-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: cliconfig-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for cliconfig-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29dea1fe7e3dc36f8fa727240272bb163a994c50e1c52ed62818742875350242
MD5 5994d7eb103709f5d1c69a4560af112a
BLAKE2b-256 8be7d7921d87b2fcec70d7870afd515e33007f57c94a37c149f2fe60c6ef7d9a

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