A package designed to simplify defaults.
Project description
cfg_param_wrapper 1.0.1
a config wrapper I made. It's made to wrap simple functions, and intercept configurations in tandem with a CfgDict object.
Check the Github README! It's likely more up to date.
Installation
# from pypi:
pip install cfg-param-wrapper
# from github:
git clone "https://github.com/zeptofine/cfg-param-wrapper"
cd cfg-param-wrapper
pip install -e .
@wrap_config
The wrap_config
decorator is meant to wrap a function, take their parameters and create a config file from it. Once a function is wrapped using @wrap_config
, either the cfg can change and the function's default parameters are updated according to the argument names and such.
This is very useful in Typer
and Click
commands (wrap it before declaring a command).
CfgDict
This is a dictionary subclass that takes a filename, and saves all the changes to the file using json
or toml
.
It allows custom encoders and decoders for the file formats it supports.
Example
from cfg_param_wrapper import wrap_config, CfgDict
cfg = CfgDict("test.json")
@wrap_config(cfg)
def test_function(s: str, is_real: bool = True): # I'd advise only wrapping functions with default parameters
return f"{s} is {'real' if is_real else 'fake'}"
if __name__ == "__main__":
print(test_function("We"))
cfg['s'] = "us"
print(test_function()) # Linters hate him!
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file cfg-param-wrapper-1.0.1.tar.gz
.
File metadata
- Download URL: cfg-param-wrapper-1.0.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b11847631c00c521bd0b0e2f8b66121a7f010e8206f2d9636460e8ba85eb05 |
|
MD5 | b4ffc51926b225ef5a6a88a8e00e8790 |
|
BLAKE2b-256 | 8f421a827946a37795056cc1154ac0b87c651e4dd115d4a67b86ee8ed2ecd43e |
File details
Details for the file cfg_param_wrapper-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: cfg_param_wrapper-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aee9bf377f69aacdaad388a8111e4a636996bc84658f4bc9c0dda6313a7b3cb |
|
MD5 | 55475f6131ad4ae257960a8b8335bfd6 |
|
BLAKE2b-256 | e377d76cd956a2c6cfb4dd6f48bf40d81a54596a5aa4af3569fe77abc73ccba3 |