You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

yamlsub

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yamlsub

A sample project that uses a YAML config file

1.3.8
Maintainers
1

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}')

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts