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

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.2.tar.gz (4.7 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.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_config_kit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f1d719275b96a3dd71d8eaffa6f32e99a08afbcc91b263a4245410eb0e0041a1
MD5 9c591ccba686f183360392acf86db385
BLAKE2b-256 c11643e872791980747f3e8d8a9090d2cd5345cac89125ae5c1dd07baefda4bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_config_kit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d5bb44e12b7ee1ec8c31acd21c7a26d96cf56c21d3ffc8ec383cadf5e17d043
MD5 d0876e06650fea23fe97490b8d7d7284
BLAKE2b-256 657af661c60baa9aafadca73fe4fbf1d4b0dd3cd15dc65d95bd05827955a2d1f

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