Simple settings functions for projects.
Project description
SmallSettings
=============
In many projects (web applicatons in particular) there is a need of making a settings. For application we need a 3 types of settings.
* Application settings (for example: application name)
* Envoritment settings (for example: url to database)
* Dynamic settings (for example: what ads to we show today)
SmallSettings provides solusion for the first 2 types of settings (the third one should be stored in the database).
The second problem with settings is wrapping some settings. Sometimes you have to wrap var from app settings in envoritment settings, and sometime you have to do the oposit. SmallSettings has a solution for this.
Settings classes
========
First we look at the "Settings" class.
>> from smallsettings import Settings
>> settings = Settings({'base_settings': 1})
>> settings['base_settings']
1
Pretty normal dict. But it have a special features:
>> settings['something'] = 'new settings %(base_settings)s'
>> settings['something']
'new settings 1'
We can now ovveride the 'base_settings':
>> settings['base_settings'] = 2
>> settings['something']
'new settings 2'
Second, the "Paths" class.
>> from smallsettings import Paths
>> paths = Paths({'base' : '/tmp'})
>> paths['base']
'/tmp'
>> paths['home'] = '/home'
>> paths['home']
'/home'
But using previous var is slite different, because the Paths class use os.path.join:
>> paths['me'] = ['%(home)s', 'me']
>> paths['me']
'/home/me'
If we want to "merge" settings and paths, we co do this:
>> merged = settings.merged(paths)
>> merged['something']
'new settings 2'
>> merged['me']
'/home/me'
Factory
=======
If we want to use 'modulename.settings' where 'modulename' is our main module and
'settings' is our settins module.
>> from smallsettings import Factory
>> factory = Factory('modulename', 'settings')
>> settings, paths = factory.make_settings()
It will read the settings from modulename/settings/default.py. This file should
looks like this:
>> def make_settings(settings, paths):
>> settings['name'] = 'value'
If we want to add some additional files for settings, like "local.py", we can do
this:
>> settings, paths = factory.make_settings(additional_modules=[('local', False)])
This is the default behavior. The bool means "raise error on missing module".
=============
In many projects (web applicatons in particular) there is a need of making a settings. For application we need a 3 types of settings.
* Application settings (for example: application name)
* Envoritment settings (for example: url to database)
* Dynamic settings (for example: what ads to we show today)
SmallSettings provides solusion for the first 2 types of settings (the third one should be stored in the database).
The second problem with settings is wrapping some settings. Sometimes you have to wrap var from app settings in envoritment settings, and sometime you have to do the oposit. SmallSettings has a solution for this.
Settings classes
========
First we look at the "Settings" class.
>> from smallsettings import Settings
>> settings = Settings({'base_settings': 1})
>> settings['base_settings']
1
Pretty normal dict. But it have a special features:
>> settings['something'] = 'new settings %(base_settings)s'
>> settings['something']
'new settings 1'
We can now ovveride the 'base_settings':
>> settings['base_settings'] = 2
>> settings['something']
'new settings 2'
Second, the "Paths" class.
>> from smallsettings import Paths
>> paths = Paths({'base' : '/tmp'})
>> paths['base']
'/tmp'
>> paths['home'] = '/home'
>> paths['home']
'/home'
But using previous var is slite different, because the Paths class use os.path.join:
>> paths['me'] = ['%(home)s', 'me']
>> paths['me']
'/home/me'
If we want to "merge" settings and paths, we co do this:
>> merged = settings.merged(paths)
>> merged['something']
'new settings 2'
>> merged['me']
'/home/me'
Factory
=======
If we want to use 'modulename.settings' where 'modulename' is our main module and
'settings' is our settins module.
>> from smallsettings import Factory
>> factory = Factory('modulename', 'settings')
>> settings, paths = factory.make_settings()
It will read the settings from modulename/settings/default.py. This file should
looks like this:
>> def make_settings(settings, paths):
>> settings['name'] = 'value'
If we want to add some additional files for settings, like "local.py", we can do
this:
>> settings, paths = factory.make_settings(additional_modules=[('local', False)])
This is the default behavior. The bool means "raise error on missing module".
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
SmallSettings-0.2.2.tar.gz
(5.0 kB
view details)
Built Distributions
SmallSettings-0.2.2-py3.3.egg
(16.1 kB
view details)
SmallSettings-0.2.2-py2.7.egg
(15.2 kB
view details)
File details
Details for the file SmallSettings-0.2.2.tar.gz
.
File metadata
- Download URL: SmallSettings-0.2.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40d61408d07d813ad0ccfaaecacbec544f6a90af28493ae733f9c3e3e1e9fc57 |
|
MD5 | aba72b0187343c391ebffa0f83b68a6d |
|
BLAKE2b-256 | 8490eb3ba4ca9cf986fc2c064d2310632ee0255ef40058b31f99cc14f0f1073c |
File details
Details for the file SmallSettings-0.2.2-py3.3.egg
.
File metadata
- Download URL: SmallSettings-0.2.2-py3.3.egg
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd6fe1a98da99c151106c3abe8443814671cd4fd9cd9331d5c768d616d92e83 |
|
MD5 | 319f28b16e2d5568c9a5947f56c703c1 |
|
BLAKE2b-256 | d24407cf7465f09a11a9f9513af4bebd25e2322078bdcbc678db7257860f63a3 |
File details
Details for the file SmallSettings-0.2.2-py2.7.egg
.
File metadata
- Download URL: SmallSettings-0.2.2-py2.7.egg
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71b2bc1265c192e2410c0d8506b2180777d88a8c0265e1582dfcad4052224851 |
|
MD5 | 341805f550357e61b234becedfd07dfb |
|
BLAKE2b-256 | d66a0593841ab4746bdf302be77eb78fe3068ead9de55d87790a121f50752eae |