Metadata-Version: 2.1
Name: cfg-param-wrapper
Version: 1.0.1
Summary: A package designed to simplify defaults.
Author-email: Zeptofine <zeptofine@gmail.com>
Project-URL: Homepage, https://github.com/zeptofine/cfg-argparser
Project-URL: Bug Tracker, https://github.com/zeptofine/cfg-argparser/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Provides-Extra: typer
License-File: LICENSE

# 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](https://github.com/zeptofine/cfg-param_wrapper/) README! It's likely more up to date.

## Installation

```bash
# 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

```python
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!
```
