Configi is a straightforward wrapper for configuration data. It provides a consistent interface to a number of back-ends, currently via arbitrary HTTP JSON loading, Redis K/V store, and S3 JSON file loading.
Project description
Configi is a straightforward wrapper for configuration data. It provides a consistent interface to a number of back-ends, currently via arbitrary HTTP JSON loading, Redis K/V store, and S3 JSON file loading.
Using Configi
The code itself is documented, but here’s a couple of recipes:
S3 Config Source
from configi import DynamicConfig, S3ConfigSource
import boto # Boto not included, but if you want to use S3ConfigSource
# you probably have it already. I hope.
s3 = boto.connect_s3()
bucket = s3.get_bucket("my-config-repository")
config_file_key = bucket.get_key("my-config-file-key")
source = S3ConfigSource(config_file_key)
config = DynamicConfig(
source,
expiry=(60*4), # Every four hours reload
quiet_mode=True, # Errors will `print` instead of throwing Exceptions.
namespace_dicts=True, # Turn dictionaries into dot-accessible namespaces.
defaults={'some_key': 'a_value'} # Defaults dict is used to return values, if a key is unset remotely.
)
print config.foo
> None
config.foo = 'bar'
print config.foo
> bar
print config.some_key
> a_value
config.some_key = 'banana'
print config.some_key
> banana
Redis Config Source
from configi import DynamicConfig, RedisConfigSource
import redis # Redis not included, but if you want to use
# RedisConfigSource, then you'll need it.
r = redis.StrictRedis() # Get a Redis connection. Yours will have more parameters.
source = RedisConfigSource(r, prefix='MY_AWESOME_CONFIGI_CONFIG_SETUP:') # Default prefix is 'CONFIGI:'
config = DynamicConfig(
source,
expiry=(60*4), # Every four hours reload
quiet_mode=True, # Errors will `print` instead of throwing Exceptions.
namespace_dicts=True, # Turn dictionaries into dot-accessible namespaces.
defaults={'some_key': 'a_value'} # Defaults dict is used to return values, if a key is unset remotely.
)
print config.foo
> None
config.foo = 'bar'
print config.foo
> bar
print config.some_key # Even though defaults were passed, any remotely-set value overrides.
> orangutan
JSON File Config Source
from configi import DynamicConfig, JSONConfigSource
source = JSONConfigSource("https://some-url.com/my-config-file.json")
config = DynamicConfig(
source,
expiry=(60*4), # Every four hours reload
quiet_mode=True, # Errors will `print` instead of throwing Exceptions.
namespace_dicts=True, # Turn dictionaries into dot-accessible namespaces.
defaults={'some_key': 'a_value'} # Defaults dict is used to return values, if a key is unset remotely.
)
print config.foo
> None
config.foo = 'bar'
> DynamicConfigError: Could not set key foo
Caveats
Some of the config sources are better suited for read-only config. Namely, the arbitrary-JSON-file-based config is strictly read-only. The S3-based config is read/write but not very optimal for high-write scenarios. Redis, if a Redis store is both secure and available to you, is probably your best bet.
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
File details
Details for the file configi-0.1.3.tar.gz
.
File metadata
- Download URL: configi-0.1.3.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc32a8d3ed5ef17afebcfa452d7f5f6cdd93b25ca63f07d2a20a5bdc4204ac90 |
|
MD5 | 771a77da23435c2b450f8f07a6f339b1 |
|
BLAKE2b-256 | 3354df1a03357f512199a5b2eb200ab2af6bfcce30e5a1dfbed61c2b28e6fe26 |