Value fetcher
Introduction
Python module to fetch values from multiple sources with optional defaults, including:
- Environment variables
- AWS Systems Manager (SSM) Parameter Store
- AWS Secrets Manager
Usage
Install the package with the following:
pip install value-fetcher
Fetching values directly
In this use case, the value fetcher package makes it convenient to fetch values from the supported sources in a consistent and simplified manner.
from value_fetcher import ValueFetcher
# Instantiate value fetcher class
fetcher = ValueFetcher()
# Retrieve values from supported AWS sources
my_secret = fetcher.get_from_aws_secrets_manager('/my/secret/key')
my_param = fetcher.get_from_aws_ssm_parameter_store('/my/parameter/key')
Configuring source locations dynamically
In this use case, environment variables are used to configure the sources for multiple keys. This is useful in more complex applications where lots of values need to be fetched and the source needs to be configured dynamically. See this contact form handler repository for example usage.
Environment variables can be appended to the configuration key name, setting the source of the value. These are:
_PARAMETER_STORE_NAME- for AWS SSM Parameter Store_SECRETS_MANAGER_NAME- for AWS Secrets Manager
One of the available configuration sources for each value must also be set by setting an environment variable ending with _SOURCE for the value name:
env- Environment variables (default)aws_ssm_parameter_store- AWS Systems Manager (SSM) Parameter Storeaws_secrets_manager- AWS Secrets Manager
For example, to fetch MY_PARAM from AWS SSM Parameter Store and MY_SECRET from AWS Secrets Manager, consider the following python script (e.g. app.py) called subsequently by a shell script:
# This file is app.py for example
from value_fetcher import ValueFetcher
# Instantiate value fetcher class, with optional defaults if values cannot be found
fetcher = ValueFetcher({
'MY_PARAM': 'Default value if none can be found',
})
# Retrieve values from supported AWS sources
my_secret = fetcher.get('MY_SECRET')
my_param = fetcher.get('MY_PARAM')
print(my_secret)
print(my_param)
The above scripts would be called by the following shell script:
#!/usr/bin/bash
MY_PARAM_SOURCE="aws_ssm_parameter_store"
MY_PARAM_PARAMETER_STORE_NAME="/my/parameter/store/key/name"
MY_SECRET_SOURCE="aws_secrets_manager"
MY_SECRET_SECRETS_MANAGER_NAME="my/secrets/manager/key/name"
export MY_PARAM_SOURCE MY_PARAM_PARAMETER_STORE_NAME
export MY_SECRET_SOURCE MY_SECRET_SECRETS_MANAGER_NAME
# For AWS ensure credentials are available, e.g. with AWS SSO, aws-vault, aws-profile etc.
python app.py
Development
This project uses Poetry for package management. After cloning, run:
./scripts/poetry.sh
to install dependencies for local development and running tests, etc.
Tests
To run static code analysers and unit tests:
./scripts/validate.sh
Metadata
Release files for value-fetcher 1.0.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 | Provenance | Actions |
|---|---|---|---|---|
| value_fetcher-1.0.3.tar.gz | 7.0 kB | Without provenance | Details for value_fetcher-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| value_fetcher-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for value_fetcher-1.0.3-py3-none-any.whl |
Total release size: 12.7 kB
Release files / value_fetcher-1.0.3.tar.gz
| Download URL | value_fetcher-1.0.3.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
865ab7b442d2154a19aeb03c82ef62adc4adc3f11d42a8647cf1b26056743260
|
|
BLAKE2b-256 checksum How to use checksums |
dbea7e4c6137b3f8fb6b8baba747b52ebd5d91856e3f96b6e335c6196e9f21a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / value_fetcher-1.0.3-py3-none-any.whl
| Download URL | value_fetcher-1.0.3-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
29c86b24e7a02c472d51a93d52ef09e0b33e5e61a1a431a174f6e3700c6ecf44
|
|
BLAKE2b-256 checksum How to use checksums |
393f783362d128c3ea7bfbc0800b727debccf055f295ea580db47b9db3e7fa28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for value-fetcher 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.