Skip to main content

Easy settings for Python projects

Project description

This module provides a spy object that resolves an attribute by searching sequentially in following places:

  1. manually set settings

  2. settings catalog

  3. user-provided settings module

  4. manually set fallbacks

Examples:

  1. Manally set settings:

from settingspy import spy spy[‘this_is_int’] = 123 spy[‘this_is_str’] = ‘string’ print(spy.this_is_int, spy.this_is_str)

  1. Settings catalog

Inside the directory specified by the SETTINGSPY_CATALOG environment variable, a file named something may exist with the desired value. File contents are restricted to booleans, integers, floats, strings. They are parsed as if eval()ed, so strings should be wrapped in parentheses.

$ echo 123 > “$SETTINGSPY_CATALOG/this_is_int” $ echo “‘string’” > “$SETTINGSPY_CATALOG/this_is_str”

  1. User provided settings module

in file mysettings.py: this_is_int = 123 this_is_str = ‘string’

import os; os.environ[‘SETTINGSPY_MODULE’] = ‘mysettings’ from settingspy import spy; print(spy.this_is_int, spy.this_is_str)

  1. Manually set fallbacks

In case a setting attribute isn’t defined anywhere else.

from settingspy import spy spy.setfallback(‘this_is_int’, 123) spy.setfallback(‘this_is_str’, ‘string’)

For more details see the source code at https://github.com/ydm/settingspy

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

settingspy-1.1.1.tar.gz (2.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page