Skip to main content

Configuration management system for complex systems

Project description

Vidhi

Vidhi (विधि, "method" in Sanskrit) is a Python configuration library for building type-safe, immutable configs with CLI and YAML support.

Features

  • Immutable configs - Frozen dataclasses prevent accidental modifications
  • CLI generation - Auto-generate --help and argument parsing from config classes
  • Polymorphic configs - Runtime variant selection with type-safe inheritance
  • Nested configs - Compose complex configurations from smaller pieces
  • YAML loading - Load configs from files with --config config.yaml
  • IDE autocomplete - Export JSON Schema for YAML file completion
  • Shell completion - Tab completion for bash, zsh, and fish

Installation

pip install vidhi

Quick Start

Basic Config

from vidhi import frozen_dataclass, field, parse_cli_args

@frozen_dataclass
class TrainingConfig:
    learning_rate: float = field(0.001, help="Learning rate", name="lr")
    batch_size: int = field(32, help="Batch size")
    epochs: int = field(10, help="Number of epochs")

config = parse_cli_args(TrainingConfig)
python train.py --help
python train.py --lr 0.01 --batch_size 64
python train.py --config config.yaml

Nested Configs

@frozen_dataclass
class DatabaseConfig:
    host: str = "localhost"
    port: int = 5432

@frozen_dataclass
class AppConfig:
    name: str = "app"
    database: DatabaseConfig = field(default_factory=DatabaseConfig)

config = parse_cli_args(AppConfig)
python app.py --database.host db.example.com --database.port 3306

Polymorphic Configs

from enum import Enum
from vidhi import BasePolyConfig, frozen_dataclass, field

class CacheType(Enum):
    MEMORY = "memory"
    REDIS = "redis"

@frozen_dataclass
class BaseCacheConfig(BasePolyConfig):
    ttl: int = 3600

    @classmethod
    def get_type(cls) -> CacheType:
        raise NotImplementedError()

@frozen_dataclass
class MemoryCacheConfig(BaseCacheConfig):
    max_size: int = 1000

    @classmethod
    def get_type(cls) -> CacheType:
        return CacheType.MEMORY

@frozen_dataclass
class RedisCacheConfig(BaseCacheConfig):
    host: str = "localhost"
    port: int = 6379

    @classmethod
    def get_type(cls) -> CacheType:
        return CacheType.REDIS

@frozen_dataclass
class AppConfig:
    cache: BaseCacheConfig = field(default_factory=MemoryCacheConfig)

config = parse_cli_args(AppConfig)
python app.py --cache_type redis --cache.host redis.example.com
python app.py --cache_type memory --cache.max_size 5000

YAML Loading

# config.yaml
cache_type: redis
cache:
  host: redis.example.com
  port: 6379
  ttl: 7200
python app.py --config config.yaml
python app.py --config config.yaml --cache.ttl 3600  # CLI overrides YAML

CLI Features

Every Vidhi config automatically supports:

Flag Description
--help Show help with all options organized by variant
--config FILE Load configuration from YAML file
--export-json-schema [FILE] Export JSON Schema for IDE autocomplete
--install-shell-completions [SHELL] Install tab completion (bash/zsh/fish)

API Summary

Function Description
@frozen_dataclass Decorator for immutable config classes
field(default, help=, name=) Field with CLI metadata
parse_cli_args(cls) Parse CLI into config
with_cli_overrides(config) Override existing config from CLI
load_yaml_config(path) Load YAML to dict
create_class_from_dict(cls, dict) Create config from dict
dataclass_to_dict(config) Serialize config to dict
BasePolyConfig Base class for polymorphic configs

Documentation

Full documentation: https://project-vajra.github.io/vidhi

See examples/ for runnable code samples.

License

Apache License 2.0

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

vidhi-0.0.3.tar.gz (127.2 kB view details)

Uploaded Source

Built Distribution

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

vidhi-0.0.3-py3-none-any.whl (72.4 kB view details)

Uploaded Python 3

File details

Details for the file vidhi-0.0.3.tar.gz.

File metadata

  • Download URL: vidhi-0.0.3.tar.gz
  • Upload date:
  • Size: 127.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vidhi-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bf9be914aee23c823e33074fa41290d0c890e31f4a14248a36f7cb96d0fd5a08
MD5 038c51600256187b42c7c65a22ad628e
BLAKE2b-256 a4a989f47808b53cfdd9dc409e44722cb971ba53cb0ccaa2f0a19f3173847e0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vidhi-0.0.3.tar.gz:

Publisher: publish.yml on project-vajra/vidhi

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

File details

Details for the file vidhi-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: vidhi-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 72.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vidhi-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 98cc8b97ac11c130c9f4f5e099bb21d652483bd83e442c5b52e38734ceffa26f
MD5 8e62adfba89d286b7ce94d6a57caa826
BLAKE2b-256 79ca5a95d7135feefcfdb16162306a9903994ca4ab12b15d3a2d95ca3b84d2dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for vidhi-0.0.3-py3-none-any.whl:

Publisher: publish.yml on project-vajra/vidhi

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