Skip to main content

A YAML configuration wrapper.

Project description

YAML Config Wrapper

CircleCI GitHub license

About

A YAML configuration wrapper. PYPI Package

Table of Contents

Using the library

Installing and using the library

First, you need to install the library either using pip:

$ pip install yaml_config_wrapper

Then, import it and use it like so:

from yaml_config_wrapper import Configuration

# The `config_schema_path` argument is optional
conf = Configuration(config_src='confs/template_conf.yml',
                     config_schema_path='yml_schemas/default_schema.json')

Creating a config file

There are two already example yml configs under confs. An example structure is the following:

tag: production
cloudstore:
  config:
    api_key: !ENV ${DROPBOX_API_KEY}
  type: dropbox
datastore:
  config:
    hostname: !ENV ${MYSQL_HOST}
    username: !ENV ${MYSQL_USERNAME}
    password: !ENV ${MYSQL_PASSWORD}
    db_name: !ENV ${MYSQL_DB_NAME}
    port: 3306
  type: mysql
email_app:
  config:
    email_address: !ENV ${EMAIL_ADDRESS}
    api_key: !ENV ${GMAIL_API_KEY}
  type: gmail

The !ENV flag indicates that you are passing an environmental value to this attribute. You can change the values/environmental var names as you wish.

There is also the option to create a validation schema the enforces a specific yaml structure. The default dummy version is the default_schema.json file.

Set the required environment variables

In order to use the !ENV flag in you config, you need to set the corresponding environment variables like so:

$ export DROPBOX_API_KEY=123
$ export MYSQL_HOST=foo.rds.amazonaws.com
$ export MYSQL_USERNAME=user
$ export MYSQL_PASSWORD=pass
$ export MYSQL_DB_NAME=Test_schema
$ export EMAIL_ADDRESS=Gmail Bot <foobar@gmail.com>
$ export GMAIL_API_KEY=123

The best way to do that, is to create a .env file (example), and source it before running the code.

Manually install the library

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You need to have a machine with anaconda installed and any Bash based shell (e.g. zsh) installed.

$ conda -V
conda 4.10.1

$ echo $SHELL
/usr/bin/zsh

Install the requirements

All the installation steps are being handled by the Makefile.

First, modify the python version (min_python) and everything else you need in the settings.ini.

Then, execute the following commands:

$ make create_env
$ conda activate yaml_config_wrapper
$ make dist

Now you are ready to use and modify the library.

Run the Unit Tests

If you want to run the unit tests, execute the following command:

$ make tests

Continuous Integration

For the continuous integration, the CircleCI service is being used. For more information you can check the setup guide.

Again, you should set the above-mentioned environmental variables (reference) and for any modifications, edit the circleci config .

Update PyPI package

This is mainly for future reference for the developers of this project. First, create a file called ~/.pypirc with your pypi login details, as follows:

[pypi]
username = your_pypi_username
password = your_pypi_password

Then, modify the python version (min_python), project status (status), release version (version) and everything else you need in the settings.ini.

Finally, execute the following commands:

$ make create_env
$ conda activate yaml_config_wrapper
$ make release

For a dev release, change the testing_version and instead of make release, run make release_test.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Buy Me A Coffee

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

yaml-config-wrapper-1.0.4.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

yaml_config_wrapper-1.0.4-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file yaml-config-wrapper-1.0.4.tar.gz.

File metadata

  • Download URL: yaml-config-wrapper-1.0.4.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for yaml-config-wrapper-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b372c9fe625a3df81e8cb2ee02e9f956618bd8897e406bc22e4feb0ccbddc8d8
MD5 f3e27393f555cbf9960dcf5512021b8c
BLAKE2b-256 e750dbeae3492a7b354dde38ee8f45648b58b6792152be112b20943da958c682

See more details on using hashes here.

File details

Details for the file yaml_config_wrapper-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: yaml_config_wrapper-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for yaml_config_wrapper-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0133a4cc45ce2f7df69fe0588613b0efbac1b18158eedfab40becb8035516e42
MD5 2063769ed85c162c88dbfc62faac85ae
BLAKE2b-256 fe311aac3a92357ba3a8437373f30889fbd6b71a60ffa3e325a2de2813ca6c53

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