Skip to main content

lzconfig — Lazy Configuration without instantiation

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
YAML .yaml .yml
JSON .json
TOML .toml
INI .ini .cfg
.env .env
XML .xml

All formats work out of the box — no extras needed.

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.1.tar.gz (21.2 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.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lzconfig-0.1.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lzconfig-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b18ae4ed3cd2a5a9b52fc53feba261c555affb06de69ec537ea08db031a90883
MD5 cb62c31edd78f734abbd2b3086d29828
BLAKE2b-256 8cdafbfcc45298c2ffcc25848ca6c15e998f1faab900d1b960d6040f336da2e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lzconfig-0.1.1.tar.gz:

Publisher: publish.yml on SihanLv/lzconfig

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

File details

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

File metadata

  • Download URL: lzconfig-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lzconfig-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2397e59db9fa47b40ec69c5c6adaed55eb560668dc47bae2c4d6f5776e990597
MD5 c8b31720683132419e3f56aaebb836de
BLAKE2b-256 aedfc119175dbe952e5753772b39eaf68ec0c09ab026857a8d02efe6b3295290

See more details on using hashes here.

Provenance

The following attestation bundles were made for lzconfig-0.1.1-py3-none-any.whl:

Publisher: publish.yml on SihanLv/lzconfig

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