Skip to main content

YAML configuration with environment variable substitution via .env files

Project description

yamlsub

YAML configuration with environment variable substitution.

Project Shields

License Supported Python Versions PyPI Releases

Table of Contents

About

A wrapper around the python-dotenv and pyaml-env packages that loads environment variables from a .env file and substitutes them into a YAML configuration file.

Getting Started

Prerequisites

  • Python 3.12+

Installing

Using pip:

pip install yamlsub

Using uv:

uv add yamlsub

To install directly from GitHub:

pip install yamlsub@git+https://github.com/willmorejg/yamlsub.git

Usage

Review the documentation for pyaml-env and python-dotenv for additional information on how to incorporate this project into other projects.

Given a .env file:

DB_HOST=localhost
DB_USER=root
DB_PASS=123456

And a config.yaml file:

database:
  host: !ENV ${DB_HOST}
  user: !ENV ${DB_USER}
  pass: !ENV ${DB_PASS}

Load and access the configuration:

from yamlsub.config import Config

cfg = Config(yaml_path='config.yaml', env_path='.env')

# Retrieve the full configuration
full_config = cfg.get_config()

# Retrieve a specific top-level key
database_config = cfg.get_config_key('database')
dbhost = database_config['host']
dbuser = database_config['user']
dbpass = database_config['pass']

print(f'Host: {dbhost}, User: {dbuser}, Pass: {dbpass}')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlsub-1.4.5.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yamlsub-1.4.5-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file yamlsub-1.4.5.tar.gz.

File metadata

  • Download URL: yamlsub-1.4.5.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yamlsub-1.4.5.tar.gz
Algorithm Hash digest
SHA256 7b1be619f4f3182ec7c3e2dff07ddae5e514533e98399c5209c27fb6f5f9d83c
MD5 5c00f02c75499a24c59e6e7c0c8a5a9f
BLAKE2b-256 ec37ad286b4ef6cc584f6dd2b0bf9d98e6c4192fa792d4950272390045652da0

See more details on using hashes here.

File details

Details for the file yamlsub-1.4.5-py3-none-any.whl.

File metadata

  • Download URL: yamlsub-1.4.5-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yamlsub-1.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 95e31a22493cf02a3fe2a23b6f5b52942db835efda92519a8128da821d57809b
MD5 a00f588ed61a6dd81a140e371cd1d2d2
BLAKE2b-256 543aab42f19f7dd7d564e099160cfbf1c03f82de83e7ea25200a433dedee4102

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page