Skip to main content

Layered configuration loader merging env vars, files, and defaults

Project description

philiprehberger-config-kit

Tests PyPI version License

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_PORTport
  • APP_DATABASE__HOSTdatabase.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

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_config_kit-0.1.5.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_config_kit-0.1.5-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_config_kit-0.1.5.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_config_kit-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9d672e177fded7d49ccf0a0d3b44cfb147fe9bc905defa3b61aa7b6142d6216c
MD5 5b84838943bed99fcfcef4941841c9b7
BLAKE2b-256 5f408118eb8fe35949796ac93f750a957418d89c59923ba8e5b320fb4119c973

See more details on using hashes here.

File details

Details for the file philiprehberger_config_kit-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_config_kit-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fb4cc1f2f059bc2990c88f1732f6624a79abb6c6dcfd0cf6918613df651a5113
MD5 a85052c6cf55a6849361a5264850c8a7
BLAKE2b-256 b797c27f3371c22be355a8596041f7ecd45b81c86e2b7d48dc4d356b7294f930

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