Skip to main content

pyStandardSettings

Standardised settings loader

a port of nodejs standard-settings

Why

No more cp config.sample.json config.json.

Your app presents a settings/settings.default.json which is always included. User, or other developer needing custom settings, loads his custom settings, overriding default settings. If a key is missing in user settings, it won’t trigger any error, as a default value is in settings.default.json. standard-settings offers multiple ways to change settings: settings.json file, command line arguments, environment variables. Check below examples for usage and priority order.

Installation

pip install pyStandardSettings

Usage

This module loads settings from a file, from commandline arguments, and environment variables. It should be required at the very beginning of your project:

from pyStandardSettings import settings

Then your settings are accessible using:

print settings.server.port

Priority order

  1. Environment variables

Example:

SERVER_PORT=2500 python main.py
service_spacebro_inputMessage=new-media python main.py
  1. Command line parameters (argv)

Example:

python main.py --server.port 2000 # to specify a field
python main.py --settings settings/settings.prod.json # to specify a settings file

NB: To use a key with argv, it needs to be present in settings.default.json

  1. Files

These files are always loaded if present:

settings/settings.json first

settings/settings.default.json

Working all together with different settings

On your project, you may have other developers working with different settings. Pushing them in the repo is annoying. We know you’ve seen that before. Using standard-settings, developers can share common default settings, AND load custom settings.

Best practice is to add settings/settings.default.json in your repo, this file covers default settings, common for each developer. And .gitignore settings/settings.json, this file has custom settings inside.

Schema

The following schema is an example of settings used in Soixante circuits apps:

{
  "server": {
      "host" : "myip",
      "port" : 3333
  },
  "timeout": {
    "lookbook": 5,
    "popup": 4
  },
  "folder": {
    "kcDownloader": "path-to/data",
    "lookbook": "path-to/lookbook"
  },
  "flag": {
    "stabalize": true,
    "devMode": true
  },
  "customKey": {
    "maxImageNumber": 64
  },
  "meta": {
      "title": "",
      "description": "",
      "message": "...",
      "source": ""
  },
  "service": {
    "altruist": {
      "host" : "192.168.1.6",
      "port" : 6666
    },
    "spacebro": {
      "host" : "192.168.1.6",
      "port" : 8888,
      "channelName": "my-channel",
      "client" : {
        "name" : "my-app"
      }
    }
  }
}

See soixantecircuits/standard

Goodies

To list all settings keys available in your project, use

python main.py -h

and it will display

usage: main.py [-h] [-s SETTINGS] [--recipe RECIPE]
               [--server.host SERVER.HOST] [--server.port SERVER.PORT]

optional arguments:
  -h, --help            show this help message and exit
  -s SETTINGS, --settings SETTINGS
                        settings file in json format
  --recipe RECIPE
  --server.host SERVER.HOST
  --server.port SERVER.PORT

test command

python -m tests.test

Metadata

Release files for pyStandardSettings 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyStandardSettings 0.0.1
File Size Uploaded
pyStandardSettings-0.0.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyStandardSettings 0.0.1
File Interpreter ABI Platform
pyStandardSettings-0.0.1-py2-none-any.whl Python 2 none any Details

Total release size: 13.8 kB

Release files / pyStandardSettings-0.0.1.tar.gz

Download URL pyStandardSettings-0.0.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ccc57de1bfc6a36b72734ed9137ed6d0818006d8ef1f76f13a0cb79da22d660b
BLAKE2b-256 checksum
How to use checksums
de7ba02a0de40d4bf55593d8b009e417617532ca917fc6638f51af46edbde800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pyStandardSettings-0.0.1-py2-none-any.whl

Download URL pyStandardSettings-0.0.1-py2-none-any.whl
Size 7.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
66001deb54038b49fc9650168bddc640888fa5372ba62fa417a554e7ac012ee9
BLAKE2b-256 checksum
How to use checksums
3385c5c91362fd79709d63d1244b5c5a1ae763fb25d98d60e806970a448ac96b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page