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
.configattribute, 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
- Simply define your config (must be a datacalss and contain the word Config in name!)
- Extend the config with your configurable (it won't turn into a dataclass unless specified!)
- 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)
- 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.)
- 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
- 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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dataconfigs-0.1.0.tar.gz | 18.3 kB | Without provenance | Details for dataconfigs-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dataconfigs-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dataconfigs-0.1.0-py3-none-any.whl |
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
|
Security for dataconfigs 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.