Skip to main content

A simple, unified interface for managing application configuration.

Project description

Konfig ✨

A dead-simple, yet powerful Python library for managing application configuration from multiple sources.


Why Konfig?

Application configuration can be messy. You might have settings in JSON, environment-specific overrides in YAML, and secrets in environment variables.

Konfig brings sanity to this chaos by providing a single, unified object to access all your settings without the boilerplate.

Our philosophy is simple: Stop worrying about how to load your config, and just use it.


Key Features 🚀

  • Multi-Format Support: Natively loads JSON, YAML, and TOML files with zero configuration.
  • Unified Access: Access nested values using standard dictionary syntax or convenient dot notation (config.get('database.host')).
  • Environment Variable Overrides: Seamlessly override file settings with environment variables — perfect for Docker and production deployments.
  • Schema Validation: Use Pydantic models to validate your configuration on load, ensuring data integrity and catching errors early.
  • Lightweight & Simple: Designed with a minimal, intuitive API to be effective without being complex.

Installation ⚙️

Install Konfig directly from PyPI:

pip install konfig-master

Quickstart

Get up and running in less than a minute.

1️⃣ Create a configuration file (e.g., settings.yaml):

# settings.yaml
database:
  host: localhost
  port: 5432
  user: "admin"

logging:
  level: "INFO"

2️⃣ Load and use it in your Python code:

from konfig_master import load

# Load the configuration
config = load('settings.yaml')

# Access values easily
db_host = config.get('database.host')
log_level = config.get('logging.level')

print(f"Connecting to {db_host} with log level {log_level}...")
# Output: Connecting to localhost with log level INFO...

Usage

Accessing Values

Dictionary-style (strict for known keys):

port = config['database']['port']  # Raises KeyError if not found

Dot notation .get() (safe for optional keys):

host = config.get('database.host')  # Returns None if not found
timeout = config.get('database.timeout', default=30)  # Provides default if missing

Working with Different Formats

Konfig automatically detects file formats (.json, .toml, .yaml) with no code changes:

config_json = load('settings.json')
config_toml = load('settings.toml')

Advanced Usage

Environment Variable Overrides

Konfig allows overriding configuration values with environment variables — essential for Docker and Kubernetes.

  1. Export environment variables:
export MYAPP_DATABASE_PORT=8000
export MYAPP_LOGGING_LEVEL="DEBUG"
  1. Load configuration with a prefix:
from konfig_master import load

config = load('settings.yaml', env_prefix='MYAPP')

print(config.get('database.port'))    # 8000 (from env)
print(config.get('logging.level'))    # DEBUG (from env)
print(config.get('database.host'))    # localhost (from file)

Schema Validation with Pydantic

Validate your configuration upfront to avoid runtime surprises.

from pydantic import BaseModel, Field

class DatabaseConfig(BaseModel):
    host: str
    port: int = Field(gt=1024)  # Must be greater than 1024
    user: str

class Settings(BaseModel):
    database: DatabaseConfig
    logging: dict
from konfig_master import load
from pydantic import ValidationError

try:
    config = load('settings.yaml', model=Settings)
    print("Configuration loaded and validated successfully!")
    print(f"Validated Port: {config.database.port}")

except ValidationError as e:
    print("Configuration error!")
    print(e)

If the config file contains an invalid value (e.g., port 80), Konfig will catch this and raise a ValidationError.


Contributing 🤝

We welcome contributions!

  1. Fork the repository.

  2. Create your feature branch:

    git checkout -b feature/AmazingFeature
    
  3. Commit your changes:

    git commit -m 'Add some AmazingFeature'
    
  4. Push to the branch:

    git push origin feature/AmazingFeature
    
  5. Open a Pull Request.


License

This project is licensed under the MIT License.


Konfig: Load Less. Do More.

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

konfig_master-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

konfig_master-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file konfig_master-0.1.1.tar.gz.

File metadata

  • Download URL: konfig_master-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for konfig_master-0.1.1.tar.gz
Algorithm Hash digest
SHA256 df1605e4104539ee36f4facfef08eeee25f7fb6747fdde74b8adaeb102d30259
MD5 52566cddbf26dfec04cd0c7f2fb32e59
BLAKE2b-256 994e6c9461642f0170420682bad46521093e7c742c829e937f8be49e5538ec47

See more details on using hashes here.

File details

Details for the file konfig_master-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: konfig_master-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for konfig_master-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1118fd61b6c634c735f72457fe5c84532542d9a5f73976c6e78b0c2e2537cbe7
MD5 cadba2e950381b6f38072ea6b41a6647
BLAKE2b-256 2580ecd6c8ad710810128dc2be613220508e56f92b165cef332a5c5a7643bef3

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