2022-12-14 19:42:24 -08:00
[](https://github.com/lordwelch/settngs/actions/workflows/build.yaml)
[](https://github.com/lordwelch/settngs/releases/latest)
[](https://pypi.org/project/settngs/)
[](https://pypistats.org/packages/settngs)
[](https://opensource.org/licenses/MIT)
# Settngs
This library is an attempt to merge reading flags/options from the commandline (argparse) and settings from a file (json).
It is a modified argparse inspired by how [flake8] loads their settings. Note that this does not attempt to be a drop-in replacement for argparse.
Install with pip
```console
pip install settngs
```
2023-01-31 19:18:09 -08:00
A trivial example is included at the bottom of settngs.py with the output below (using bash). For a more complete example see [ComicTagger].
2022-12-14 19:42:24 -08:00
```console
$ python -m settngs
Hello world
$ python -m settngs --hello lordwelch
Hello lordwelch
$ python -m settngs --hello lordwelch -s
Hello lordwelch
2022-12-15 18:53:29 -08:00
Successfully saved settings to settings.json
2022-12-14 19:42:24 -08:00
$ python -m settngs
Hello lordwelch
$ python -m settngs -v
Hello lordwelch
2022-12-15 18:53:29 -08:00
merged_namespace.values.example_verbose=True
2022-12-14 19:42:24 -08:00
$ python -m settngs -v -s
Hello lordwelch
2022-12-15 18:53:29 -08:00
Successfully saved settings to settings.json
merged_namespace.values.example_verbose=True
2022-12-14 19:42:24 -08:00
$ python -m settngs
Hello lordwelch
2022-12-15 18:53:29 -08:00
merged_namespace.values.example_verbose=True
2023-01-31 19:18:09 -08:00
$ cat >settings.json < < EOF
{
"example": {
"hello": "lordwelch",
"verbose": true
},
"persistent": {
"test": false,
"hello": "world"
}
}
EOF
2022-12-14 19:42:24 -08:00
$ python -m settngs --no-verbose
Hello lordwelch
$ python -m settngs --no-verbose -s
Hello lordwelch
2022-12-15 18:53:29 -08:00
Successfully saved settings to settings.json
2022-12-14 19:42:24 -08:00
$ python -m settngs --hello world --no-verbose -s
Hello world
2022-12-15 18:53:29 -08:00
Successfully saved settings to settings.json
2022-12-14 19:42:24 -08:00
$ python -m settngs
Hello world
```
settngs.json at the end:
```json
{
"example": {
"hello": "world",
"verbose": false
2023-01-31 19:18:09 -08:00
},
"persistent": false,
"hello": "world"
2022-12-14 19:42:24 -08:00
}
```
## What happened to the 'i'?
PyPi wouldn't let me use 'settings'
[flake8]: https://github.com/PyCQA/flake8
[ComicTagger]: https://github.com/comictagger/comictagger