lzconfig — Lazy Configuration without instantiation
lz: Too lazy to type
lazy
Import and go. No init, no loader calls, no boilerplate.
import lzconfig as lz
# Attribute-style access
print(lz.database.host) # → "localhost"
print(lz.database.credentials.user) # → "admin"
# Dict-style access
print(lz['database']['host']) # → "localhost"
# Mixed access
print(lz.database['port']) # → 5432
# Safe access with defaults
print(lz.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, lz is your config.
Command-line --key value arguments are merged over the file, so the command
line always wins. And if command-line arguments are present, no config file is
needed at all.
Config File Resolution
-
If
LZCONFIG_FILEis set (and non-empty), that file is used. Relative paths are resolved against the current working directory. -
Otherwise, the current directory is scanned for the first match:
Priority Filename 1 lzconfig.yaml2 lzconfig.yml3 lzconfig.json4 lzconfig.toml5 lzconfig.ini6 lzconfig.cfg7 lzconfig.env8 lzconfig.xml -
If nothing is found and there are no
--key valuecommand-line arguments,ConfigNotFoundErroris 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.
Command-Line Arguments
--key value and --key=value arguments are merged over the file-based
configuration — the command line is the highest-priority source:
python app.py --database.host example.com --port 8080 --debug true
import lzconfig as lz
lz.database.host # "example.com" — overrides the config file
lz.port # 8080 — an int, not a string
lz.debug # True — a bool
Rules:
- Dotted keys build nested structure:
--database.host xsetslz.database.host. - Values are parsed with JSON when possible (
--port 5432→ int,--debug true→ bool,--tags '["a","b"]'→ list); otherwise they stay strings (--zip 01234→"01234"). - A bare
--key(no value) is treated asTrue. - Only
--options are consumed; everything else is left insys.argvuntouched, and a bare--ends option parsing. - If command-line arguments are present, no config file is necessary, the config will be built from the command line alone.
- If neither a config file nor command-line arguments exist,
ConfigNotFoundErroris raised.
Access Patterns
| Pattern | Example |
|---|---|
| Attribute chain | lz.a.b.c |
| Dict chain | lz['a']['b']['c'] |
| Mixed | lz.a['b'].c |
| List index | lz['items'][0].name |
| Membership | 'key' in lz |
| Safe get | lz.get('key', default) |
| Keys | lz.keys() |
| Length | len(lz) |
| Iteration | for k in lz: ... |
| Attribute write | lz.debug = True |
| Dict write | lz['database']['port'] = 8080 |
| Delete key | del lz.debug / del lz['debug'] |
The config object is mutable — attribute and dict-style writes update the
underlying data in place, and nested values share the same storage
(lz.database.host = '...' is visible through lz['database']['host']).
Key / Method Collision
If a config key happens to have the same name as a ConfigObject method
(e.g., get, items, keys):
- Attribute access (
lz.items) returns the method. - Dict access (
lz['items']) always returns the config value.
This is a deliberate trade-off. When in doubt, use [] — it always works.
The same rule applies to writes: lz.items = [...] still stores the config
value, but reading lz.items returns the method.
Error Handling
| Exception | When |
|---|---|
ConfigNotFoundError |
No config file found and no --key value arguments present |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lzconfig-0.1.3.tar.gz.
File metadata
- Download URL: lzconfig-0.1.3.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e09e442721fe2c1500add0bbfc73db4bb4937c4b33750821295a741ba62569e
|
|
| MD5 |
f73fa2d94d72fbab7039b8eb4ea63c92
|
|
| BLAKE2b-256 |
1e9f447ed2dfdf98cff4552f6a63f1d94c31d6d16174475afed814966e011f11
|
Provenance
The following attestation bundles were made for lzconfig-0.1.3.tar.gz:
Publisher:
publish.yml on SihanLv/lzconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lzconfig-0.1.3.tar.gz -
Subject digest:
0e09e442721fe2c1500add0bbfc73db4bb4937c4b33750821295a741ba62569e - Sigstore transparency entry: 2326782000
- Sigstore integration time:
-
Permalink:
SihanLv/lzconfig@05ea9c3f5cbefba1b384f24418a00f8fe72ff4a7 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/SihanLv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05ea9c3f5cbefba1b384f24418a00f8fe72ff4a7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lzconfig-0.1.3-py3-none-any.whl.
File metadata
- Download URL: lzconfig-0.1.3-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1dbf3a6a8ff135ca7de9655bf082b0968d00ee6642d8149c3ec39874ebe346b
|
|
| MD5 |
1c6c85f1cd28e474ee426461ca778ac0
|
|
| BLAKE2b-256 |
c3bcf3fb6fb18d7d59a290662bfa8dddc3e045f3015907639de7f4e7554fe829
|
Provenance
The following attestation bundles were made for lzconfig-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on SihanLv/lzconfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lzconfig-0.1.3-py3-none-any.whl -
Subject digest:
c1dbf3a6a8ff135ca7de9655bf082b0968d00ee6642d8149c3ec39874ebe346b - Sigstore transparency entry: 2326782157
- Sigstore integration time:
-
Permalink:
SihanLv/lzconfig@05ea9c3f5cbefba1b384f24418a00f8fe72ff4a7 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/SihanLv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05ea9c3f5cbefba1b384f24418a00f8fe72ff4a7 -
Trigger Event:
push
-
Statement type: