Configuration tools
Project description
CONfiguration tools for MAnaging your environment (con24ma)
A practical Python package for creating command-line interfaces from dataclasses with powerful argument parsing capabilities.
Installation
pip install ./con24ma
Quick Start
Basic Setup
from dataclasses import dataclass
from con24ma import DataClassConfig, ArgField, DictField
@dataclass
class Config(DataClassConfig):
name: str = ArgField('myapp', help="Application name")
debug: bool = ArgField(False, help="Enable debug mode")
config: dict = DictField(help="Additional configuration")
# Parse and use
config, remaining_args = Config.parse_args()
print(f"Running {config.name} with debug={config.debug}")
Command Line Usage
python script.py --name MyApp --debug --config timeout=30 retries=3
# Output: Running MyApp with debug=True
# config.config = {'timeout': 30, 'retries': 3}
Real-World Example
from dataclasses import dataclass
from typing import Optional
from con24ma import DataClassConfig, ArgField, DictField
@dataclass
class ModelConfig(DataClassConfig):
# Core model settings
model: str = ArgField('resnet50', ['-m'], help="Model architecture name")
model_kwargs: dict = DictField(help="Additional model parameters as key=value")
# Training settings
pretrained: Optional[bool] = ArgField(None, help="Use pretrained weights")
trained_file: Optional[str] = ArgField(None, help="Path to trained model file")
# Usage
config, _ = ModelConfig.parse_args()
python train.py -m efficientnet_b0 --pretrained --model-kwargs drop_rate=0.2 num_classes=1000
Key Features
- Type-safe: Full dataclass type support with automatic CLI generation
- DictField: Built-in support for
key=valueargument parsing - Flexible: Custom argument destinations, choices, validation
- Serializable: Easy JSON configuration save/load
- Extensible: Hook methods for custom processing
Documentation
For detailed documentation and advanced usage examples:
- Field Types Guide - Complete reference for ArgField, DictField, and other field types
- Argument Parsing Details - Deep dive into the kwargs parsing system and advanced argument handling
Basic API
DataClassConfig
Main base class for configuration dataclasses.
@dataclass
class Config(DataClassConfig):
# Define fields with ArgField/DictField
pass
# Parse arguments
config, remaining = Config.parse_args()
ArgField
Standard command-line argument field.
# Basic usage
name: str = ArgField("default", help="Help text")
# With custom options
verbose: bool = ArgField(False, ['-v', '--verbose'], help="Verbose mode")
mode: str = ArgField("train", choices=['train', 'test'], help="Mode")
DictField
Dictionary field for key=value parsing.
# Parse --config key1=value1 key2=value2
config: dict = DictField(help="Configuration parameters")
Best Practices
Configuration Validation
@dataclass
class Config(DataClassConfig):
learning_rate: float = ArgField(0.001, help="Learning rate")
@classmethod
def prep_parsed(cls, parsed: dict) -> dict:
if parsed.get('learning_rate', 0) <= 0:
raise ValueError("Learning rate must be positive")
return parsed
Configuration Persistence
import json
# Save configuration
config, _ = Config.parse_args()
with open('config.json', 'w') as f:
json.dump(config.asdict(), f, indent=2)
# Load and merge with CLI args
with open('config.json', 'r') as f:
saved_config = json.load(f)
config, _ = Config.parse_args(base_dict=saved_config)
Requirements
- Python 3.9+
- Standard library only (no external dependencies)
License
This project is released under MIT License.
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 con24ma-1.1.0.tar.gz.
File metadata
- Download URL: con24ma-1.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ec065c421b638d9b3ba7f25c0150fbe8cb94138ea7ce2aec74a242a3c0f26e0
|
|
| MD5 |
dfd273e5cd7e556dbc58380b2f248383
|
|
| BLAKE2b-256 |
f7ef3af3b9295732279ec46070f77f9489b41545fc3cd6742c39728533ce9874
|
Provenance
The following attestation bundles were made for con24ma-1.1.0.tar.gz:
Publisher:
publish.yml on qnilix/con24ma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
con24ma-1.1.0.tar.gz -
Subject digest:
0ec065c421b638d9b3ba7f25c0150fbe8cb94138ea7ce2aec74a242a3c0f26e0 - Sigstore transparency entry: 1787250293
- Sigstore integration time:
-
Permalink:
qnilix/con24ma@9117721f2ba4f2dfc7f755a9fdae1259ecee83bc -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/qnilix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9117721f2ba4f2dfc7f755a9fdae1259ecee83bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file con24ma-1.1.0-py3-none-any.whl.
File metadata
- Download URL: con24ma-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baa6b7b1281850da09736731207e60c5e8e9576902325d8821dacbc3a4288e83
|
|
| MD5 |
ad095016e8a511d39489e0d2a22d3364
|
|
| BLAKE2b-256 |
b0b8508ed9eb342932d66c34946a3a17bfb7df0b6eda48ce0a7da0963039df4a
|
Provenance
The following attestation bundles were made for con24ma-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on qnilix/con24ma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
con24ma-1.1.0-py3-none-any.whl -
Subject digest:
baa6b7b1281850da09736731207e60c5e8e9576902325d8821dacbc3a4288e83 - Sigstore transparency entry: 1787250409
- Sigstore integration time:
-
Permalink:
qnilix/con24ma@9117721f2ba4f2dfc7f755a9fdae1259ecee83bc -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/qnilix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9117721f2ba4f2dfc7f755a9fdae1259ecee83bc -
Trigger Event:
push
-
Statement type: