Skip to main content

Typed, dependency-free configuration objects with CLI, environment, and file parsing (a scriptconfig successor).

Project description

Pypi PypiDownloads ReadTheDocs GithubActions Codecov GitlabCIPipeline GitlabCICoverage

kwconf provides typed, dependency-free configuration objects that parse consistently from Python keyword arguments, the command line, the environment, and config files. It is a successor to scriptconfig, keeping the useful ergonomics while dropping the footguns (most notably, comma-strings no longer silently split into lists).

Read the Docs

http://kwconf.readthedocs.io/en/latest/

Github

https://github.com/Erotemic/kwconf

Pypi

https://pypi.org/project/kwconf

Features

  • One model, many inputs. CLI, kwargs, env, and files map onto the same field model.

  • Trust at the Python boundary, parse at the text boundary. Config(x='1') keeps '1'; --x=1 parses it. Defaults are WYSIWYG.

  • Progressive typing. Stays simple untyped; add annotations to harden. Value / Flag are typed so x: int = Value(None) is a static error on ty, mypy, and pyright. Ships py.typed.

  • Zero required dependencies. YAML and the ubelt-backed niceties are optional extras.

  • Modal subcommand CLIs, nested configs with dotted overrides, argparse round-tripping, and YAML/JSON load/dump.

Installation

pip install kwconf

# optional extras
pip install kwconf[yaml]    # YAML config load/dump and parser='yaml'
pip install kwconf[ubelt]   # rich repr, Config.__json__, port_to_argparse

Quickstart

import kwconf as kw

class DemoConfig(kw.Config):
    count: int = 1
    mode: str = kw.Value('fast', choices=['fast', 'safe'])
    tags: list[str] = kw.Value(default_factory=list, nargs='+')

cfg = DemoConfig.cli(argv=['--count=3', '--mode=safe', '--tags', 'a', 'b'])
assert cfg.count == 3
assert cfg.mode == 'safe'
assert cfg.tags == ['a', 'b']

See the documentation for the coercion model, nested configs, modal CLIs, and a scriptconfig migration guide.

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

kwconf-0.10.0.tar.gz (119.0 kB view details)

Uploaded Source

Built Distribution

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

kwconf-0.10.0-py3-none-any.whl (92.2 kB view details)

Uploaded Python 3

File details

Details for the file kwconf-0.10.0.tar.gz.

File metadata

  • Download URL: kwconf-0.10.0.tar.gz
  • Upload date:
  • Size: 119.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kwconf-0.10.0.tar.gz
Algorithm Hash digest
SHA256 eb4bd0586fc2fd015d5738d65231163a81840815235fc588d13dcc139a843239
MD5 0903092ea3f7669a536fcfd9f43f1cc8
BLAKE2b-256 a8608c9001edf2683355343806382c2606890c3ccb6373ee17b821e7f1b3141e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kwconf-0.10.0.tar.gz:

Publisher: release.yml on Erotemic/kwconf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kwconf-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: kwconf-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 92.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kwconf-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4ef2dd871748acdf565de61bfbcca028b9736de37ff2d6483757a114bdbde49
MD5 00b23fba27a6d19c4f7371c8965ebff7
BLAKE2b-256 de8419e8037d5d99896a48bf94d85199edba4f331c92a82a2d3ccbb35c431ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kwconf-0.10.0-py3-none-any.whl:

Publisher: release.yml on Erotemic/kwconf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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