Skip to main content

A sample project that uses a YAML config file

Project description

Project Title

YAML substitution

Project Shields

License Supported Python Versions PyPI Releases

Table of Contents

About

A wrapper around the dotenv and pyaml-env packages.

Getting Started

This project just serves as a wrapper to load environment variables from a .env file, and then update a YAML configuration file with environment variables as needed / required.

It's important to view the documentation for the pyaml-env and dotenv projects.

Prerequisites

  • python, version 3.11+
  • python's build package: pip install build

Installing

To install using pip:

pip install yamlsub

To include the package from VCS in a project, you can follow the pip documentation to import a GitHub project.

For example:

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

Usage

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

Using an example .env file containing the following ...

DB_HOST=localhost
DB_USER=root
DB_PASS=123456

... and a sample config.yaml file ...

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

... and the following code ...

from yamlsub.config import Config

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

, you can access configuration values as follows:

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.3.8.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

yamlsub-1.3.8-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

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