Go to file
pre-commit-ci[bot] 3b0ae0f24a
[pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v3.15.2 → v3.16.0](https://github.com/asottile/pyupgrade/compare/v3.15.2...v3.16.0)
- [github.com/hhatto/autopep8: v2.2.0 → v2.3.1](https://github.com/hhatto/autopep8/compare/v2.2.0...v2.3.1)
- [github.com/PyCQA/flake8: 7.0.0 → 7.1.0](https://github.com/PyCQA/flake8/compare/7.0.0...7.1.0)
2024-06-24 17:18:37 +00:00
.github/workflows Include pyproject.toml 2023-04-26 15:32:06 -07:00
settngs Don't inherit from argparse Namespace 2024-06-06 19:33:07 -07:00
testing Fix settings being overwritten when using the same dest attribute 2023-12-16 16:51:00 -08:00
tests Improve types 2024-05-20 15:09:33 -07:00
workflows Initial Commit 2022-12-14 20:57:57 -08:00
.gitignore Add py.typed 2023-04-25 00:13:51 -07:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate 2024-06-24 17:18:37 +00:00
LICENSE Initial Commit 2022-12-14 20:57:57 -08:00
pyproject.toml Include pyproject.toml 2023-04-26 15:32:06 -07:00
README.md Fix readme example 2023-11-19 00:20:43 -08:00
requirements-dev.txt Initial Commit 2022-12-14 20:57:57 -08:00
setup.cfg Fix metavar deprecation on BooleanOptionAction 2024-04-29 19:12:48 -07:00
setup.py Initial Commit 2022-12-14 20:57:57 -08:00

CI GitHub release (latest by date) PyPI PyPI - Downloads PyPI - License

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

pip install settngs

A trivial example is included at the bottom of settngs.py with the output below (using bash). For a more complete example see ComicTagger.

$ python -m settngs
Hello world
$ python -m settngs --hello lordwelch
Hello lordwelch
$ python -m settngs --hello lordwelch -s
Hello lordwelch
Successfully saved settings to settings.json
$ python -m settngs
Hello lordwelch
$ python -m settngs -v
Hello lordwelch
merged_namespace.values.Example_Group__verbose=True
$ python -m settngs -v -s
Hello lordwelch
Successfully saved settings to settings.json
merged_namespace.values.Example_Group__verbose=True
$ python -m settngs
Hello lordwelch
merged_namespace.values.Example_Group__verbose=True
$ cat >settings.json << EOF
{
  "example": {
    "hello": "lordwelch",
    "verbose": true
  },
  "persistent": {
    "test": false,
    "hello": "world"
  }
}
EOF
$ python -m settngs --no-verbose
Hello lordwelch
$ python -m settngs --no-verbose -s
Hello lordwelch
Successfully saved settings to settings.json
$ python -m settngs --hello world --no-verbose -s
Hello world
Successfully saved settings to settings.json
$ python -m settngs
Hello world

settngs.json at the end:

{
  "Example Group": {
    "hello": "world",
    "verbose": false
  },
  "persistent": false,
  "hello": "world"
}

What happened to the 'i'?

PyPi wouldn't let me use 'settings'