Skip to main content

Configuration Enhanced & Easy ☕️ - A Hydra-like configuration parser helper package

Project description

Language: 한국어 | English

Hydra-style Configuration Management + Pydantic Type Safety + Typer-style Auto Help Generation

Python Version License: MIT Status Tests


☕️ Overview

confee is a package that makes configuration management in Python applications simple, type-safe, and intuitive. It combines the best of Hydra and Pydantic, allowing you to manage configuration files, environment variables, and CLI arguments seamlessly.


✨ Key Features

  • 🎯 Type-Safe Configuration — Automatic type validation & IDE autocomplete with Pydantic V2
  • 📋 Multi-Format Support — Automatic detection and parsing of YAML and JSON
  • 🔄 Flexible Override System — Override values via CLI arguments and environment variables
  • 🏗️ Configuration Inheritance — Merge and combine parent-child configurations
  • 📁 File Reference — Load file contents with @file: & @config: prefixes
  • 🔐 Strict Mode — Reject unknown fields or control validation error handling
  • 📦 Zero Configuration — Ready to use with sensible defaults
  • ⚙️ Parse Order Control — Freely adjust priority of file/env/cli sources
  • 💬 Auto Help Generation — Display all options and defaults with --help flag
  • 🪆 Nested Field Access — Override nested fields with dot notation (database.host=localhost)
  • 🧾 Verbosity Control — Adjust output verbosity with --quiet/--verbose/--no-color flags

📦 Installation

pip install confee

🚀 Quick Start

Basic Usage

from confee import ConfigBase

class AppConfig(ConfigBase):
    name: str
    debug: bool = False
    workers: int = 4

# Parse from all sources (file, environment, CLI)
config = AppConfig.load(config_file="config.yaml")

print(config.name)     # Type-safe access
print(config.debug)    # Full IDE support
print(config.workers)  # Auto-completion enabled

YAML Configuration File

name: production-app
debug: false
workers: 8

Command Line Override

python app.py name=my-app debug=true workers=16

Environment Variables

export CONFEE_NAME=my-app
export CONFEE_DEBUG=true
export CONFEE_WORKERS=16

python app.py

Help Display

python app.py --help

Detailed Validation Error Messages

By default, validation errors are displayed concisely, but using the --verbose flag shows detailed error information for each field:

# Concise error message (default)
python app.py name=123

# Output:
# Config error: field 'name' - Input should be a valid string

# Display detailed error messages in verbose mode
python app.py name=123 --verbose

# Output:
# ❌ Configuration Validation Error
#
#   Found 1 validation error(s):
#
#   [1] Field: name
#       Error: Input should be a valid string
#       Type: string_type
#       Got: 123
#
#   💡 How to fix:
#     1. Add the required field to your configuration file
#     2. Or pass the value via CLI: python main.py name=myapp
#     3. Or set an environment variable: export CONFEE_NAME=myapp
#     4. Check field types match your configuration class

Or set via environment variable:

export CONFEE_VERBOSITY=verbose
python app.py name=123

🎯 Advanced Features

Nested Configuration

from confee import ConfigBase

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

class AppConfig(ConfigBase):
    name: str
    database: DatabaseConfig

# Override nested fields from CLI
# python app.py database.host=prod.db database.port=3306
config = AppConfig.load()
print(config.database.host)  # "prod.db"

File References

# config.yaml
name: my-app
api_key: "@file:secrets/api_key.txt"
database_config: "@config:configs/database.yaml"

Custom Environment Prefix

# Use custom prefix instead of CONFEE_
# MYAPP_DEBUG=true instead of CONFEE_DEBUG=true
config = AppConfig.load(env_prefix="MYAPP_")

Custom Source Order

# Control which sources override others
config = AppConfig.load(
    config_file="config.yaml",
    source_order=["cli", "env", "file"]  # CLI highest priority
)

Strict/Non-Strict Modes

# Strict mode (default): Forbid unknown fields
class Config(ConfigBase):
    name: str

# Non-strict mode: Ignore unknown fields
config = Config.load(strict=False)

📚 Documentation


🎯 Use Cases

Environment-specific Configuration

# dev.yaml
debug: true
workers: 2

# prod.yaml
debug: false
workers: 32

# Load appropriate config
import os
env = os.getenv("APP_ENV", "dev")
config = AppConfig.load(config_file=f"{env}.yaml")

Kubernetes Environment Variables

# pod.yaml
containers:
  - env:
    - name: CONFEE_DEBUG
      value: "false"
    - name: CONFEE_WORKERS
      value: "16"

Configuration Validation

from pydantic import Field

class AppConfig(ConfigBase):
    workers: int = Field(ge=1, le=128)  # Validate range
    timeout: float = Field(gt=0)         # Must be positive

🔄 Integration Examples

With FastAPI

from fastapi import FastAPI
from confee import ConfigBase

class AppConfig(ConfigBase):
    title: str = "My API"
    debug: bool = False

# Load config from file and environment only (no CLI)
config = AppConfig.load(
    config_file="config.yaml",
    source_order=["env", "file"]
)
app = FastAPI(title=config.title, debug=config.debug)

With Click

import click
from confee import ConfigBase

class AppConfig(ConfigBase):
    name: str

# Load config from file and environment only (no CLI)
config = AppConfig.load(
    config_file="config.yaml",
    source_order=["env", "file"]
)

@click.command()
def main():
    click.echo(f"Hello {config.name}")

✅ Testing Your Configuration

def test_config_loading():
    config = AppConfig.load(
        config_file="tests/fixtures/config.yaml",
        cli_args=["debug=true"],
        strict=True
    )
    assert config.debug is True

🤝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for your changes
  4. Submit a pull request

📜 License

MIT License © 2025

See LICENSE for details.


💬 Support

For issues and questions:


Enjoy ☕️ configuration management!


Language: 한국어 | English

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

confee-0.2.0.tar.gz (703.8 kB view details)

Uploaded Source

Built Distribution

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

confee-0.2.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file confee-0.2.0.tar.gz.

File metadata

  • Download URL: confee-0.2.0.tar.gz
  • Upload date:
  • Size: 703.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confee-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0778d3bb3a4393ac4da97045170d83fd4938d1b0df4a06005148686dca925cf3
MD5 728ace509f050e4a3b3837fb87be2246
BLAKE2b-256 cc3c2790b24c8ccc72110cb5436adddfdc11d7483faa359d81e5c1ee51ce59f0

See more details on using hashes here.

File details

Details for the file confee-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: confee-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for confee-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffa0b844faa43bf1697d3c1a329599cf39e0c6ac366dccfe49809b44ddbd3615
MD5 6dd46c9235776e50c4e034df966518f4
BLAKE2b-256 32bf76305e0c9b06d34a0ad33fa3024c6a21da3d3769b94d6854153900db74df

See more details on using hashes here.

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