AWS config sources for the typedconfig package
Project description
typed-config-aws-sources
AWS config sources for the typed-config package.
pip install typed-config-aws-sources
Requires python 3.6 or above.
Basic usage
Please read the readme for typed-config first.
# my_app/config.py
from typedconfig_awssource import IniS3ConfigSource
from typedconfig import Config, key, section
@section('database')
class AppConfig(Config):
port = key(cast=int)
config = AppConfig()
config.add_source(IniS3ConfigSource('my_bucket_name', 'config_key.cfg'))
config.read()
# my_app/main.py
from my_app.config import config
print(config.host)
Supplied Config Sources
IniS3ConfigSource
This loads configuration from an INI file stored in an S3 bucket
from typedconfig_awssource import IniS3ConfigSource
source = IniS3ConfigSource('bucket_name', 'key_name.cfg', encoding='utf8', must_exist=True)
- Supply the bucket name and key name as the first two arguments
encoding
defaults to'utf8'
if not suppliedmust_exist
defaults toTrue
if not supplied. Ifmust_exist
isFalse
, and the bucket or key can't be found, or AWS credentials fail, then no error is thrown and this config source will just return than it cannot find the requested config value every time.
An example INI file might look like this:
[database]
port = 2000
DynamoDBConfigSource
This reads configuration from a DynamoDB table. The table should have a partition key which holds the config section, a sort key which holds the config key name, and another 'column' containing the config value as a string.
So an item in DynamoDB corresponding to the above INI file example would look like this
{
"section": "database",
"key": "port",
"value": "2000"
}
Create the DynamoDBConfigSource
like this:
from typedconfig_awssource import DynamoDbConfigSource
source = DynamoDbConfigSource('table_name',
section_attribute_name='config_section_column_name',
key_attribute_name='config_key_column_name',
value_attribute_name='config_value_column_name')
- The first argument is the DynamoDB table name and is required
- The other three arguments are optional, and are supplying the attribute (or "column") names in the table which store the three things defining a config parameter (section, key, and value)
- Default attribute names are
"section"
,"key"
, and"value"
Contributing
Ideas for new features and pull requests are welcome. PRs must come with tests included. This was developed using Python 3.7 but Travis tests run with v3.6 too.
Development setup
- Clone the git repository
- Create a virtual environment
virtualenv venv
- Activate the environment
venv/scripts/activate
- Install development dependencies
pip install -r requirements.txt
Running tests
pytest
To run with coverage:
pytest --cov
Deploying to PyPI
You'll need to pip install twine
if you don't have it.
- Bump version number in
typedconfig_awssource/__version__.py
python setup.py sdist bdist_wheel
twine check dist/*
- Upload to the test PyPI
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
- Check all looks ok at https://test.pypi.org/project/typed-config-aws-sources
- Upload to live PyPI
twine upload dist/*
Here is a good tutorial on publishing packages to PyPI.
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 Distribution
Hashes for typed-config-aws-sources-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9764a8387552d0b2f31617bf4c541dded5b6849559e2db8b7505d944be2de2d3 |
|
MD5 | 39b79a158dc25224d0d183d8b77f876a |
|
BLAKE2b-256 | bdcc16e88802689a5a6e1e535f34271e1b5d8a3f6d83d107b54429cd98774d57 |
Hashes for typed_config_aws_sources-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaebaf149a0e14a830878f1056296feaee737ecbc2cd983cea71eaa75a886886 |
|
MD5 | 751cf0e632134359cbedec4243b18c10 |
|
BLAKE2b-256 | 9fb67934fcc2fe4e856c7fc96a036ffbb3086ab697cf05f812898aafa9bae583 |