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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: yamlsub-1.3.8.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for yamlsub-1.3.8.tar.gz
Algorithm Hash digest
SHA256 f8839063b1e93471328c0f50be28b972155283daa0ab4a2416a2239c1165cfd9
MD5 9ef34f988ea29c821ef5e9188b8a2ccb
BLAKE2b-256 0d60762c963abfd391df3ad782c3f2b18217d2f332b2b03b691864cc7d3ac519

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yamlsub-1.3.8-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for yamlsub-1.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bcb6dd3fa903f82743a1f65ba9ca68546fcf0e239a6fa99cc8b142b7d51f5233
MD5 6e465ee0d74f81af440184c8a04b7d8c
BLAKE2b-256 bf7a6dd709d3b770402ecde674bcc065d4fe6862d91d7495b706ef5a7a73231f

See more details on using hashes here.

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