Skip to main content

Package short description.

Project description

Documentation Status https://travis-ci.org/MacHu-GWU/configirl-project.svg?branch=master https://codecov.io/gh/MacHu-GWU/configirl-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/configirl.svg https://img.shields.io/pypi/l/configirl.svg https://img.shields.io/pypi/pyversions/configirl.svg https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social
https://img.shields.io/badge/Link-Document-blue.svg https://img.shields.io/badge/Link-API-blue.svg https://img.shields.io/badge/Link-Source_Code-blue.svg https://img.shields.io/badge/Link-Install-blue.svg https://img.shields.io/badge/Link-GitHub-blue.svg https://img.shields.io/badge/Link-Submit_Issue-blue.svg https://img.shields.io/badge/Link-Request_Feature-blue.svg https://img.shields.io/badge/Link-Download-blue.svg

Welcome to configirl Documentation

What is configirl

configirl is a single script, pure python, no dependencies, python2.7, 3.4+ compatible, drop in ready python library to help you manage complex config value logic.

from configirl import ConfigClass, Constant, Deriable

class Config(object):
    PROJECT_NAME = Constant()
    PROJECT_NAME_SLUG = Deriable()

    @PROJECT_NAME_SLUG.getter
    def get_project_name_slug(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

config = Config(PROJECT_NAME="my_project")

What problem does configirl solve

Devops Engineer has to deal with lots of config and parameters everyday. Some config value are just a constant value, like a integer and a string. Some config value can be derived from other config values, sometimes event requires the context.

There are lots of Devops tools available in the community, such as:

  • Shell Script for command line tool, automation

  • Jenkins groovy for CI/CD

  • Cloudformation for Infrastructure as Code

  • Terraform for Infrastructure as Code

They all using different language and different syntax. The way, and flexibility of managing config value in different tools varies very much! If you have to manage a list of config values, and you are using multiple devops tools in the same project. Allow those tools talk to each other is NOT EASY at all. And the effort to manage config value in certain tools might be very difficult (like CloudFormation).

configirl provides a solution to manage complex logic for config values in an elegant way. Since Python is easy to learn and it is full featured programming language, you got the perfect balance of simplicity and flexibility. To integrate with any Devops tools, you just reference the value from the finalized config JSON file.

Quick Start

  1. Copy configirl.__init__.py to your Devops workspace directory, and rename it as configirl.py. That is for drop in ready.

  2. Create a config-raw.json file put the following content:

{
    "PROJECT_NAME": "my_project",
    "STAGE": "dev"
}
  1. Create a config.py file, put the following content. Since it is Python2.7, 3.4+ compatible, pure Python, no dependencies, it works everywhere.

from configirl import ConfigClass, Constant, Derivable

class Config(object):
    CONFIG_DIR = "your-devops-workspace-dir"

    PROJECT_NAME = Constant()
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_project_name_slug(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    @PROJECT_NAME_SLUG.validator
    def check_project_name_slug(self, value):
        if "_" in value:
            raise ValueError("you can't use `_` in slugifie name!")

    STAGE = Constant()

    ENVIRONMENT_NAME = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_environment_name(self):
        return "{}-{}".format(
            self.PROJECT_NAME_SLUG.get_value(),
            self.STAGE.get_value(),
        )

config = Config()
config.update_from_raw_json_file()
config.dump_shell_script_json_config_file()
config.dump_cloudformation_json_config_file()
# you can call more custom dump method here
# depends on what other devops tools you are using
  1. Everytime you call python config.py then the ground truth config value in config-raw.json will be parsed. and two more config-final-for-shell-script.json, config-final-for-cloudformation.json will be create. Then you can just reference value from thos xxx-final-xxx.json file.

// content of config-final-for-shell-script.json
{
    "PROJECT_NAME": "my_project",
    "PROJECT_NAME_SLUG": "my-project",
    "STAGE": "dev",
    "ENVIRONMENT_NAME": "my-project-dev"
}
// content of config-final-for-cloudformation.json
{
    "ProjectName": "my_project",
    "ProjectNameSlug": "my-project",
    "Stage": "dev",
    "EnvironmentName": "my-project-dev"
}

Additional Feature

  1. you can custom your validator.

from configirl import ConfigClass, Constant, Derivable

class Config(object):
    PROJECT_NAME = Constant()
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_project_name_slug(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    @PROJECT_NAME_SLUG.validator
    def check_project_name_slug(self, value):
        if "_" in value:
            raise ValueError("you can't use `_` in slugifie name!")
  1. you can inherit your Config Class.

from configirl import ConfigClass, Constant, Derivable

class Config1(object):
    PROJECT_NAME = Constant()

class Config2(Config1):
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_project_name_slug(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    @PROJECT_NAME_SLUG.validator
    def check_project_name_slug(self, value):
        if "_" in value:
            raise ValueError("you can't use `_` in slugifie name!")

class Config(Config2):
    CONFIG_DIR = "your-devops-workspace-dir"

config = Config()
... do what every you need

Install

configirl is released on PyPI, so all you need is:

$ pip install configirl

To upgrade to latest version:

$ pip install --upgrade configirl

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

configirl-0.0.2.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

configirl-0.0.2-py2.py3-none-any.whl (47.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file configirl-0.0.2.tar.gz.

File metadata

  • Download URL: configirl-0.0.2.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.2

File hashes

Hashes for configirl-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4489f9a22bc9407119c5a6b891b695421f139b25150c6c411a8829249def1d1c
MD5 be252d5335d147cb092bd7c8e32da77f
BLAKE2b-256 2e45671ab7103b3fc3eadf9fdb8c1c22e14e62430c8d1008ffc7b3a80deb17ee

See more details on using hashes here.

File details

Details for the file configirl-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: configirl-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.2

File hashes

Hashes for configirl-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 06d41cb615b17d5e0e2b2df94593ff3311b554b9c9bf6d906f161a46b8f76fba
MD5 cd8259361bfc8a8d8931b99f191ce39f
BLAKE2b-256 0a372ae908e38dc8fcc61fa10eb935c9d88a639dd38e7e364c6cdd6629f4115a

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