Skip to main content

ClearConf is a library created to support easy and manageble python configuration. It consists in a CLI tool to manage the configuration directory, and in a python class (BaseConfig) which adds additional functionalities to a configuration class.

Project description

clearconf

ClearConf is a library created to support easy and manageble python configuration. It consists in a CLI tool to manage configuration and in a python class (BaseConfig) which adds additional functionalities to a configuration class.

Installation

To install ClearConf just run

pip install clearconf

Usage

The first step to use clearconf would be to use the CLI tool in the root of your project to initialize it:

cconf init

This will generate a config directory where you will store your configurations and a .clearconf file used by ClearConf to keep track of configurations. After this you can start populating your config directory. You can find examples of configuration files in the Example section.

❗ClearConf recursively recognize as configuration all python files ending with _conf

Finally you can import a generic configuration in your script as

from configs import Config

and use it as you please.

When the script is run, if a default configuration has been set via the CLI

cconf defaults add main.py test_conf.py

such configuration will be dynamically imported.

Otherwise, clearconf will list all the available configuration and ask you to pick one.

0: example3_conf
1: example1_conf
2: example2_conf
3: example4_conf
Choose a configuration file:

CLI

For more informations on the command line interface check the related README here

Examples

Example 1

A configuration file for machine learning could be structure as follow.

from models import MLP
from datasets import ImageNet


class Config(BaseConfig):
    seed = 1234

    class Model:
        architecture = MLP

        class Params:
            num_layers = 16
            layers_dim = [96] * num_layers


    class Data:
        dataset = ImageNet

        class Params:
            root = './data/PCN'
            split = 'PCN.json'
            subset = 'train'

The training/test script could read the configuration as follows:

from configs import Config

Model = Config.Model
Data = Config.Data

model = Model.architecture(**Model.Params.to_dict())
dataset = Data.dataset(**Data.Params.to_dict())

Example 2

It is also possible to simplify the configuration further using inheritance. For example the Model configuration seen before would look like this:

from models import MLP

class Config(BaseConfig):
    seed = 1234

    class Model(MLP):

        class Params:
            num_layers = 16
            layers_dim = [96] * num_layers

The corresponding scirp is:

from configs import Config

Model = Config.Model
model = Model(**Model.Params.to_dict())

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

clearconf-0.3.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

clearconf-0.3.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file clearconf-0.3.1.tar.gz.

File metadata

  • Download URL: clearconf-0.3.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.11 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for clearconf-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a649c4d4dc0e78e43f40fd185c51d50b25282ae9fcf2d95a48c04030ffa342c3
MD5 2d7919fae62fd0c53976ace9eec3cea8
BLAKE2b-256 e0cc430cd120ce0eb51bf734245a97615298d3a0cc9232355914847d0c8a1824

See more details on using hashes here.

File details

Details for the file clearconf-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: clearconf-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.11 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for clearconf-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 793d4b6c9879a91610b1d6e017bfecf744984f78c69b1a1fd0812b6b4e0283d9
MD5 c48dcf76e15fddda68f95bc07d27c777
BLAKE2b-256 b690e8d70cf62b1527c05fa34e0e5e65c7d59e79f8fe739d2eb951ddb4cb4563

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