Skip to main content

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 Store
  • aws_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)

Source distribution for value-fetcher 1.0.3
File Size Uploaded
value_fetcher-1.0.3.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for value-fetcher 1.0.3
File Interpreter ABI Platform
value_fetcher-1.0.3-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page