Layered configuration loader merging env vars, files, and defaults
Project description
philiprehberger-config-kit
Layered configuration loader merging env vars, files, and defaults.
Install
pip install philiprehberger-config-kit
Usage
from philiprehberger_config_kit import Config
config = Config(
sources=[
Config.defaults({"port": 3000, "debug": False, "log_level": "info"}),
Config.json_file("config.json", optional=True),
Config.env_file(".env", optional=True),
Config.env(prefix="APP_"),
]
)
# Typed access
port = config.get_int("port")
debug = config.get_bool("debug")
db_url = config.get_str("database_url")
timeout = config.get_float("timeout", default=5.0)
hosts = config.get_list("allowed_hosts")
# Nested access (dot notation)
redis_host = config.get_str("redis.host")
# Validation
config.require("database_url", "secret_key") # raises ConfigError if missing
# Check existence
if config.has("cache_ttl"):
ttl = config.get_int("cache_ttl")
Source Priority
Sources are applied in order — later sources override earlier ones:
Config(sources=[
Config.defaults({...}), # lowest priority
Config.json_file("..."), # overrides defaults
Config.env_file(".env"), # overrides JSON
Config.env(prefix="APP_"), # highest priority
])
Environment Variables
With prefix="APP_", env vars are mapped:
APP_PORT→portAPP_DATABASE__HOST→database.host(double underscore = nested)
.env Files
DATABASE_URL=postgresql://localhost/mydb
SECRET_KEY="my-secret"
DEBUG=true
Bool Coercion
get_bool() accepts: true/false, 1/0, yes/no, on/off
License
MIT
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 philiprehberger_config_kit-0.1.1.tar.gz.
File metadata
- Download URL: philiprehberger_config_kit-0.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fdfc094e8071d1c2ed132678d3629833ce3bd9547df71336b6d471d071d9497
|
|
| MD5 |
ac2a7d4aac54955799bb10cada8e7815
|
|
| BLAKE2b-256 |
3a398c9f86a950e21140cfd33709a6532737acdc9a7572727edbf59f51a435ee
|
File details
Details for the file philiprehberger_config_kit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_config_kit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb92df274613e44686e0cdd6321d9601968814df50625c563a121f0e7d7255ee
|
|
| MD5 |
96b308befadbe42632acdb3120ae9f4e
|
|
| BLAKE2b-256 |
cc6206d4d1badd95269f5ad5deb7c72264f2af21f86fe1bddf68baac862e0d0b
|