Skip to main content

Turn your dataclasses into configs seamlessly.

Project description

Dataconfigs

About

Dataconfigs provides a seamless integration between dataclasses as configs and any configurable classes that use these configs. The most powerful feature is that config attributes become part of configurable, i.e., no need for explicit .config attribute (unless specified otherwise). This keep class definitions very siple yet decouples configurable parameters from class attributes. In terms of configs, it is a simplified hydra alternative, yet supporting more features.

Features

Last 3 features are in development:

  • Embedded config params in configurables (no need for separate .config attribute, unless specified otherwise)
  • Easy type annotations (visible annotations, even though configs are never inherited from)
  • Support for multiple, nested, hierarchical, and union configs, as well as non-atomic types
  • Various file support (json, yaml, pickle)
  • CLI support
  • Decorator-based (inspired by Hydra)

Quick Start

Install the library:

pip install dataconfigs

Check the demo.

Simple Script Example

  1. Simply define your config (must be a datacalss and contain the word Config in name!)
  2. Extend the config with your configurable (it won't turn into a dataclass unless specified!)
  3. Instantiate your configurable by optionally overwriting default config parameters
from datacalsses import dataclass, is_dataclass
from dataconfigs import configurable, show_config_params

@datacalss
class MyConfig:
    """My config class
    Args:
        param1 (int): The first parameter.
        param2 (str): The second parameter.
    """
    param1: int = 0
    param2: str = "param2"

@configurable
class MyConfigurable(MyConfig):
    def __init__(self, attr1=1, attr2=2):
        print(self.param1, self.param2) # Already available!

assert not is_dataclass(MyConfigurable) # Only attributes were copied!
obj = MyConfigurable("attr1", param1=1) # Can overwrite config params! 
# 1, 'param2'

Simple CLI Example (only ideas for now)

Assume you have config.json file as follows:

{
    "param1": 111,
    "param2": "222"
}

One possibility is to directly make the configurable. Example main.py:

@configurable.main("path/to/config.json", MyConfigurable, attr1="attr1")
def main(my_configurable):
    pass

if __name__ == "__main__":
    main()

We can still overwrite config params or the whole config file when calling:

dataconfigs main.py --param2 'custom' # 111, 'custom'
dataconfigs main.py --config path/to/config2.yaml

If we call dataconfigs main.py -h, descriptions will be extracted from docstrings:

Options:
--param1 : (int) The first parameter. Defaults to 111.
--param2 : (str) The second parameter. Defaults to '222'.

Tutorials (TODO)

  1. Config classes: there are many ways to define configs. The only restriction is that they must be dataclasses and contain an "Config" word in their class name (see basics):
    • Basics
    • Unions & non-atomic types
    • Multiple, nested and hierarchical configs
    • Config files (json, yaml, pkl, etc.)
  2. Configurables: any class (configurable) that extends the config(-s) will only obtain its attributes and won't alter its class definition. The configurable class can inherit from any other parents in the usual manner.
    • Config vs non-config attributes
    • Various ways to instantiate
  3. Compatibility with Third Party CLI
    • Pytorch Lightning
    • Tensorflow
    • Optuna
    • Ray

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

dataconfigs-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

dataconfigs-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataconfigs-0.1.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for dataconfigs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c56f0be32762dd1be33dec439e883b87e2d5e8088f4e23a910b1a0f5c545355
MD5 99909df91a0cf9d730dfc2dfffe9d55c
BLAKE2b-256 031ca3a550e314a7f0ee90dd42535643dc6adafd60f9efd11724cc460ce88881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dataconfigs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.7

File hashes

Hashes for dataconfigs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac494a18b6e2b31aae23f60c56676f9b218007883386eaf74cc7352e65b53331
MD5 e4eae7fc433148f3d158a617bfd7e0f6
BLAKE2b-256 51ba83c5e928c50d97cbaf5ab50ccac889e2d2d9d0ceae7fde0175dbd992f48c

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