Skip to main content

settings should be simple, boring and forget-able. With settipy it will be just that.

Project description

settipy

settings should be simple, and with settipy it is.

settings parses command line and environment variables on one line. And makes it available throughout the code base. Making using settings in your project as boring and unimportant as it should be. settings vars is as simple as:

settipy.set("FOO", "default value", "help text")

getting vars out has the same level of complexity as setting the value.

settipy["FOO"]

Features

  • Simple to use
  • supports command line and environment variables
  • Support for types: str, int, bool, list, dict
  • Singleton, makes it easy to use in program anywhere in the code-base
  • Supports help text with --help
  • Ease of use in any environment examples: linux, docker, k8
  • Force program to be run with env or cli vars.

Example

example of how to use. More can be found in the example_project

settipy.set("FOO", "default value", "handy help text")

settipy.parse()

print("foo = ", settipy["FOOBAR"])

The above go will produce program that can be used as follows. get handy help text set in the above example on the same line. This can get very handy when the project grows and is used in different environments

$ python example.py --help
Usage of example.py:
  -FOO string
      handy help text (default "default value")

When no value is given, default value is used

$ python example.py
foo = default value

Running the binary with command line input

$ python example.py -FOO bar
foo = bar

Running the binary with environment variable

$ FOO=ok;python example.py
foo = ok

Order of preference

variables are set with preference variables on the command line will have highest preference. This because while testing you might want to override environment The priority order is as follows

  1. Command line input
  2. Environment variables
  3. Default values

Types

settipy supports different types. It's possible to use the method "get". But to be more clear to the reader of the code you can add the type e.g "get_bool".

// string
settipy.set("FOO", "default", "help text")
settipy["FOO"]

// integer
settipy.set_int("FOO", 42, "help text")
settipy["FOO"]

// boolean
settipy.set_bool("FOO", True, "help text")
settipy["FOO"]

// list
settipy.set_list("FOO", [1, 2, 3], "help text", sep=".")
settipy["FOO"]

dic = {
   "foo": ["bar",],
   "foo1": ["bar1", "bar2"]
}
settipy.set_dict("foodict", dic, "dict with lists", item_sep=";", key_sep=";", sep=",")
settipy["foodict"]

Var Should be set

settipy supports different types.

// string
settipy.set("foshure", True, "handy message", should=True)
flag: foshure handy message: should be set

Install

$ pip install settipy

Future features

  • add feature to print out all the values that are set at startup. to add to that passwords should not be shown.
  • remove redundant data after parse has run. Every byte counts.
  • conditional should, combinations of input create depenedencies for example -output_file_name could be needed if -mode is write_to_file
  • Add support for passwords. Password can be stored as hashes. With salt and pepper. Pepper can be stored in envirnoment and the salt given at the cli. This will allow for safer storing of passwords. Passwords are then just hashes in config. At runtime at the parse fase settipy will use the salt and pepper to decrypt the password. Since this will properly use external package the major version upgrade is needed. 1.0 will be requirement free. and 2.0 will start to use packages.

License

MIT

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

settipy-1.5.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

settipy-1.5.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file settipy-1.5.0.tar.gz.

File metadata

  • Download URL: settipy-1.5.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for settipy-1.5.0.tar.gz
Algorithm Hash digest
SHA256 89016b3848bc3e37c6eec648617625faff481a64e86369e4275c094f90a7366a
MD5 e65b8106f05453a60183826a236f9ce5
BLAKE2b-256 87daca2a6d7c000cbc7e95bae54473243c91019fc4571f8f22e3d898b4c998ba

See more details on using hashes here.

File details

Details for the file settipy-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: settipy-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for settipy-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c47f429f3169478f9232f97f3dff0905d768fd4a9929817610f6f4086a15947
MD5 d6c7123d79458cc6d851167411364b59
BLAKE2b-256 62f15c1a6d6b09064822be61807788df78a3c08b0279400b2fd2e0518ec46704

See more details on using hashes here.

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