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.
Release files for configi 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| configi-0.1.3.tar.gz | 3.7 kB | Details |
Release files / configi-0.1.3.tar.gz
| Download URL | configi-0.1.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc32a8d3ed5ef17afebcfa452d7f5f6cdd93b25ca63f07d2a20a5bdc4204ac90
|
|
BLAKE2b-256 checksum How to use checksums |
3354df1a03357f512199a5b2eb200ab2af6bfcce30e5a1dfbed61c2b28e6fe26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |