{ "info": { "author": "Nic Kroeker", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Testing", "Topic :: Software Development :: Testing :: Acceptance" ], "description": "# e2e.env\n\n_Class-based modeling of environment variables and their type conversions._\n\nEspecially suited to test automation where environment variables are used in\nabundance, or even in applications that could benefit from these mappings.\n\n## Requirements\n\nFor ease of implementation, Python 3.6 is required in order to use\n[PEP-526](https://www.python.org/dev/peps/pep-0526/) variable\nannotations.\n\n## Overview\n\nEnvironment variable access is common, and usually done via a module-based\napproach.\n\n```python\nSERVICE_HOST = os.getenv('COMPANY_APP_HOST')\nSERVICE_PORT = int(os.getenv('COMPANY_APP_PORT'))\n```\n\nThis works just fine, but sometimes they need to be refreshed...\n\n```python\n# Whoops, forgot the int conversion!\nSERVICE_PORT = os.getenv('COMPANY_APP_PORT')\n```\n\n... which isn't very [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself).\n\nAdditionally, you may sometimes need to keep track of the name _and_ the value from the environment,\n\n```python\n# This is getting verbose quickly\nENVNAME_SERVICE_HOST = 'COMPANY_APP_HOST'\nSERVICE_HOST = os.getenv(ENVNAME_SERVICE_HOST)\nENVNAME_SERVICE_PORT = 'COMPANY_APP_PORT'\nSERVICE_PORT = int(os.getenv(ENVNAME_SERVICE_PORT))\n```\n\nIn one swoop, we can map the environment variables as well as their\nconversions to native types, and fetch either the value or the name:\n\n```python\nclass ServiceVars(e2e.env.EnvMapper):\n host: str = 'COMPANY_APP_HOST'\n port: int = 'COMPANY_APP_PORT'\n\n# Get the port via instance\nprint(ServiceVars().port) # 8080\ntype(ServiceVars().port) # \n\n# Get the name of the port environment variable via class\nprint(ServiceVars.port) # COMPANY_APP_PORT\ntype(ServiceVars.port) # \n```\n\n## Using your own \"converters\"\n\nAll `EnvMapper` does is read the type annotation and constructs the returned\nvalue by passing the environment value to it.\n\nThat is, when modeling,\n```python\n mapped_name: annotated_type = 'ENV_VAR_NAME'\n```\n... on access via the `EnvMapper` instance, becomes ...\n```python\n annotated_type(os.getenv('ENV_VAR_NAME'))\n```\n\nIn the above examples for example, we had `port: int = 'COMPANY_APP_PORT'`.\nThis essentially gets shuffled into `int(os.getenv('COMPANY_APP_PORT'))`. So\nany callable that can take a single `str` in its constructor and return the\nappropriate type will work.\n\n## Production use\n\nThe code is incredibly simple, and will adhere to these contracts:\n\n- Variables that do not exist will cause a\n `e2e.env.exceptions.NoSuchVariableError` to be raised.\\*\n- Access of an unmapped environment variable will raise an `AttributeError`, as\n would be reasonably expected.\n- Access of a mapping without an annotation will raise a `TypeError` with the\n mapping name and model class.\n\n\\* Open for discussion. Returning `None` could work. Passing `None` to the type\nconverter usually won't produce consistent behaviour across types, and so can't\nbe determined as a special case (e.g. `str(None)` gives `\"None\"`, `int(None)`\nraises a `TypeError`). See\n[Issue #1](https://github.com/nickroeker/e2e.env/issues/1) for more info.\n\n## Future work\n\n- Support `raise_on_dne` or something similar to change what happens when an\n environment variable is not found. Please add a thumbs-up for\n [Issue #1](https://github.com/nickroeker/e2e.env/issues/1) if you'd like to\n see this feature.\n ```python\n class ServiceVars(e2e.env.EnvMapper, raise_on_dne=False): ...\n ```\n ```python\n class ServiceVars(e2e.env.EnvMapper, dne=lambda: None): ...\n ```\n- Support for combining mappings into one larger mapping, for organizational\n purposes. Please add a thumbs-up for\n [Issue #2](https://github.com/nickroeker/e2e.env/issues/2) if you'd like to\n see this feature.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nickroeker/e2e.env", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "e2e.env", "package_url": "https://pypi.org/project/e2e.env/", "platform": "", "project_url": "https://pypi.org/project/e2e.env/", "project_urls": { "Homepage": "https://github.com/nickroeker/e2e.env" }, "release_url": "https://pypi.org/project/e2e.env/0.1.0/", "requires_dist": [ "tox ; extra == 'dev'", "pytest ; extra == 'dev'" ], "requires_python": "", "summary": "Easily model and convert environment variables you care about.", "version": "0.1.0" }, "last_serial": 4809764, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "088d76a809a2d09d6c2949ff3f9684e2", "sha256": "959ce98fb85b774c39254b96054c6d9b018ca38bc4ca42140f8dcbd8508517e9" }, "downloads": -1, "filename": "e2e.env-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "088d76a809a2d09d6c2949ff3f9684e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4459, "upload_time": "2019-02-12T09:07:20", "url": "https://files.pythonhosted.org/packages/67/09/88a146f5717d4f0eb898fb98bfc5e9b34fd9383b24f4edb43887d31d5528/e2e.env-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2070dbdc3032bb7d73fd1f103ac04b18", "sha256": "6e0eb457e1459a023ad304ef3489492558d87b3343628ee28bdc409008e12720" }, "downloads": -1, "filename": "e2e.env-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2070dbdc3032bb7d73fd1f103ac04b18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4389, "upload_time": "2019-02-12T09:07:22", "url": "https://files.pythonhosted.org/packages/b8/04/585e0b73a5abdc71a54e304a406aeb3d7b225ec16d2053018a2e33723d97/e2e.env-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "088d76a809a2d09d6c2949ff3f9684e2", "sha256": "959ce98fb85b774c39254b96054c6d9b018ca38bc4ca42140f8dcbd8508517e9" }, "downloads": -1, "filename": "e2e.env-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "088d76a809a2d09d6c2949ff3f9684e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4459, "upload_time": "2019-02-12T09:07:20", "url": "https://files.pythonhosted.org/packages/67/09/88a146f5717d4f0eb898fb98bfc5e9b34fd9383b24f4edb43887d31d5528/e2e.env-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2070dbdc3032bb7d73fd1f103ac04b18", "sha256": "6e0eb457e1459a023ad304ef3489492558d87b3343628ee28bdc409008e12720" }, "downloads": -1, "filename": "e2e.env-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2070dbdc3032bb7d73fd1f103ac04b18", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4389, "upload_time": "2019-02-12T09:07:22", "url": "https://files.pythonhosted.org/packages/b8/04/585e0b73a5abdc71a54e304a406aeb3d7b225ec16d2053018a2e33723d97/e2e.env-0.1.0.tar.gz" } ] }