Skip to main content

Spruce-settings

Spruce-settings is a Python library for application settings.

Some applications require certain settings to exist before they are launched. Some applications require the ability to save certain settings so that they persist after termination. It is desirable to access both persistent and runtime settings via a uniform interface. This package provides objects that satisfy these requirements.

Settings may be stored in a variety of ways. Windows uses a system registry. OS X uses XML preferences files. Many Unix applications use INI-style configuration (conf) files. It is desirable to store some settings in a database. For now, this module implements only the conf file method, but it provides enough abstraction to allow for other methods to be implemented as needed.

Examples

Single use

import spruce.settings as _settings

settings = _settings.Settings(organization='myorg',
                              application='myapp')
with settings.open(), settings.ingroup('db'):
    dbserver = settings.value('server', required=True)
    dbport = settings.intvalue('port')
    db_entity_tables = settings.listvalue('entity_tables')

Multiple uses

import spruce.settings as _settings

settings = _settings.Settings(organization='myorg',
                              application='myapp')
with settings.open():
    with settings.ingroup('dbconn'):
        dbserver = settings.value('server', required=True)
        dbport = settings.intvalue('port')

    with settings.ingroup('dbtables'):
        db_entity_tables = settings.listvalue('entity_tables')

Factory method

from collections import namedtuple as _namedtuple

import spruce.settings as _settings

class User(_namedtuple('User', ('name', 'password'))):
    @classmethod
    def from_settings(cls, settings, group=None, name_key='name',
                      password_key='password'):
        with settings.ingroup(group):
            name = settings.value(name_key, required=True)
            password = settings.value(password_key, required=True)
        return cls(name=name, password=password)

settings = _settings.Settings(organization='myorg',
                              application='myapp')
with settings.open():
    user = User.from_settings(settings, 'user')

Design

Scopes

Settings may be specified for the entire system or per user. This scope is called the base scope.

Settings are specific to organizations, applications, or subsystems, which are collectively called component scopes. Subsystems are grouped by the applications to which they belong. Applications are grouped by the organizations that produce them.

Settings

Each setting is a (key, value) pair. A key is a non-empty string that identifies the setting uniquely per application. A value is any string (or any object that can be represented as a string).

Keys are case-sensitive.

Groups

Keys can be grouped; for example, Book/Color and Book/PageCount are both part of the Book group, and some storage formats (such as conf) may reflect this by writing Color and PageCount entries together in a Book section.

Groups can be nested.

Locations

The primary location is the unique location determined by the combination of format, base scope, organization, application, and subsystem specified when creating a Settings object.

When settings are written, they are always written to the primary location.

When a setting is queried, the primary location is searched first. If it is not found there, the fallback mechanism is triggered. First, greater component scopes are searched. If the setting is not found there and the base scope is user, then the original component scope is searched in the system base scope, followed by the greater component scopes in system.

Formats

Settings formats specify where and how settings are stored. Each format defines the file path at which settings are stored for a given scope and how to read and write settings in those files.

Changelog

Metadata

Release files for Spruce-settings 0.2.2

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

Source distribution (sdist)

Source distribution for Spruce-settings 0.2.2
File Size Uploaded Provenance
Spruce-settings-0.2.2.tar.gz 33.3 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for Spruce-settings 0.2.2
File Interpreter ABI Platform
Spruce_settings-0.2.2-py27-none-any.whl Python 2.7 none any Details
Spruce_settings-0.2.2-py2.7.egg Legacy Egg format - - Details

Total release size: 77.6 kB

Release files / Spruce-settings-0.2.2.tar.gz

Download URL Spruce-settings-0.2.2.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aa7ec318b823affaaee9536bee0c88b39947b6cf5015e23454bfe63fc8fbee60
BLAKE2b-256 checksum
How to use checksums
32280ea733e56b3b31208e33ecb86cc83e30ac9fa49ac74e04fc52305fcc973c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Spruce_settings-0.2.2-py27-none-any.whl

Download URL Spruce_settings-0.2.2-py27-none-any.whl
Size 25.1 kB
Tags Python 2.7
SHA-256 checksum
How to use checksums
4b8625493921b954e5d7e47fc03c2da77d68c95cd7d7cd6ae73063b16b1ce99c
BLAKE2b-256 checksum
How to use checksums
2ce2763d8fbeca5f50a157aca790ba66822f9e75748ba8201aa1cc70f2b21acd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Spruce_settings-0.2.2-py2.7.egg

Download URL Spruce_settings-0.2.2-py2.7.egg
Size 19.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
e9e399d586c1494646637ccf2b9a5ba660830aec21683b8748d2f44e98faa445
BLAKE2b-256 checksum
How to use checksums
440903a091b6456792fe96a587d3894dbe33322c8721ba76d7d4ced13dd191ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Spruce-settings 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.2 This release

3 release files No provenance

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