Skip to main content

envyconfig

Envyconfig is a python package for reading YAML config files with pointers to external keys. It reads the specified YAML file, fetches data from the configured sources, and returns the corresponding dict structure.

The primary purpose is to allow keys to secret configuration items to be stored in the YAML file, for ease of use during program loading.

Builds on the PyYAML package, with the following additions:

  • Environment variables can be specified as config values.
  • GCP Secrets can be specified as config values.
  • Nested YAML structures can be flattened to get a simple key / value dict.
  • Default values can be specified, for instance from the command line.

Requires Python 3.8 or higher.

Basic Usage

>> > import envyconfig
>> > config = envyconfig.load(config_file='my_config.yaml')
>> > print(config)
{'foo': {'bar': 'baz'}}

Sample config file.

foo:

   # Google Cloud Secret Manager: Loads "bar" from secret "bar" in the "my-project"
   #  GCP project.
   bar: ${gs:/my-project/my-secret}

   # Environment variables: Loads "baz" from the environment variable "BAZ".
   # If this variable is not set, it defaults to "something_else".
   baz: ${env:BAZ:something_else}

   # HashiCorp Vault: Loads "bam" from the secret "bam" mounted Vault mount
   # "/path/to/secrets/mount/my-secrets/".
   bam: ${vault:/path/to/secrets/mount/my-secrets/bam}

Usage Details

Interpolation keys.

You indicate the values you want interpolated by one of the configured engines through a wrapper ${<method>:<key>:<default>}, such as ${env:MY_VAR:my_default}. The currently supported engines are

  • environment (os.environ) variables (key: env), and
  • Google Secret Manager (key: gs).
  • HashiCorp Vault
  • Format strings for run-time interpolation. The engines are lazy-loaded, so unless you request interpolation by one of them, the configuration is not loaded. This is useful for advanced engines (presently gs), that rely on external libraries and configuration.

As the method, key and default values are separated by a :, this character is not allowed in the method or key names. It is allowed in default values, though. So $(env:REDIRECT_PAGE:https://localhost/} is legal syntax.

Environment variables

Environment variables behave like you expect them to.

Google Secret Manager

This engine requires the optional dependency (or separate installation of) google-cloud-secret-manager (i.e. pip install envyconfig[google-cloud-secret-manager]), and a pointer to your GCP key (GOOGLE_APPLICATION_CREDENTIALS), as described on Authenticating as a service account)

Credits and further documentation

Release files for envyconfig 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for envyconfig 1.2.1
File Interpreter ABI Platform
envyconfig-1.2.1-py3-none-any.whl Python 3 none any Details

Release files / envyconfig-1.2.1-py3-none-any.whl

Download URL envyconfig-1.2.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c44f40d268f3ff429258376c9152031f0784b771f012cbf8bb9449e85f4db40d
BLAKE2b-256 checksum
How to use checksums
6355cfe014cc80450bfe0a2cd70b30418b4400bbe6ca791b39d1b93ea1c50884
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

1.2.1 This release

1 release file

1.2.0

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.0

2 release files

0.5.3

2 release files

0.4.5

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.0.0

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