Metadata-Version: 2.4
Name: config-lib-msgspec
Version: 0.0.2
Summary: A lightweight configuration management library for Python applications with multiple sources, type validation, and automatic merging
Author-email: Artem Shestopalov <tema.rastaclaus@gmail.com>
Project-URL: Homepage, https://github.com/yourusername/config-lib
Project-URL: Repository, https://github.com/yourusername/config-lib
Project-URL: Issues, https://github.com/yourusername/config-lib/issues
Keywords: configuration,config,settings,yaml,environment,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: msgspec>=0.19.0
Requires-Dist: pyyaml>=6.0.2
Requires-Dist: typing-extensions>=4.13.0; python_full_version < "3.11"
Provides-Extra: dev
Requires-Dist: pytest>=8.3.5; extra == "dev"
Requires-Dist: coverage>=7.8.0; extra == "dev"
Requires-Dist: ruff>=0.3.0; extra == "dev"
Requires-Dist: mypy>=1.9.0; extra == "dev"
Dynamic: license-file

# Config-Lib

A lightweight configuration management library for Python applications that supports multiple sources (YAML, environment variables, CLI arguments) with type validation and automatic merging.


## Features

- **Multiple Configuration Sources**  
  Load from YAML files, environment variables, and command-line arguments
- **Precedence Hierarchy**  
  CLI arguments > Environment variables > YAML config files > Default values
- **Type Annotations**  
  Built on `msgspec` for robust type validation and serialization
- **Nested Configurations**  
  Support for complex nested structures with dot/bracket notation
- **Error Handling**  
  Clear validation errors and graceful handling of source failures

## Installation

```bash
pip install config-lib
```

## Basic Usage

```python
from config_lib.base import BaseConfig

class AppConfig(BaseConfig):
    """Main application configuration"""
    host: str = "localhost"
    port: int = 8080
    debug: bool = False

config = AppConfig.load()
```

## Configuration Sources

### YAML File
```yaml
# config.yaml
host: "0.0.0.0"
port: 9000
```

```python
os.environ["CFG_CONFIG"] = "config.yaml"
config = AppConfig.load()  # Loads from YAML
```

### Environment Variables
```bash
export CFG_HOST="127.0.0.1"
export CFG_PORT=3000
```

### CLI Arguments
```bash
python app.py --host 192.168.1.1 --port 4000
```

## Nested Configurations

```python
from msgspec import Struct

class DatabaseConfig(Struct):
    host: str = "localhost"
    port: int = 5432

class AppConfig(BaseConfig):
    db: DatabaseConfig = DatabaseConfig()
    cache_ttl: int = 300
```

**Environment variables**:  
`CFG_DB__HOST=postgres.example.com CFG_DB__PORT=6432`

**CLI arguments**:  
`python app.py --db.host postgres.example.com --db.port 6432`

## Precedence Rules

1. **Command-line arguments** (highest priority)
2. **Environment variables**
3. **YAML configuration file** (lowest priority)
4. **Class defaults** (used if no other sources provide values)

## Error Handling & Validation

The library provides:
- Automatic type validation using `msgspec`
- Clear error messages for missing required fields
- Graceful handling of malformed configuration sources
- Warning logging for source loading errors

## Contributing

```bash
# Run tests
pytest tests/

# Check test coverage
pytest --cov=config_lib --cov-report=html
```

Contributions welcome! Please follow standard Python packaging practices and ensure all tests pass before submitting PRs.

## License

MIT License. See [LICENSE](LICENSE) for details.
