Skip to main content

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=value argument 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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

con24ma-1.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

con24ma-1.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

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

Hashes for con24ma-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0ec065c421b638d9b3ba7f25c0150fbe8cb94138ea7ce2aec74a242a3c0f26e0
MD5 dfd273e5cd7e556dbc58380b2f248383
BLAKE2b-256 f7ef3af3b9295732279ec46070f77f9489b41545fc3cd6742c39728533ce9874

See more details on using hashes here.

Provenance

The following attestation bundles were made for con24ma-1.1.0.tar.gz:

Publisher: publish.yml on qnilix/con24ma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for con24ma-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 baa6b7b1281850da09736731207e60c5e8e9576902325d8821dacbc3a4288e83
MD5 ad095016e8a511d39489e0d2a22d3364
BLAKE2b-256 b0b8508ed9eb342932d66c34946a3a17bfb7df0b6eda48ce0a7da0963039df4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for con24ma-1.1.0-py3-none-any.whl:

Publisher: publish.yml on qnilix/con24ma

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page