yapeco


Nameyapeco JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/turtlebasket/yapeco
SummaryYet Another Python Envvar Config Object
upload_time2023-11-23 02:16:35
maintainer
docs_urlNone
authorMichael Lisano
requires_python>=3.8,<4.0
licenseAGPL-3.0-or-later
keywords python config environment dotenv variables
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `yapeco`: Yet Another Python Envvar Config Object

A positively miniscule utility module to access `.env` (and otherwise environment-defined) config values in a structured way through a Python object. Created out of annoyance with not being able to autocomplete said envvars in my editor :^)

## Features & Limitations

- Case-insensitive + snake-case (i.e. `SNAKE_case`) field names
- Primitives such as `str`, `bool`, `int` and `float` are supported (no guarantees with `float` though, because, well... floating point)
- Assuming use of the above primitives, supports `Optional[*]` types (and by extension `Union[*,None]`), but no others from `typing`
- Default values through class variable assignment; assumed to be `None` for optional types
- Will (intentionally) raise a `RuntimeError` if there is no value set and no default value
- Common boolean config formats (i.e. `VAR=0/1/true/false/True/False`) work as expected

## Usage

Installation (PyPI):

```bash
pip3 install yapeco
```

A simple example:

```bash
# -- [mock environment] ---------------------------
API_KEY=abc123
DELAY_MSEC=18
FEATURE_A_ENABLED=false
FEATURE_B_ENABLED=1
```

```python
# --- contrived_config.py -------------------------

from yapeco import BaseEnvironment as Env

class Config(Env):
    api_key: str
    delay_msec: int
    feature_a_enabled: bool
    feature_a_flags: str = "-a -b -c"
    feature_b_enabled: bool
    feature_b_flags: Optional[str]


# --- main.py -------------------------------------

from config import Config

Config.api_key # "abc123"
Config.delay_msec # 18
Config.feature_a_enabled # False
Config.feature_a_flags # "-a -b -c"
Config.feature_b_enabled # True
Config.feature_b_flags # None

# ...
# API_KEY=def456
# FEATURE_B_ENABLED=false

Config.refresh() # update environment

Config.api_key # "def456"
Config.feature_b_enabled # False
```

## Development

Requires [poetry](https://python-poetry.org/).

```bash
poetry install  # install dependencies
poetry build  # build package
poetry run pytest .  # run tests
poetry run pyright .  # run type checks
```

## Feature Backburner

- Support implied types (type conversion currently depends on `cls.__annotations__`)

## Extra

Pedantic note:

> As in Smalltalk, classes themselves are objects. 
>
> —[The Literal Python Documentation](https://docs.python.org/3/tutorial/classes.html)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/turtlebasket/yapeco",
    "name": "yapeco",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "python,config,environment,dotenv,variables",
    "author": "Michael Lisano",
    "author_email": "mlisano@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a9/71/89dec9b670ea4aaf5baf363b662c0b4c586f873b22c7bed904b55dd4eb93/yapeco-0.1.2.tar.gz",
    "platform": null,
    "description": "# `yapeco`: Yet Another Python Envvar Config Object\n\nA positively miniscule utility module to access `.env` (and otherwise environment-defined) config values in a structured way through a Python object. Created out of annoyance with not being able to autocomplete said envvars in my editor :^)\n\n## Features & Limitations\n\n- Case-insensitive + snake-case (i.e. `SNAKE_case`) field names\n- Primitives such as `str`, `bool`, `int` and `float` are supported (no guarantees with `float` though, because, well... floating point)\n- Assuming use of the above primitives, supports `Optional[*]` types (and by extension `Union[*,None]`), but no others from `typing`\n- Default values through class variable assignment; assumed to be `None` for optional types\n- Will (intentionally) raise a `RuntimeError` if there is no value set and no default value\n- Common boolean config formats (i.e. `VAR=0/1/true/false/True/False`) work as expected\n\n## Usage\n\nInstallation (PyPI):\n\n```bash\npip3 install yapeco\n```\n\nA simple example:\n\n```bash\n# -- [mock environment] ---------------------------\nAPI_KEY=abc123\nDELAY_MSEC=18\nFEATURE_A_ENABLED=false\nFEATURE_B_ENABLED=1\n```\n\n```python\n# --- contrived_config.py -------------------------\n\nfrom yapeco import BaseEnvironment as Env\n\nclass Config(Env):\n    api_key: str\n    delay_msec: int\n    feature_a_enabled: bool\n    feature_a_flags: str = \"-a -b -c\"\n    feature_b_enabled: bool\n    feature_b_flags: Optional[str]\n\n\n# --- main.py -------------------------------------\n\nfrom config import Config\n\nConfig.api_key # \"abc123\"\nConfig.delay_msec # 18\nConfig.feature_a_enabled # False\nConfig.feature_a_flags # \"-a -b -c\"\nConfig.feature_b_enabled # True\nConfig.feature_b_flags # None\n\n# ...\n# API_KEY=def456\n# FEATURE_B_ENABLED=false\n\nConfig.refresh() # update environment\n\nConfig.api_key # \"def456\"\nConfig.feature_b_enabled # False\n```\n\n## Development\n\nRequires [poetry](https://python-poetry.org/).\n\n```bash\npoetry install  # install dependencies\npoetry build  # build package\npoetry run pytest .  # run tests\npoetry run pyright .  # run type checks\n```\n\n## Feature Backburner\n\n- Support implied types (type conversion currently depends on `cls.__annotations__`)\n\n## Extra\n\nPedantic note:\n\n> As in Smalltalk, classes themselves are objects. \n>\n> \u2014[The Literal Python Documentation](https://docs.python.org/3/tutorial/classes.html)\n",
    "bugtrack_url": null,
    "license": "AGPL-3.0-or-later",
    "summary": "Yet Another Python Envvar Config Object",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/turtlebasket/yapeco",
        "Repository": "https://github.com/turtlebasket/yapeco"
    },
    "split_keywords": [
        "python",
        "config",
        "environment",
        "dotenv",
        "variables"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "010a2bdc4ede2698e01476135593e88c11de5e928f3fed9f040de27942c65e8a",
                "md5": "a583a3c07f1e28e9ac169872c36a87cf",
                "sha256": "933d6b08fb244b1b4894d463f7293d8f4f79566381a75c2f5119c5541c0d88e5"
            },
            "downloads": -1,
            "filename": "yapeco-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a583a3c07f1e28e9ac169872c36a87cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 3048,
            "upload_time": "2023-11-23T02:16:34",
            "upload_time_iso_8601": "2023-11-23T02:16:34.275061Z",
            "url": "https://files.pythonhosted.org/packages/01/0a/2bdc4ede2698e01476135593e88c11de5e928f3fed9f040de27942c65e8a/yapeco-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a97189dec9b670ea4aaf5baf363b662c0b4c586f873b22c7bed904b55dd4eb93",
                "md5": "c6384d29ec17bf6c4e70d944d70a6c3e",
                "sha256": "c71a34e3c82c0d628f3ef3534024b1ac93402b9682ffe2bd11271b34eb90de26"
            },
            "downloads": -1,
            "filename": "yapeco-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c6384d29ec17bf6c4e70d944d70a6c3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 2784,
            "upload_time": "2023-11-23T02:16:35",
            "upload_time_iso_8601": "2023-11-23T02:16:35.834895Z",
            "url": "https://files.pythonhosted.org/packages/a9/71/89dec9b670ea4aaf5baf363b662c0b4c586f873b22c7bed904b55dd4eb93/yapeco-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-23 02:16:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "turtlebasket",
    "github_project": "yapeco",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yapeco"
}
        
Elapsed time: 0.14291s