lazy-env-configurator


Namelazy-env-configurator JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/satyamsoni2211/lazy_env_configurator
SummaryDynamic Config Class Creation using Environment Variables
upload_time2023-04-17 05:37:42
maintainer
docs_urlNone
authorsatyam soni
requires_python>=3.9,<4.0
licenseMIT
keywords config environment variables env config class dynamic creation lazy_env_configurator python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## LAZY_ENV_CONFIGURATOR

---

![Github Builds](https://img.shields.io/github/actions/workflow/status/satyamsoni2211/lazy_env_configurator/python-app.yml?style=plastic)

A utility library for Dynamic Config class generation. Now no more repeated boilerplate code...

Before `lazy_env_configurator`, config classes used to be created as below.

```python
    class BaseConfig:
        APP = os.environ.get("APP")
        APP_ENV = os.environ.get("APP_ENV")

        # authentication related configuration
        # DB Credentials
        DB_USERNAME = os.environ.get("DB_USERNAME")
        DB_PASSWORD = os.environ.get("DB_PASSWORD")
        DB_HOST = os.environ.get("DB_HOST")
        DB_PORT = os.environ.get("DB_PORT")
        DB_NAME = os.environ.get("DB_NAME")
        DB_DRIVER = os.environ.get("DB_DRIVER")
```

This use to require a lot of boiler plate and redundant code With `lazy_env_configurator` this can be reduced to below:

```python
from lazy_env_configurator import BaseEnv, BaseConfig as Config_
class BaseConfig(BaseEnv):
    class Config(Config_):
        envs = ('APP',
        'APP_ENV',
        'DB_USERNAME',
        'DB_PASSWORD',
        'DB_PASSWORD',
        'DB_HOST',
        # defaults
        ('DB_PORT',3306),
        'DB_NAME',
        'DB_DRIVER'
        )
```

### Benefits of using `lazy_env_configurator` over Normal classes

---

- Low memory footprint.
- Lazily evaluates environment variable and only loads them when used.
- Once loaded, env variables are cached.
- Get defaults populated, in case of missing `env` variables.
- env attributes can be overridden easily.
- classes expose `instance` attribute preventing need to initialization and making it behave singleton.
- Loads `.env` files by default so you only need to focus on essentials.

### How to use

Let us refer below example:

```python
from lazy_env_configurator import BaseEnv, BaseConfig as Config_
class BaseConfig(BaseEnv):
    class Config(Config_):
        envs = ('APP',
        'APP_ENV',
        'DB_USERNAME',
        'DB_PASSWORD',
        'DB_PASSWORD',
        'DB_HOST',
        # defaults
        ('DB_PORT',3306),
        'DB_NAME',
        'DB_DRIVER'
        )
```

We can now use `BaseConfig` class create as below.

```python
>>>BaseConfig.instance.APP
```

Every class, subclassed from `BaseEnv` would expose `.instance` attribute which will be instance of the subclass. This instance can be used to access all the attributes on the class.

> For simplicity, `metaclass` pre-initialises created class, so to make it behave as singleton.

### How this works ?

---

`lazy_env_configurator` uses `descriptors` under the hood to dynamically populate env variables as attributes, thus making them available on demand, `Lazily`.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/satyamsoni2211/lazy_env_configurator",
    "name": "lazy-env-configurator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "config,environment,variables,env,config,class,dynamic,creation,lazy_env_configurator,python",
    "author": "satyam soni",
    "author_email": "satyam.soni@hotmail.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/25/34/202996072497d5c0235cbc4fcc674f659cf40580da36db8e4e001406ab00/lazy_env_configurator-0.1.0.tar.gz",
    "platform": null,
    "description": "## LAZY_ENV_CONFIGURATOR\n\n---\n\n![Github Builds](https://img.shields.io/github/actions/workflow/status/satyamsoni2211/lazy_env_configurator/python-app.yml?style=plastic)\n\nA utility library for Dynamic Config class generation. Now no more repeated boilerplate code...\n\nBefore `lazy_env_configurator`, config classes used to be created as below.\n\n```python\n    class BaseConfig:\n        APP = os.environ.get(\"APP\")\n        APP_ENV = os.environ.get(\"APP_ENV\")\n\n        # authentication related configuration\n        # DB Credentials\n        DB_USERNAME = os.environ.get(\"DB_USERNAME\")\n        DB_PASSWORD = os.environ.get(\"DB_PASSWORD\")\n        DB_HOST = os.environ.get(\"DB_HOST\")\n        DB_PORT = os.environ.get(\"DB_PORT\")\n        DB_NAME = os.environ.get(\"DB_NAME\")\n        DB_DRIVER = os.environ.get(\"DB_DRIVER\")\n```\n\nThis use to require a lot of boiler plate and redundant code With `lazy_env_configurator` this can be reduced to below:\n\n```python\nfrom lazy_env_configurator import BaseEnv, BaseConfig as Config_\nclass BaseConfig(BaseEnv):\n    class Config(Config_):\n        envs = ('APP',\n        'APP_ENV',\n        'DB_USERNAME',\n        'DB_PASSWORD',\n        'DB_PASSWORD',\n        'DB_HOST',\n        # defaults\n        ('DB_PORT',3306),\n        'DB_NAME',\n        'DB_DRIVER'\n        )\n```\n\n### Benefits of using `lazy_env_configurator` over Normal classes\n\n---\n\n- Low memory footprint.\n- Lazily evaluates environment variable and only loads them when used.\n- Once loaded, env variables are cached.\n- Get defaults populated, in case of missing `env` variables.\n- env attributes can be overridden easily.\n- classes expose `instance` attribute preventing need to initialization and making it behave singleton.\n- Loads `.env` files by default so you only need to focus on essentials.\n\n### How to use\n\nLet us refer below example:\n\n```python\nfrom lazy_env_configurator import BaseEnv, BaseConfig as Config_\nclass BaseConfig(BaseEnv):\n    class Config(Config_):\n        envs = ('APP',\n        'APP_ENV',\n        'DB_USERNAME',\n        'DB_PASSWORD',\n        'DB_PASSWORD',\n        'DB_HOST',\n        # defaults\n        ('DB_PORT',3306),\n        'DB_NAME',\n        'DB_DRIVER'\n        )\n```\n\nWe can now use `BaseConfig` class create as below.\n\n```python\n>>>BaseConfig.instance.APP\n```\n\nEvery class, subclassed from `BaseEnv` would expose `.instance` attribute which will be instance of the subclass. This instance can be used to access all the attributes on the class.\n\n> For simplicity, `metaclass` pre-initialises created class, so to make it behave as singleton.\n\n### How this works ?\n\n---\n\n`lazy_env_configurator` uses `descriptors` under the hood to dynamically populate env variables as attributes, thus making them available on demand, `Lazily`.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Dynamic Config Class Creation using Environment Variables",
    "version": "0.1.0",
    "split_keywords": [
        "config",
        "environment",
        "variables",
        "env",
        "config",
        "class",
        "dynamic",
        "creation",
        "lazy_env_configurator",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdb881dca5f9d2de9defdfcdd101ef41321067aa4c0f23524d124ea251389be8",
                "md5": "0c2215ae97682456e28e508158c4dbd4",
                "sha256": "abbc5c782f2930c1fe2ea6ddd738024d7140294acc3e8011070b4fd18fbefa7a"
            },
            "downloads": -1,
            "filename": "lazy_env_configurator-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c2215ae97682456e28e508158c4dbd4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 6223,
            "upload_time": "2023-04-17T05:37:39",
            "upload_time_iso_8601": "2023-04-17T05:37:39.627720Z",
            "url": "https://files.pythonhosted.org/packages/bd/b8/81dca5f9d2de9defdfcdd101ef41321067aa4c0f23524d124ea251389be8/lazy_env_configurator-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2534202996072497d5c0235cbc4fcc674f659cf40580da36db8e4e001406ab00",
                "md5": "3c7bcf12384c87ab7078dad9e18bfd56",
                "sha256": "f19cf5ca01024a68ecb6c14324e8c2536fd30029c40f0b73c2066bfb389b68b4"
            },
            "downloads": -1,
            "filename": "lazy_env_configurator-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3c7bcf12384c87ab7078dad9e18bfd56",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 4326,
            "upload_time": "2023-04-17T05:37:42",
            "upload_time_iso_8601": "2023-04-17T05:37:42.002553Z",
            "url": "https://files.pythonhosted.org/packages/25/34/202996072497d5c0235cbc4fcc674f659cf40580da36db8e4e001406ab00/lazy_env_configurator-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-17 05:37:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "satyamsoni2211",
    "github_project": "lazy_env_configurator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "lazy-env-configurator"
}
        
Elapsed time: 0.05499s