confease
confease is a small Python configuration helper for applications that need predictable precedence across defaults, configuration files, environment variables, and CLI arguments.
Use it when you want one shared configuration object that can load user and system config files, accept argparse overrides, read typed environment values, and persist user preferences without building a full settings framework.
Status:
confeaseis an alpha prototype. The public API is intentionally small, but behavior may still change before a stable release.
Installation
When published, install from PyPI:
pip install confease
For local development from this repository:
git clone https://github.com/octanima-labs/confease.git
cd confease
hatch run pytest
The package requires Python 3.11 or newer.
Quickstart
Create one shared configuration object near your application entry point:
from argparse import ArgumentParser
from confease import Confease
parser = ArgumentParser()
parser.add_argument("--debug", dest="DEBUG", action="store_true")
parser.add_argument("--database-host", dest="database", action="store_const", const={"host": "db.internal"})
args = parser.parse_args()
conf = Confease(
"~/.config/my-app/conf.yaml",
APP_DIR="~/Apps",
DEBUG=False,
database={"host": "localhost", "port": 5432},
)
conf.load_sources(args, "/etc/my-app/conf.yaml")
Read values with get() or indexed access:
conf.get("APP_DIR") # "~/Apps"
conf["APP_DIR"] # "~/Apps"
conf.get("MISSING") # None
conf["MISSING"] # None
conf.get("DEBUG", cast=bool) # False
Update values with set() or indexed assignment:
conf.set("DEBUG", True)
conf["APP_DIR"] = "/srv/app"
conf.save()
By default, save() writes only user-origin values. Use save(user_only=False) when you want to persist the full effective configuration, including defaults and overrides.
Nested Keys
Confease supports one nested level. Internally, nested leaves are stored as dotted keys:
conf.set("database", {"host": "localhost", "port": 5432})
conf.get("database.host") # "localhost"
conf["database.host"] # "localhost"
conf.get("database") # {"host": "localhost", "port": 5432}
conf["database"]["host"] # "localhost"
Section access returns a plain snapshot dictionary. Missing subkeys raise KeyError, so write nested values through dotted keys or set():
conf["database.port"] = 5433
Source Precedence
By default, sources are resolved in this order:
CLI > ENV > SYS > USR > DEF
Origins mean:
CLI: values from anargparse.Namespacepassed toload_sources()orreload_cli().ENV: known environment variables loaded byreload_env().SYS: config files outside the current user home directory.USR: config files inside the current user home directory and values assigned withset().DEF: defaults passed as keyword arguments toConfease(...).
Customize precedence with preference:
conf = Confease("conf.yaml", preference=["env", "cli", "user", "default"])
conf.load_sources(args, "conf.yaml", preference=["cli", "env", "user", "default"])
Omitted origins are appended after the origins you provide.
Environment Variables
reload_env() only imports environment variables whose keys are already known from defaults or loaded files. Values are parsed with yaml.safe_load, so common scalar text recovers Python types:
export DEBUG=true
export PORT=5432
conf = Confease(DEBUG=False, PORT=8000)
conf.reload_env()
conf["DEBUG"] # True
conf["PORT"] # 5432
File Formats
The parser is inferred from the path suffix when parser=None is used, or you can pass a parser class explicitly.
Supported suffixes:
.yaml,.yml.json.toml.ini,.cfg,.conf,.config.xml.csv
from confease import Confease, Json
yaml_conf = Confease("conf.yaml", parser=None)
json_conf = Confease("conf.json", parser=Json)
YAML, JSON, TOML, INI, and XML persist one-level nested sections. CSV persists flat dotted keys with a key,value header.
Edit Config Files
edit_file() opens a temporary draft in a blocking text editor, validates the edited content with the active parser, and only then replaces the real config file:
from confease import TextEditor
conf.editor = TextEditor("code")
conf.edit_file(user_only=True)
Invalid edited content raises an error and leaves the previous file and in-memory values unchanged.
Documentation
- Documentation: https://octanima-labs.github.io/confease
- Repository: https://github.com/octanima-labs/confease
- Issues: https://github.com/octanima-labs/confease/issues
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 confease-1.0.0.tar.gz.
File metadata
- Download URL: confease-1.0.0.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6f490af1fc0dcd6b1d4001c775461fb7e4a37b266b2aaa45a5956f8e3942a84
|
|
| MD5 |
b78b8e48383e392870ecccfb9c19acfb
|
|
| BLAKE2b-256 |
e5adf55a2b6abc72b791ad665fe36eba0102a26034ef8cf9f55b06d0fbf0e4ba
|
Provenance
The following attestation bundles were made for confease-1.0.0.tar.gz:
Publisher:
release.yml on octanima-labs/confease
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confease-1.0.0.tar.gz -
Subject digest:
d6f490af1fc0dcd6b1d4001c775461fb7e4a37b266b2aaa45a5956f8e3942a84 - Sigstore transparency entry: 2451895976
- Sigstore integration time:
-
Permalink:
octanima-labs/confease@4ba0386621ccbdd4495d0a70739f449acf68f682 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/octanima-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4ba0386621ccbdd4495d0a70739f449acf68f682 -
Trigger Event:
push
-
Statement type:
File details
Details for the file confease-1.0.0-py3-none-any.whl.
File metadata
- Download URL: confease-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 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 |
529d34c637f2e298ea5cd53392bf364067e27e8e202589633c565f83c56939d3
|
|
| MD5 |
fdf28d62b492282f12e17c0174c3daa3
|
|
| BLAKE2b-256 |
a4d0ae066d6d25e26064d5336dda909fef292fb1d887802804a8a1e029ae9649
|
Provenance
The following attestation bundles were made for confease-1.0.0-py3-none-any.whl:
Publisher:
release.yml on octanima-labs/confease
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confease-1.0.0-py3-none-any.whl -
Subject digest:
529d34c637f2e298ea5cd53392bf364067e27e8e202589633c565f83c56939d3 - Sigstore transparency entry: 2451896942
- Sigstore integration time:
-
Permalink:
octanima-labs/confease@4ba0386621ccbdd4495d0a70739f449acf68f682 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/octanima-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4ba0386621ccbdd4495d0a70739f449acf68f682 -
Trigger Event:
push
-
Statement type: