Application settings
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file Spruce-settings-0.2.2.tar.gz
.
File metadata
- Download URL: Spruce-settings-0.2.2.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa7ec318b823affaaee9536bee0c88b39947b6cf5015e23454bfe63fc8fbee60 |
|
MD5 | 907007e7fa8c6c3a7944814485ebb7ad |
|
BLAKE2b-256 | 32280ea733e56b3b31208e33ecb86cc83e30ac9fa49ac74e04fc52305fcc973c |
File details
Details for the file Spruce_settings-0.2.2-py27-none-any.whl
.
File metadata
- Download URL: Spruce_settings-0.2.2-py27-none-any.whl
- Upload date:
- Size: 25.1 kB
- Tags: Python 2.7
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8625493921b954e5d7e47fc03c2da77d68c95cd7d7cd6ae73063b16b1ce99c |
|
MD5 | 838a9c870543b92a0365496deb7b48a2 |
|
BLAKE2b-256 | 2ce2763d8fbeca5f50a157aca790ba66822f9e75748ba8201aa1cc70f2b21acd |
File details
Details for the file Spruce_settings-0.2.2-py2.7.egg
.
File metadata
- Download URL: Spruce_settings-0.2.2-py2.7.egg
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e399d586c1494646637ccf2b9a5ba660830aec21683b8748d2f44e98faa445 |
|
MD5 | ab9933043e78b06dc7d12ec543999892 |
|
BLAKE2b-256 | 440903a091b6456792fe96a587d3894dbe33322c8721ba76d7d4ced13dd191ab |