Skip to main content

A library for managing settings

Project description

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'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

settngs-0.10.0.tar.gz (22.1 kB view hashes)

Uploaded Source

Built Distribution

settngs-0.10.0-py3-none-any.whl (11.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page