Skip to main content

Pythonic agile application configuration helpers

Project description

PKonfig logo

Configs for humans

pypi downloads versions license Type Checked with Mypy Code Quality - Pylint Code Style - Black Code Style - isort codecov

PKonfig

Pragmatic, type-safe configuration for Python apps. PKonfig turns scattered env vars and config files into one clean, validated object with predictable precedence and great DX.

Why PKonfig

  • Avoid config spaghetti: declare your config as code, not as ad‑hoc parsing scattered around the app.
  • Fail fast: catch missing or invalid values at startup, not at 2 a.m. in production.
  • Predictable precedence: layer env vars, .env, secret files, YAML/JSON/TOML/INI in the order you choose.
  • Type-safe by default: fields convert and validate values; your IDE autocompletion just works.
  • Fast and lightweight: minimal dependencies, small surface area, no magic.
  • Framework-agnostic: works equally well in CLIs, services, scripts, and jobs.

What problems it solves

  • “Where does this setting come from?” → Single source of truth with clear precedence.
  • “Why did prod behave differently?” → Explicit, validated defaults and fail-fast checks.
  • “Why is this a string not an int?” → Built-in casting and validation for common types.

Key features

  • Typed, validated configuration objects
  • Multiple sources (env vars, .env, secret files, YAML, JSON, TOML, INI) with flexible precedence
  • Pydantic Settings integration through PKonfigBaseSettings
  • Minimal dependencies, fail-fast checks, and great IDE autocompletion
  • Extensible API with high performance
  • List values parsing with validation

Quick start

from pkonfig.config import Config
from pkonfig.storage.env import Env
from pkonfig.storage.secret_file import SecretFile
from pkonfig.storage.yaml_ import Yaml

class App(Config):
    host: str = "127.0.0.1"
    port: int = 8000
    debug = False

# Highest precedence first
cfg = App(
    Env(prefix="APP"),
    SecretFile("secrets", missing_ok=True),
    Yaml("config.yaml", missing_ok=True),
)

print(cfg.host, cfg.port, cfg.debug)
# Env example: APP_PORT=9000 python app.py → 9000 overrides file/defaults
# SecretFile example: secrets/api_key.txt → cfg.api_key == file contents
# Vault export example: SecretFile("vault-export.json") reads vault kv get -format=json output
# and exposes nested keys like cfg.database.password

Install

pip install pkonfig
# extras for file formats
pip install pkonfig[yaml]
pip install pkonfig[toml]
pip install pkonfig[pydantic]

pydantic-settings integration is available on Python 3.10+.

Pydantic Settings integration

from pydantic import BaseModel

from pkonfig import DictStorage
from pkonfig.pydantic_settings import PKonfigBaseSettings, pkonfig_settings_config


class Database(BaseModel):
    host: str
    port: int


class Settings(PKonfigBaseSettings):
    model_config = pkonfig_settings_config(
        DictStorage(database={"host": "db.internal", "port": "5432"}),
    )

    database: Database


settings = Settings()
assert settings.database.port == 5432

Documentation

Links

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

pkonfig-2.4.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

pkonfig-2.4.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file pkonfig-2.4.0.tar.gz.

File metadata

  • Download URL: pkonfig-2.4.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pkonfig-2.4.0.tar.gz
Algorithm Hash digest
SHA256 a1908cc3fc5dd2f94ba8b299f0187ca9da0d19c3f89e55f38b4540e16f13184b
MD5 15473f994214079ff03f8934b1e85f41
BLAKE2b-256 4991c85424c1db3276a95235996052accb1ea4da7c2e5d72cbb9d6a50699eece

See more details on using hashes here.

File details

Details for the file pkonfig-2.4.0-py3-none-any.whl.

File metadata

  • Download URL: pkonfig-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pkonfig-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3639373321f20700c1a709a9a76414af7c3006cd1f02340eefe14a4044a7474
MD5 3ab8d41f79aa90a5c53c39f4f092eafa
BLAKE2b-256 d5f5c081280b962d30e25d7d764643d03cfeba45c04c79a09a4d31c450ce7879

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