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.
- Export environment variables:
export MYAPP_DATABASE_PORT=8000
export MYAPP_LOGGING_LEVEL="DEBUG"
- 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!
-
Fork the repository.
-
Create your feature branch:
git checkout -b feature/AmazingFeature
-
Commit your changes:
git commit -m 'Add some AmazingFeature'
-
Push to the branch:
git push origin feature/AmazingFeature
-
Open a Pull Request.
License
This project is licensed under the MIT License.
✨ Konfig: Load Less. Do More.
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1605e4104539ee36f4facfef08eeee25f7fb6747fdde74b8adaeb102d30259
|
|
| MD5 |
52566cddbf26dfec04cd0c7f2fb32e59
|
|
| BLAKE2b-256 |
994e6c9461642f0170420682bad46521093e7c742c829e937f8be49e5538ec47
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1118fd61b6c634c735f72457fe5c84532542d9a5f73976c6e78b0c2e2537cbe7
|
|
| MD5 |
cadba2e950381b6f38072ea6b41a6647
|
|
| BLAKE2b-256 |
2580ecd6c8ad710810128dc2be613220508e56f92b165cef332a5c5a7643bef3
|