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
--helpand 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf9be914aee23c823e33074fa41290d0c890e31f4a14248a36f7cb96d0fd5a08
|
|
| MD5 |
038c51600256187b42c7c65a22ad628e
|
|
| BLAKE2b-256 |
a4a989f47808b53cfdd9dc409e44722cb971ba53cb0ccaa2f0a19f3173847e0d
|
Provenance
The following attestation bundles were made for vidhi-0.0.3.tar.gz:
Publisher:
publish.yml on project-vajra/vidhi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vidhi-0.0.3.tar.gz -
Subject digest:
bf9be914aee23c823e33074fa41290d0c890e31f4a14248a36f7cb96d0fd5a08 - Sigstore transparency entry: 886563630
- Sigstore integration time:
-
Permalink:
project-vajra/vidhi@0299e1082aef2c158ecf71f5dab7e450193899ce -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/project-vajra
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0299e1082aef2c158ecf71f5dab7e450193899ce -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98cc8b97ac11c130c9f4f5e099bb21d652483bd83e442c5b52e38734ceffa26f
|
|
| MD5 |
8e62adfba89d286b7ce94d6a57caa826
|
|
| BLAKE2b-256 |
79ca5a95d7135feefcfdb16162306a9903994ca4ab12b15d3a2d95ca3b84d2dc
|
Provenance
The following attestation bundles were made for vidhi-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on project-vajra/vidhi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vidhi-0.0.3-py3-none-any.whl -
Subject digest:
98cc8b97ac11c130c9f4f5e099bb21d652483bd83e442c5b52e38734ceffa26f - Sigstore transparency entry: 886563668
- Sigstore integration time:
-
Permalink:
project-vajra/vidhi@0299e1082aef2c158ecf71f5dab7e450193899ce -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/project-vajra
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0299e1082aef2c158ecf71f5dab7e450193899ce -
Trigger Event:
release
-
Statement type: