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, 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, 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.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"),
    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

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.2.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.2.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pkonfig-2.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 f7af758617495d9650e2f93101a844aaae146f319d053779e16e4eccc9645f46
MD5 db1233341c4f3cd7c62e3c7fa708bcd6
BLAKE2b-256 3c28dc030d3918f69963c63a9da45e574eb3bf0b70712d4e1666ef38d367f1e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pkonfig-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5a851e2dc722f26d1ffac5de7fee869750f52c99f92b9fd2756c618c0f8fa01
MD5 84859478de1e5c19a26d15d9b3518a23
BLAKE2b-256 0d9f1e515b8de7a3ece2bb0687a5b1b10b894cfa9a36e7912dbf1cc8b353b97c

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