Skip to main content

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

Metadata

Release files for dataconfigs 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataconfigs 0.1.0
File Size Uploaded
dataconfigs-0.1.0.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dataconfigs 0.1.0
File Interpreter ABI Platform
dataconfigs-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / dataconfigs-0.1.0.tar.gz

Download URL dataconfigs-0.1.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3c56f0be32762dd1be33dec439e883b87e2d5e8088f4e23a910b1a0f5c545355
BLAKE2b-256 checksum
How to use checksums
031ca3a550e314a7f0ee90dd42535643dc6adafd60f9efd11724cc460ce88881
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.7

Release files / dataconfigs-0.1.0-py3-none-any.whl

Download URL dataconfigs-0.1.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac494a18b6e2b31aae23f60c56676f9b218007883386eaf74cc7352e65b53331
BLAKE2b-256 checksum
How to use checksums
51ba83c5e928c50d97cbaf5ab50ccac889e2d2d9d0ceae7fde0175dbd992f48c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page