pyenv-configurator


Namepyenv-configurator JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/satyamsoni2211/pyenv_configurator
SummaryDynamic Config Class Creation using Environment Variables
upload_time2023-04-16 12:41:49
maintainer
docs_urlNone
authorsatyam soni
requires_python>=3.9,<4.0
licenseMIT
keywords config environment variables env config class dynamic creation pyenv-configurator python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## PYENV_CONFIGURATOR

---

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

Before `pyenv_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 `pyenv_configurator` this can be reduced to below:

```python
from pyenv_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_DROVER'
        )
```

### Benefits of using `pyenv_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 pyenv_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_DROVER'
        )
```

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 ?

---

`pyenv_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/pyenv_configurator",
    "name": "pyenv-configurator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "config,environment,variables,env,config,class,dynamic,creation,pyenv-configurator,python",
    "author": "satyam soni",
    "author_email": "satyam.soni@hotmail.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/0e/09/6d38cbb8924c87cb24f08f90196f5caac616ebc4c8a63122049328537d5b/pyenv_configurator-0.1.0.tar.gz",
    "platform": null,
    "description": "## PYENV_CONFIGURATOR\n\n---\n\nA utility library for Dynamic Config class generation. Now no more repeated boilerplate code...\n\nBefore `pyenv_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 `pyenv_configurator` this can be reduced to below:\n\n```python\nfrom pyenv_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_DROVER'\n        )\n```\n\n### Benefits of using `pyenv_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 pyenv_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_DROVER'\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`pyenv_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",
        "pyenv-configurator",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82c16a9d6514ab2d7a8db4386b426e3278a327055c364fa3046a870f41992e59",
                "md5": "20c5461457d3f96373add797b56f95e7",
                "sha256": "a6c703814b3c6bb9cce883c4c7f5f6caf59e8122d7dd10c1f9b15dfe690ba20b"
            },
            "downloads": -1,
            "filename": "pyenv_configurator-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20c5461457d3f96373add797b56f95e7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 6739,
            "upload_time": "2023-04-16T12:41:46",
            "upload_time_iso_8601": "2023-04-16T12:41:46.078806Z",
            "url": "https://files.pythonhosted.org/packages/82/c1/6a9d6514ab2d7a8db4386b426e3278a327055c364fa3046a870f41992e59/pyenv_configurator-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e096d38cbb8924c87cb24f08f90196f5caac616ebc4c8a63122049328537d5b",
                "md5": "8ddeb41d5ae25484191a8ac3a68c5106",
                "sha256": "60f453248a12c58b94b9905f9677fd7034e64ee62573570b82fb2f82c18455e5"
            },
            "downloads": -1,
            "filename": "pyenv_configurator-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8ddeb41d5ae25484191a8ac3a68c5106",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 4650,
            "upload_time": "2023-04-16T12:41:49",
            "upload_time_iso_8601": "2023-04-16T12:41:49.366436Z",
            "url": "https://files.pythonhosted.org/packages/0e/09/6d38cbb8924c87cb24f08f90196f5caac616ebc4c8a63122049328537d5b/pyenv_configurator-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-16 12:41:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "satyamsoni2211",
    "github_project": "pyenv_configurator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "pyenv-configurator"
}
        
Elapsed time: 0.05660s