Skip to main content

lzconfig — Zero-Boilerplate Configuration

lz: Too lazy to type lazy

中文文档

Import and go. No init, no loader calls, no boilerplate.

import lzconfig

# Attribute-style access
print(lzconfig.database.host)           # → "localhost"
print(lzconfig.database.credentials.user)  # → "admin"

# Dict-style access
print(lzconfig['database']['host'])     # → "localhost"

# Mixed access
print(lzconfig.database['port'])        # → 5432

# Safe access with defaults
print(lzconfig.get('debug', False))     # → True

How It Works

At import time, lzconfig discovers your config file, parses it, interpolates environment variables, and replaces itself in sys.modules with the loaded configuration object. From then on, lzconfig is your config.

Config File Resolution

  1. If LZCONFIG_FILE is set (and non-empty), that file is used. Relative paths are resolved against the current working directory.

  2. Otherwise, the current directory is scanned for the first match:

    Priority Filename
    1 lzconfig.yaml
    2 lzconfig.yml
    3 lzconfig.json
    4 lzconfig.toml
    5 lzconfig.ini
    6 lzconfig.cfg
    7 lzconfig.env
    8 lzconfig.xml
  3. If nothing is found, ConfigNotFoundError is raised at import time.

Supported Formats

Format Extensions Dependency
YAML .yaml .yml PyYAML
JSON .json stdlib
TOML .toml tomli (Python < 3.11) / tomllib (3.11+)
INI .ini .cfg stdlib (configparser)
.env .env python-dotenv (optional)
XML .xml stdlib

Core formats (JSON, INI, XML) work with zero dependencies. Install extras as needed:

pip install lzconfig[yaml,toml,dotenv]   # specific extras
pip install lzconfig[all]                # everything

Environment Variable Interpolation

$VAR and ${VAR} references in config values are expanded at load time using os.path.expandvars:

# lzconfig.yaml
database:
  host: $DB_HOST
  password: ${DB_PASSWORD}

Undefined variables are left as literal text — no error is raised.

Access Patterns

Pattern Example
Attribute chain lzconfig.a.b.c
Dict chain lzconfig['a']['b']['c']
Mixed lzconfig.a['b'].c
List index lzconfig['items'][0].name
Membership 'key' in lzconfig
Safe get lzconfig.get('key', default)
Keys lzconfig.keys()
Length len(lzconfig)
Iteration for k in lzconfig: ...

Key / Method Collision

If a config key happens to have the same name as a ConfigObject method (e.g., get, items, keys):

  • Attribute access (lzconfig.items) returns the method.
  • Dict access (lzconfig['items']) always returns the config value.

This is a deliberate trade-off. When in doubt, use [] — it always works.

Error Handling

Exception When
ConfigNotFoundError No config file found at import time
ConfigParseError File found but cannot be parsed
ConfigKeyError Accessing a non-existent key

All exceptions inherit from ConfigError and can be imported directly:

from lzconfig import ConfigError, ConfigNotFoundError, ConfigKeyError

License

MIT

Download files

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

Source Distribution

lzconfig-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

lzconfig-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lzconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 54c598365936961a83347e9526b834ff08ddea64ae3345d51eb6c65eb5006df8
MD5 4ecc9ebf74944cebbbc043e70be4da3c
BLAKE2b-256 1ad96c90476e4770272749a09d6ad75511a1a26d577fb062f28c08f60de39f95

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lzconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e97708b8aa004916a1794b48308799dc0e09f01f16987c653585c10a901f212f
MD5 9404e412c23af171706e18fbc765ce00
BLAKE2b-256 4249a0816a48c58b317adbe2d630e1c8eed1d1f824b1072ba3aac5abb3cdfc1e

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