Skip to main content

larzconf

Layered, typed application configuration. Pure Python, zero dependencies.

Read configuration from defaults, files, .env, and environment variables — layered so later sources win — and access it with the right types. No more int(os.environ.get("PORT", "8000")) scattered through your code, and no dependency to add.

from larzconf import Config

config = (Config()
          .from_dict({"port": 8000, "debug": False})   # defaults
          .from_file("config.json", optional=True)      # committed config
          .from_dotenv(".env")                           # local dev
          .from_env(prefix="APP_"))                      # production wins

config.int("port")                 # int, not "8000"
config.bool("debug")               # True / False from "true"/"1"/"yes"...
config.list("allowed_hosts")       # comma-split -> list
config.get("db.host")              # dotted access into nested config
config.get("secret_key", required=True)   # raises if missing

Why

  • Zero dependencies. No python-dotenv, no pydantic-settings, no framework. Just the standard library.
  • The 12-factor layering you actually want. Defaults, then a config file, then .env for local development, then real environment variables in production — each layer deep-merges over the last.
  • Typed, not stringly. config.int(...), .bool(...), .float(...), .list(...) coerce values and raise a clear ConfigError on bad input; required=True fails fast at startup instead of at 3am.
  • Nested & dotted. JSON config nests naturally; access it with config.get("db.host"). Env vars map to nesting via __ (APP_DB__HOSTdb.host).
  • Validates end-to-end. Hand the whole config to a schema (larzvalidate, or anything with .load(dict)) to type-check it once at boot.

Install

pip install larzconf

Loading

Config().from_dict({...})              # defaults / literals
       .from_json("config.json")       # a JSON file
       .from_dotenv(".env")            # KEY=VALUE (export/comments/quotes ok)
       .from_env(prefix="APP_")        # APP_PORT -> port, APP_DB__HOST -> db.host
       .from_file(path, optional=True) # dispatch by extension

Each call returns the Config, so they chain, and each layer overrides the ones before it.

Reading

config.get("key", default=None, cast=int, required=False)
config.int("port")            config.float("ratio")
config.bool("debug")          config.list("hosts")     config.str("name")
config.get("db.host")         # nested, dotted
"port" in config             config["port"]            config.as_dict()

Validate at startup (optional)

from larzvalidate import Schema, Integer, Boolean, String

class Settings(Schema):
    port  = Integer(min=1, max=65535, default=8000)
    debug = Boolean(default=False)
    secret_key = String(required=True)

settings = config.validate(Settings())   # cleaned, typed dict — or raises

larzconf doesn't depend on larzvalidatevalidate() accepts anything with a .load(dict) method.

Tests

python -m unittest discover -s tests -v      # 25 tests, zero deps

The Larz stack

Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf

License

MIT © larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzconf-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

larzconf-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file larzconf-0.1.0.tar.gz.

File metadata

  • Download URL: larzconf-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzconf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c6d868ef235b5aac49711fb4237119ae4917f987e9a7a6b5e26559b919ff63c
MD5 c82fc98fb072b5f0d1063b72efe83436
BLAKE2b-256 8a457718db9f7606a322e2b8ae7d3bd9a7608debdf4d82a18813aaf024d7f101

See more details on using hashes here.

File details

Details for the file larzconf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzconf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzconf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b34acd7429c8ad89d2c9e13daf8fc04d162f132256a13d3cd4b039847d11d52c
MD5 bec34f3864cf6d5eefe160f0a099890f
BLAKE2b-256 ea7fa041c0e80a691a36795031e7db1b35f8d579e558d393f399cd27d8628249

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page