{ "info": { "author": "Cromefire_", "author_email": "tim.langhorst@outlook.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development", "Typing :: Typed" ], "description": "# Schema config\n[![PyPI](https://img.shields.io/pypi/v/schema-config.svg?logo=python&logoColor=dddddd)](https://pypi.org/project/schema-config/)\n[![GitLab](https://img.shields.io/badge/GitLab-source_code-orange.svg?logo=gitlab)](https://gitlab.com/cromefire_/schema-config)\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/schema-config.svg?logo=python&logoColor=dddddd)](https://pypi.org/project/schema-config/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/schema-config.svg?logo=python&logoColor=dddddd)](https://pypi.org/project/schema-config/)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/schema-config.svg?logo=python&logoColor=dddddd)](https://pypi.org/project/schema-config/)\n[![PyPI - Status](https://img.shields.io/pypi/status/schema-config.svg)](https://pypi.org/project/schema-config/)\n\n\n\n- [Install](#install)\n- [Usage](#usage)\n * [Loading a configuration](#loading-a-configuration)\n * [Specifying a configuration schema](#specifying-a-configuration-schema)\n * [Configuring your program](#configuring-your-program)\n * [The `Configurator` class](#the-configurator-class)\n + [Creation](#creation)\n + [Adding files](#adding-files)\n + [Getting the configuration](#getting-the-configuration)\n * [The `Configuration` class](#the-configuration-class)\n + [Getting items](#getting-items)\n + [Checking for items](#checking-for-items)\n + [Setting items](#setting-items)\n + [Other useful abilities](#other-useful-abilities)\n- [Issues & Suggestions](#issues--suggestions)\n\n\n\n## Install\n\nRequires CPython/PyPy 3.6 minimum\n\n```bash\npip3 install schema-config~=[version]\n```\n\n_Warning: In this early versions (0.X.Y) minor versions may introduce major breaking changes!_\n\n## Usage\n### Loading a configuration\n```python\nfrom pkg_resources import resource_string\nfrom os import environ\n\nfrom schema_config import Configurator\n\nschema: bytes = resource_string(__name__, \"config.schema.json\")\nfactory: Configurator = Configurator.from_string(schema)\n\n# The order is important, the first file will be loaded\nif \"CONFIG\" in environ:\n # loads the configuration from a yaml file (typings come from YAML)\n factory.add_file(environ[\"CONFIG\"])\nelse:\n # Search for your programm's configurations\n factory.add_file(\"/etc/programm/config.yaml\")\n factory.add_file(\"./programm.yaml\")\n\n# Get your configuration object\ncfg = factory.load_config()\n```\n\n### Specifying a configuration schema\nschema-config is configured using [jsonschema](https://json-schema.org). \n\nA possible schema could be:\n```json\n{\n \"$schema\": \"http://json-schema.org/draft-04/schema\",\n \"properties\": {\n \"database\": {\n \"type\": \"object\",\n \"properties\": {\n \"host\": {\n \"type\": \"string\"\n },\n \"port\": {\n \"type\": \"number\"\n },\n \"password\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"host\"]\n }\n },\n \"required\": [\"database\"]\n}\n```\n\n### Configuring your program\nWith the examples above a user could configure the program like this:\n`/etc/program/config.yaml`:\n```yaml\ndatabase:\n host: \"example.com\"\n port: $json{DB_PORT}\n password: $string{DB_PASSWORD}\n```\nWith an environment variable (currently quotes are needed):\n```bash\nDB_PORT=\"9999\"\nDB_PASSWORD=\"test\"\n```\n\nBoth would be merged in a `Configuration` object similar to:\n```json\n{\n \"database\": {\n \"host\": \"example.com\",\n \"port\": 9999,\n \"password\": \"test\"\n }\n}\n```\n\n### The `Configurator` class\n#### Creation\nFrom a file\n``` python\nfactory = Configurator.from_file(\"\")\n```\n\nFrom a string\n``` python\nfactory = Configurator.from_string(\"\")\n```\n\nFrom a dict\n``` python\nfactory = Configurator(json_schema_as_a_dict)\n```\n\n#### Adding files\n``` python\nfactory.add_file(\"\")\n```\n\n_Warning: The order is important! The first one will be loaded_\n\n#### Getting the configuration\n``` python\ncfg = factory.load_config() # type: Configuration\n```\n\n### The `Configuration` class\nThe `Configuration` class is something like an easier `dict`.\n\n#### Getting items\nWith `KeyError` if not available\n``` python\ndatabase = cfg[\"database\"]\nhost = cfg[\"database.host\"]\n```\n\nWith default:\n``` python\nhost = cfg.get(\"database.host\", \"localhost\")\npassword = cfg.get(\"database.password\") # Default: None\n```\n\n#### Checking for items\n``` python\ncfg.has(\"database.host\")\n\"database.host\" in cfg\n```\n\n#### Setting items\n``` python\ncfg[\"database\"] = {\"host\": \"example.com\"}\ncfg[\"database.host\"] = \"example.com\"\n```\n\n#### Other useful abilities\nCreating a new Configuration\n``` python\ncfg = Configuration(some_dict)\n```\n\nGetting a dict out of it\n``` python\ndict_cfg = cfg.raw\n```\n\n## Issues & Suggestions\nIf you have any issues, suggestions, licensing problems, etc. just open an issue in [the gitlab repo](https://gitlab.com/cromefire_/schema-config)\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/cromefire_/schema-config", "keywords": "", "license": "MPL-2.0", "maintainer": "", "maintainer_email": "", "name": "schema-config", "package_url": "https://pypi.org/project/schema-config/", "platform": "", "project_url": "https://pypi.org/project/schema-config/", "project_urls": { "Bug Tracker": "https://gitlab.com/cromefire_/schema-config/issues", "Documentation": "https://gitlab.com/cromefire_/schema-config", "Homepage": "https://gitlab.com/cromefire_/schema-config", "Source Code": "https://gitlab.com/cromefire_/schema-config" }, "release_url": "https://pypi.org/project/schema-config/0.3.0/", "requires_dist": [ "attrs (==19.1.0)", "deepmerge (==0.0.5)", "jsonschema (==3.0.2)", "pyrsistent (==0.15.4)", "pyyaml (==5.1.2)", "six (==1.12.0)" ], "requires_python": "", "summary": "Load and validate configurations using jsonschema", "version": "0.3.0" }, "last_serial": 5722686, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "42bd63d3381633e3cbce75f7ada17be4", "sha256": "d7ca36ca8905daae18fe49bac0557ee97ccf1584a55e680351c10d195d57236a" }, "downloads": -1, "filename": "schema_config-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "42bd63d3381633e3cbce75f7ada17be4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3793, "upload_time": "2019-04-07T19:16:33", "url": "https://files.pythonhosted.org/packages/9b/53/5916605e1f0a85025d3a45b86d0098540d6082b9b89c992ea37aacaebdaa/schema_config-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a61ae5f27038f40c7919530aa10ef4a", "sha256": "af713d7d73b74650bd85ef185ba5f24fc20ebecb71f71cf6604606853c73a709" }, "downloads": -1, "filename": "schema_config-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3a61ae5f27038f40c7919530aa10ef4a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2957, "upload_time": "2019-04-07T19:16:34", "url": "https://files.pythonhosted.org/packages/2d/76/9912ec6b8b250fd65dab6ec8660e345a211629fc575a027f13ce607e6c02/schema_config-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "2dced5a85deedb1e0249a06350348113", "sha256": "4f9ec57bb3c8bbb08c8f16632a844629aefb6ebaf21ea68a7df80ab22dfdba26" }, "downloads": -1, "filename": "schema_config-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2dced5a85deedb1e0249a06350348113", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3994, "upload_time": "2019-04-08T08:16:39", "url": "https://files.pythonhosted.org/packages/f8/0c/c2f84ecc092a8c999288a8b5e2e8225b3a1cde4044fc5fcac91e62f2899a/schema_config-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "36cb55572f2c23b7b00392f361ffb300", "sha256": "9b5f8849e12fd1264befc1253ac3dd9d0d45679576437cd18fcdf8606f42a418" }, "downloads": -1, "filename": "schema_config-0.1.0.tar.gz", "has_sig": false, "md5_digest": "36cb55572f2c23b7b00392f361ffb300", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3167, "upload_time": "2019-04-08T08:16:40", "url": "https://files.pythonhosted.org/packages/01/7d/c81786c232e017f1c83f6f4efe8cfd9f7e2d514cd32ea02daab932baa118/schema_config-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "56c14c1617e67f4d7acc0aa53e5afecf", "sha256": "bf55ae3dcdd2d86bd17b326ee29c6522622572135703529fb11155b83d2381ce" }, "downloads": -1, "filename": "schema_config-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "56c14c1617e67f4d7acc0aa53e5afecf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3994, "upload_time": "2019-04-08T12:05:22", "url": "https://files.pythonhosted.org/packages/7b/17/0db02afc09a2e5497c558caeba17870c6cf2a91932e8876f30e56cfb2a90/schema_config-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ed68da2294243ef2a704b82156fa0796", "sha256": "32ce3a5034bca549cbd8cd2c9830006fe6b1f3a5c5daece58beb45c0ca07975e" }, "downloads": -1, "filename": "schema_config-0.1.1.tar.gz", "has_sig": false, "md5_digest": "ed68da2294243ef2a704b82156fa0796", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3169, "upload_time": "2019-04-08T12:05:23", "url": "https://files.pythonhosted.org/packages/a0/5b/43c063e38503c3e782ab6f059e057a44afb4fb09d9297b43757c883c5a43/schema_config-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "53c0561852a7b151431dfc4be929f71b", "sha256": "fc774692537a5cfc8c48ef7ecf1c7efe023e05a0310d2021ada0fc6de488c57f" }, "downloads": -1, "filename": "schema_config-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "53c0561852a7b151431dfc4be929f71b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5873, "upload_time": "2019-06-03T20:36:43", "url": "https://files.pythonhosted.org/packages/58/5b/cb2cc1b01483712956a5829386638cdd16580f6491f907bf1cd42ff6108b/schema_config-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e6f05acee25c1b9b716693e39b4fba8e", "sha256": "a7144b62c8368f709d70ba60c6bf8dfc55e9c196f8f25cbe1e735159c95778e5" }, "downloads": -1, "filename": "schema-config-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e6f05acee25c1b9b716693e39b4fba8e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5682, "upload_time": "2019-06-03T20:36:44", "url": "https://files.pythonhosted.org/packages/7f/b4/a9494dc4469f10a38f92f19b124a84b0cf134b547c7494d7a8bf775d0fad/schema-config-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "9c37cfdc40fc44a4031369f8eb8a5172", "sha256": "94b54aff189f4d115a4139a49aad35970c6fe673828d6d661dd41b20c81afc45" }, "downloads": -1, "filename": "schema_config-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9c37cfdc40fc44a4031369f8eb8a5172", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5935, "upload_time": "2019-06-06T13:30:10", "url": "https://files.pythonhosted.org/packages/79/3a/46c0046250ac02fb1f38f98eac3d5dca95b7dca1f3565e7ba13fc6658825/schema_config-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9acd2de049b297f8f111c886ba6ce4b7", "sha256": "0b33af9ec3dc205fef80f6d60a1f062f5b44b576759e5687ea772f7fc7b71562" }, "downloads": -1, "filename": "schema-config-0.2.1.tar.gz", "has_sig": false, "md5_digest": "9acd2de049b297f8f111c886ba6ce4b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5752, "upload_time": "2019-06-06T13:30:12", "url": "https://files.pythonhosted.org/packages/85/82/8bc58893788c0e4358d4182d357072517e32458e938e67234659be7b1468/schema-config-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "d9580a15de881b355c75998132086104", "sha256": "124e3bae84be148c38c2f50fe8ee53f46df428317990576fde4b94ea07b54fc9" }, "downloads": -1, "filename": "schema_config-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d9580a15de881b355c75998132086104", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5031, "upload_time": "2019-08-23T20:32:50", "url": "https://files.pythonhosted.org/packages/0d/54/d25a6df71d546d14cf20aed7094f930c43e1749691f9fda9fb584d084824/schema_config-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "15838a6912cba9ec67373e3326071e64", "sha256": "eab25329ecc9309f9d7cee11ceae2d6999a3c2b60e19043b4324d43fddb13335" }, "downloads": -1, "filename": "schema-config-0.3.0.tar.gz", "has_sig": false, "md5_digest": "15838a6912cba9ec67373e3326071e64", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5214, "upload_time": "2019-08-23T20:32:53", "url": "https://files.pythonhosted.org/packages/bc/b4/f2dfd566ab849614b82bde199851628cae6c7cc7b56a4c6f08636913501d/schema-config-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d9580a15de881b355c75998132086104", "sha256": "124e3bae84be148c38c2f50fe8ee53f46df428317990576fde4b94ea07b54fc9" }, "downloads": -1, "filename": "schema_config-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d9580a15de881b355c75998132086104", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5031, "upload_time": "2019-08-23T20:32:50", "url": "https://files.pythonhosted.org/packages/0d/54/d25a6df71d546d14cf20aed7094f930c43e1749691f9fda9fb584d084824/schema_config-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "15838a6912cba9ec67373e3326071e64", "sha256": "eab25329ecc9309f9d7cee11ceae2d6999a3c2b60e19043b4324d43fddb13335" }, "downloads": -1, "filename": "schema-config-0.3.0.tar.gz", "has_sig": false, "md5_digest": "15838a6912cba9ec67373e3326071e64", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5214, "upload_time": "2019-08-23T20:32:53", "url": "https://files.pythonhosted.org/packages/bc/b4/f2dfd566ab849614b82bde199851628cae6c7cc7b56a4c6f08636913501d/schema-config-0.3.0.tar.gz" } ] }