{ "info": { "author": "Manuel Barkhau", "author_email": "mbarkhau@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Environment :: Other Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# [MyENV: Environment Variable Parsing using Type annotations][repo_ref]\n\nMyENV parses you're environment variables using type annotations.\nThis allows you to configure your app/service as layed out by\n[12factor.net/config](https://12factor.net/config), while keeping\nyour code type safe.\n\nProject/Repo:\n\n[![MIT License][license_img]][license_ref]\n[![Supported Python Versions][pyversions_img]][pyversions_ref]\n[![PyCalVer v201902.0007][version_img]][version_ref]\n[![PyPI Version][pypi_img]][pypi_ref]\n[![PyPI Downloads][downloads_img]][downloads_ref]\n\nCode Quality/CI:\n\n[![Build Status][build_img]][build_ref]\n[![Type Checked with mypy][mypy_img]][mypy_ref]\n[![Code Coverage][codecov_img]][codecov_ref]\n[![Code Style: sjfmt][style_img]][style_ref]\n\n\n| Name | role | since | until |\n|-------------------------------------|-------------------|---------|-------|\n| Manuel Barkhau (mbarkhau@gmail.com) | author/maintainer | 2018-09 | - |\n\n\n\n\n\n[](TOC)\n\n- [Environment Variables and Configuration](#environment-variables-and-configuration)\n - [Declaration](#declaration)\n - [Parsing](#parsing)\n- [my_service/cfg.py](#my_service-cfg-py)\n - [Config Files](#config-files)\n- [config/prod.env](#config-prod-env)\n\n[](TOC)\n\n## Environment Variables and Configuration\n\nIn order of priority, configuration is parsed from\n\n 1. Environment variables\n 2. Configuration files\n 3. Defaults defined in source code\n\n\n## Declaration\n\nThe `myenv` module provides a convenient way to do this parsing.\nAs far as your application code is concerned, it is enough to\ndeclare a subclass of `myenv.BaseEnv`. Instances of this\nsubclass are populated from config files and the environment.\n\n```python\nimport myenv\n\n\nclass Database(myenv.BaseEnv):\n\n _environ_prefix = \"DATABASE_\"\n\n vendor : str = \"postgres\"\n host : str = \"127.0.0.1\"\n port : int = 5432\n user : str = \"myuser\"\n password : str\n name : str = \"app_db_v1\"\n\n @property\n def url(self) -> str:\n db = self\n return f\"{db.vendor}://{db.user}:{db.password}@{db.host}:{db.port}/{db.name}\"\n```\n\nFor each annoatated member of `DBEnv` declare the 1. name, 2. type and\n3. an optional default variable. Members without a\ndefault must be set by an environment variable or configuration\nfile, otherwise a `KeyError` will be raised.\n\n\n## Parsing\n\nTo use the above configuration class, simply instanciate it.\n\n```python\n# my_service/cfg.py\nimport sqlalchemay as sqla\n\ndb_cfg = Database() # populated from os.environ\ndb_cfg.port # 12345 (parsed from DATABASE_PORT)\ndb_cfg.password # \"supersecret\" (parsed from DATABASE_PASSWORD)\ndb_cfg.url # \"mysql://myuser:supersecret@127.0.0.1:12345/mydb\"\n\nengine = sqla.create_engine(db_cfg.url)\n```\n\nIn case you're worried about the instantiation of `Database()`,\nit will return a singleton instance, so the `os.environ` and\nconfiguration files are parsed only once.\n\n\n## Config Files\n\nWhen parsing configs, the following paths are parsed if they\nexist. By default the configs are loaded from `${PWD}/config/`,\nbut you can override the location of configuration files by\nsetting the environment variable `ENV_CONFIG_DIR`.\n\n - `${ENV_CONFIG_DIR}/${ENV}.env`\n - `${ENV_CONFIG_DIR}/prod.env`\n\nAny variables defined in these files will be set, unless it was\nalready set in the environ or a previous config file.\n\nThis approach allows you to satisfy typical use cases in which a\nservice is hosted:\n\n 1. Development Machine\n 2. Stage/Production Environment\n\nYou can put use case specifc configuration files in your project\nsource tree, such as:\n\n - `project/config/dev.env`\n - `project/config/stage.env`\n - `project/config/prod.env`\n\nTo parse the appropriate config file, all you have to do is set a\nsingle environment variable `ENV=`. If `ENV` is not set,\nit will fall back to `ENV=prod`.\n\nThe `*.env` config files are flat text files, with one KEY=value\nmapping per line. The only lines which are parsed, are lines which\nbegin with an all upper case token, followed by an `=` character:\n\n```ini\n# config/prod.env\nDATABASE_PORT=12345\nDATABASE_USER=prod_user\nDATABASE_NAME=prod_db\nDATABASE_PASSWORD=supersecret\n```\n\nFor sensitive configuration parameters, such as passwords and\nauthentication tokens, you may prefer to write config files\noutside of your source tree, or to provide them always and only\nvia environment variables.\n\n\n\n[repo_ref]: https://gitlab.com/mbarkhau/myenv\n\n[build_img]: https://gitlab.com/mbarkhau/myenv/badges/master/pipeline.svg\n[build_ref]: https://gitlab.com/mbarkhau/myenv/pipelines\n\n[codecov_img]: https://gitlab.com/mbarkhau/myenv/badges/master/coverage.svg\n[codecov_ref]: https://mbarkhau.gitlab.io/myenv/cov\n\n[license_img]: https://img.shields.io/badge/License-MIT-blue.svg\n[license_ref]: https://gitlab.com/mbarkhau/myenv/blob/master/LICENSE\n\n[mypy_img]: https://img.shields.io/badge/mypy-checked-green.svg\n[mypy_ref]: https://mbarkhau.gitlab.io/myenv/mypycov\n\n[style_img]: https://img.shields.io/badge/code%20style-%20sjfmt-f71.svg\n[style_ref]: https://gitlab.com/mbarkhau/straitjacket/\n\n[pypi_img]: https://img.shields.io/badge/PyPI-wheels-green.svg\n[pypi_ref]: https://pypi.org/project/myenv/#files\n\n[downloads_img]: https://pepy.tech/badge/myenv/month\n[downloads_ref]: https://pepy.tech/project/myenv\n\n[version_img]: https://img.shields.io/static/v1.svg?label=PyCalVer&message=v201902.0007&color=blue\n[version_ref]: https://pypi.org/project/pycalver/\n\n[pyversions_img]: https://img.shields.io/pypi/pyversions/myenv.svg\n[pyversions_ref]: https://pypi.python.org/pypi/myenv\n\n\n\n# Changelog for https://gitlab.com/mbarkhau/myenv\n\n## v201902.0007\n\n - Packaging updates\n - Better test and mypy coverage\n\n\n## v201812.0005-beta\n\n - Add config parsing\n - Simplify instantiation (no need to import myenv to use subclasses)\n - Switch to https://gitlab.com/mbarkhau/myenv\n - Use https://gitlab.com/mbarkhau/bootstrapit\n\n\n## v201809.0001-beta\n\n - Initial release\n\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://gitlab.com/mbarkhau/myenv", "keywords": "environ variables mypy config configuration", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "myenv", "package_url": "https://pypi.org/project/myenv/", "platform": "", "project_url": "https://pypi.org/project/myenv/", "project_urls": { "Homepage": "https://gitlab.com/mbarkhau/myenv" }, "release_url": "https://pypi.org/project/myenv/201902.7/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Type safe environment variables parsing.", "version": "201902.7" }, "last_serial": 4860470, "releases": { "201809.1b0": [ { "comment_text": "", "digests": { "md5": "8ff5b8a79fc696320d6d67384f47364f", "sha256": "0ef35ccbefe83ce39250d1601cff06f05ef0a279f873cb737cca1c3b74b185fc" }, "downloads": -1, "filename": "myenv-201809.1b0-py36.py37-none-any.whl", "has_sig": false, "md5_digest": "8ff5b8a79fc696320d6d67384f47364f", "packagetype": "bdist_wheel", "python_version": "py36.py37", "requires_python": null, "size": 3397, "upload_time": "2018-09-07T22:43:04", "url": "https://files.pythonhosted.org/packages/73/6d/dba5a7bea1ff463ca7bc692a5eca37a2aa341e362a502f59144672d9d0b2/myenv-201809.1b0-py36.py37-none-any.whl" } ], "201812.3b3": [ { "comment_text": "", "digests": { "md5": "fd7d5b936a9ea2067a6b96b7fa82732f", "sha256": "cb78a17f2536eb1afef5ce4ffde8f42f7f31a791cd5b24342fc94326d91b1b84" }, "downloads": -1, "filename": "myenv-201812.3b3-py36.py37-none-any.whl", "has_sig": false, "md5_digest": "fd7d5b936a9ea2067a6b96b7fa82732f", "packagetype": "bdist_wheel", "python_version": "py36.py37", "requires_python": ">=3.6", "size": 7598, "upload_time": "2018-12-01T21:47:42", "url": "https://files.pythonhosted.org/packages/0d/4a/37e0fdfe00db385332ac2f9ee5772f9101d965992d3eb1271ef03fda5c7c/myenv-201812.3b3-py36.py37-none-any.whl" }, { "comment_text": "", "digests": { "md5": "db005f62ce0d5eb5bdac47ea966ad9ba", "sha256": "3da63e5584d4bf0dc916fafb3b36679cfeb507db942d59e647a47269bdf6a307" }, "downloads": -1, "filename": "myenv-201812.3b3.tar.gz", "has_sig": false, "md5_digest": "db005f62ce0d5eb5bdac47ea966ad9ba", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8685, "upload_time": "2018-12-01T21:47:43", "url": "https://files.pythonhosted.org/packages/80/a2/caaa464da1122905714b26e5429fca5b9beeab628f7b3698f95cf515b918/myenv-201812.3b3.tar.gz" } ], "201812.5b0": [ { "comment_text": "", "digests": { "md5": "b6042d17bbfd1da00df6bd27bd345180", "sha256": "65d48e7fede781ddd273fcfcb6430eb8dedb54ffb303c102da10981221f1ef96" }, "downloads": -1, "filename": "myenv-201812.5b0-py36.py37-none-any.whl", "has_sig": false, "md5_digest": "b6042d17bbfd1da00df6bd27bd345180", "packagetype": "bdist_wheel", "python_version": "py36.py37", "requires_python": ">=3.6", "size": 7613, "upload_time": "2018-12-09T17:58:08", "url": "https://files.pythonhosted.org/packages/fb/40/aae1517fe8d17856298c58ea0684733a76b628f936255862b015a0eeebad/myenv-201812.5b0-py36.py37-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1134340c85305a2d65f9824bc48cf314", "sha256": "d457f9a489c3ff1da5c39d90cbf21999df6afd6b266894a2c81e3f6ad7d9087f" }, "downloads": -1, "filename": "myenv-201812.5b0.tar.gz", "has_sig": false, "md5_digest": "1134340c85305a2d65f9824bc48cf314", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 10581, "upload_time": "2018-12-09T17:58:09", "url": "https://files.pythonhosted.org/packages/24/78/2ce25f59e9d50b3448379d119bfb575389eb9d7a39c0a55a1fd8352b9e0a/myenv-201812.5b0.tar.gz" } ], "201902.7": [ { "comment_text": "", "digests": { "md5": "4034a6cf114211aca9897f104be393e6", "sha256": "530cf9c08d4e7361421705143b02b527964386343777029c96c3163c87b3752f" }, "downloads": -1, "filename": "myenv-201902.7-py36.py37-none-any.whl", "has_sig": false, "md5_digest": "4034a6cf114211aca9897f104be393e6", "packagetype": "bdist_wheel", "python_version": "py36.py37", "requires_python": ">=3.6", "size": 8621, "upload_time": "2019-02-24T09:24:52", "url": "https://files.pythonhosted.org/packages/da/48/977e0e54ba6bfad865b6195026a0c2125b0bef022e10f1687662cd96bb32/myenv-201902.7-py36.py37-none-any.whl" }, { "comment_text": "", "digests": { "md5": "12cb17e7b8d4c01e21f5ed916d3c5e24", "sha256": "739c0ed411fc8a9c24b07f7834edcaaeeac994fff0e6da9d711d10e327225fef" }, "downloads": -1, "filename": "myenv-201902.7.tar.gz", "has_sig": false, "md5_digest": "12cb17e7b8d4c01e21f5ed916d3c5e24", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 10964, "upload_time": "2019-02-24T09:24:53", "url": "https://files.pythonhosted.org/packages/5a/86/daccc488c93c0a187da3dd929896c375b156ee8f25adb3c015d800e18a22/myenv-201902.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4034a6cf114211aca9897f104be393e6", "sha256": "530cf9c08d4e7361421705143b02b527964386343777029c96c3163c87b3752f" }, "downloads": -1, "filename": "myenv-201902.7-py36.py37-none-any.whl", "has_sig": false, "md5_digest": "4034a6cf114211aca9897f104be393e6", "packagetype": "bdist_wheel", "python_version": "py36.py37", "requires_python": ">=3.6", "size": 8621, "upload_time": "2019-02-24T09:24:52", "url": "https://files.pythonhosted.org/packages/da/48/977e0e54ba6bfad865b6195026a0c2125b0bef022e10f1687662cd96bb32/myenv-201902.7-py36.py37-none-any.whl" }, { "comment_text": "", "digests": { "md5": "12cb17e7b8d4c01e21f5ed916d3c5e24", "sha256": "739c0ed411fc8a9c24b07f7834edcaaeeac994fff0e6da9d711d10e327225fef" }, "downloads": -1, "filename": "myenv-201902.7.tar.gz", "has_sig": false, "md5_digest": "12cb17e7b8d4c01e21f5ed916d3c5e24", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 10964, "upload_time": "2019-02-24T09:24:53", "url": "https://files.pythonhosted.org/packages/5a/86/daccc488c93c0a187da3dd929896c375b156ee8f25adb3c015d800e18a22/myenv-201902.7.tar.gz" } ] }