A simple wrapper around dataclasses, for general configuration
Project description
Confclasses
Create dataclass-style classes that can be used for configuring a Python tool. The idea is to handle loading and saving the config from files while allowing simpler IDE usage with the config. We don't need 90% of the features in dataclasses, so we make the API easier.
The module is designed to have a global config object that is instantiated at the start and then loaded dynamically later. Please see the common usage section for an example.
confclasses_comments is also shipped with this tool. It uses ruamel.yaml to add comments and ast to get the "docstring" of the annotations (fields) in the config classes.
Common usage
Create a config.py to store the config.
# config.py
@confclass
class RepeatingConfig:
test: str
default1: int = 123
@confclass
class NestedConfig:
field1: str = "foo"
field2: str = "bar"
""" test document for field 2 """
hashed_field3: RepeatingConfig = RepeatingConfig(test="nested")
@confclass
class ExampleConfig:
nested: NestedConfig
field3: int = 42
""" test document for field 3 """
hashed_field1: list = ["test", "items"]
hashed_field2: dict = {"key1": "value1"}
hashed_field4: RepeatingConfig = RepeatingConfig(test="base")
config = ExampleConfig()
Loading it at the start
# main.py
from confclasses import load_config
from config import config
from .example_module import example_function
def main():
with open('conf.yaml', 'r') as f:
load_config(config, f.read())
example_function()
In the example_module
# example_module.py
from config import config
def example_function():
print(config.field3)
Planned changes
- XDG support
- Move comments code into base file
- Type checking
- Tests in pipelines
- Contribution guide
- Scalars mapped to confclass
- remove PyYAML
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file confclasses-1.0.0.dev0.tar.gz.
File metadata
- Download URL: confclasses-1.0.0.dev0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f258588c8be14b9bf4c186950d10a6709220baf11af98bfba3eba2be62431876
|
|
| MD5 |
ba5f4dab4913f418bfd9dfcc2a91510d
|
|
| BLAKE2b-256 |
1f7a6b7f1970d969526ac71d6a3d38c189c54b8c33c113164db8a6ffa4d5ed39
|
Provenance
The following attestation bundles were made for confclasses-1.0.0.dev0.tar.gz:
Publisher:
pypi.yaml on LexisNexis-RBA/ins-datahub-module-py-confclasses
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confclasses-1.0.0.dev0.tar.gz -
Subject digest:
f258588c8be14b9bf4c186950d10a6709220baf11af98bfba3eba2be62431876 - Sigstore transparency entry: 629899015
- Sigstore integration time:
-
Permalink:
LexisNexis-RBA/ins-datahub-module-py-confclasses@78175429ae876b68df07138c4a11832ee6d6500a -
Branch / Tag:
refs/tags/v1.0.0.dev0 - Owner: https://github.com/LexisNexis-RBA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@78175429ae876b68df07138c4a11832ee6d6500a -
Trigger Event:
push
-
Statement type:
File details
Details for the file confclasses-1.0.0.dev0-py3-none-any.whl.
File metadata
- Download URL: confclasses-1.0.0.dev0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c977fb9b2fe1ed053a6c28479e958d5250dd2a0cd3172e0bf9128dca820f0534
|
|
| MD5 |
11e0213c28baf505c7109928f43314a0
|
|
| BLAKE2b-256 |
6dada381eaddf781478ac8fbf22105ff40d512650d76b2ab1cc528cf035e6ab7
|
Provenance
The following attestation bundles were made for confclasses-1.0.0.dev0-py3-none-any.whl:
Publisher:
pypi.yaml on LexisNexis-RBA/ins-datahub-module-py-confclasses
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confclasses-1.0.0.dev0-py3-none-any.whl -
Subject digest:
c977fb9b2fe1ed053a6c28479e958d5250dd2a0cd3172e0bf9128dca820f0534 - Sigstore transparency entry: 629899048
- Sigstore integration time:
-
Permalink:
LexisNexis-RBA/ins-datahub-module-py-confclasses@78175429ae876b68df07138c4a11832ee6d6500a -
Branch / Tag:
refs/tags/v1.0.0.dev0 - Owner: https://github.com/LexisNexis-RBA
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@78175429ae876b68df07138c4a11832ee6d6500a -
Trigger Event:
push
-
Statement type: