{ "info": { "author": "chkap", "author_email": "d47bc0@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# jcfg\n\njcfg is an easy-to-use json-based configuration tool for building python programs.\n\nSuppose that you want to develop an program that has three config options: a file path (type of string), an integer (type of int), and a float number. And also want to be able to load configs from a local file. Then, you can write code like this, with jcfg:\n\n```python\n# in file: my_program.py\nfrom jcfg import JsonCfg\n\ndef main():\n cfg = JsonCfg({\n 'input_path': '',\n 'input_int': 0,\n 'input_float': 0.0\n })\n cfg.parse_args()\n\n # do any work you want below\n # you can get the input_path, input_int, or input_float like this:\n\n res = cfg.input_int + cfg.input_float\n # `cfg.input_int` and `cfg.input_float` will get the actual value depending on the cli input. jcfg have done the type check work for you. If the input option cannot be parsed as an integer, it will raise error\n\n ....\n\nif __name__ == '__main__':\n main()\n\n```\n\nType `python3 my_program.py -h` in your terminal, you will get:\n```bash\nusage: test_readme.py [-h] [-c CONFIG_PATH] [--input_float INPUT_FLOAT]\n [--input_int INPUT_INT] [--input_path INPUT_PATH]\n\noptional arguments:\n -h, --help show this help message and exit\n -c CONFIG_PATH file path to update config\n --input_float INPUT_FLOAT\n type: , default: 0.0\n --input_int INPUT_INT\n type: , default: 0\n --input_path INPUT_PATH\n type: , default:\n```\n\nAs you can see above, these config options can be loaded from either cli input or a json file with cli option `-c your_config.json`. \n\n# Usage\n\n## To define config options\n\nThe config options should be defined based on the dict object provided when constructing `JsonCfg`. Each key in the dict will be the name of an config option, and the corresponding value will be either the default value for this config or a sub-config under this key name, based on:\n\n1. if the value is a dict without the key `_default`, this value will define a sub-config under this key,\n2. otherwise, the value indicates the default value (and also some other meta info) for this key. The type of this config will be implicitly determined as the type of the default value. \n\nFor better understanding, here is an example:\n\n```python\ncfg = jcfg.JsonCfg({\n 'option_int': -1, # this define an config option with name `option_int` with default value of -1, and also with type of int (type(-1) is int).\n 'option_float': 0.0, # this define config `option_float`, with default value 0.0, and type of float.\n 'option_str': 'default_value', # default value: 'default_value', with type str\n 'option_list': [], # this defins an config with default value of empty list, of type list\n 'sub_config': { # this will define and sub-config\n 'sub_int': 0,\n 'sub_float': 0.0,\n 'sub_sub_config': { # sub-config can be recursively defined\n 'leaf_key': 0, \n }\n },\n 'not_sub_config': { # however, this won't define a sub-config, but an config with value type: string\n '_default': 'this_is_default_value', \n '_desc': 'this_si_description', # this will provide detailed description for this config when typing --help\n },\n 'option_by_tuple': (2, 'this is a description'), # this option is defined with a 2-size tuple, the 1st is default value, 2rd is description\n 'option_by_tuple_3': (0.0, 'this is a description', lambda x: x>=0.0), # this option is defined with a 3-size tuple, the 3rd is to validate the value.\n})\n```\n\nThe config option value currently only supports following types:\n- int\n- float\n- str\n- list\n\nNote that, if you want a config option with type of dict, you'd better define it as an 2-size list, then parse this option as dict in your code yourself.\n\n## To load configs from cli\n\nAll config options could be overrided from cli with the corresponding config key name. For sub-config, the config key name is defined by all the config key name between root config and leaf config. Here is an example to override the sub-config value:\n\n```bash\npython3 test.py --sub_config.sub_int 2\n```\n\n## To load configs from file\n\nAll configs can also be loaded from a **json** file with a more tolerant json loader: [jstyleson](https://github.com/linjackson78/jstyleson), which supports js-style comments and also allows trailing comma, or from **yaml** file. Here is an examples of loading from json:\n\n```json\n\\\\ config.json\n/* js-style comments supported!\n*/\n{\n \"option_str\": \"new_string\", // in-line comments supported!\n \"sub_config\":{\n \"sub_int\": 1, // trailing comma allowed\n },\n \"sub_config.sub_float\": 3\n}\n```\nThese config can be updated by `python3 test.py -c config.json`.\n\nNote that, sub-config value can be defined as a dict or key-value pair with full config path, like above.\n\nIf both config file and cli option are provided, the config will be **first overrided from config file, then overrided from cli options**.\n\n## Access to configs.\n\nThe configs can be easily accessed like this:\n```python\ncfg.option_int # or \ncfg['option_int']\n\n# for sub-config\ncfg.sub_config.sub_int # or\ncfg['sub_config']['sub_int'] # or\ncfg['sub_config.sub_int']\n```\n\n# Other features\n\n* Config key startswith `_` denotes private config options, which will never be overrided from cli or file.\n* '_default' is the reserved key, you should never define a config with key name '_default'.\n* '_desc' is another reserved key for defining cli description of config key\n* Some other reserved key startswith `_` may be added someday, to provide more advanced meta control.\n\n# Test\n\nRun `cd test; python3 test_main.py -v`.\n\n\n\n\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://github.com/chkap/jcfg", "keywords": "", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "jcfg", "package_url": "https://pypi.org/project/jcfg/", "platform": "", "project_url": "https://pypi.org/project/jcfg/", "project_urls": { "Homepage": "https://github.com/chkap/jcfg" }, "release_url": "https://pypi.org/project/jcfg/0.10.2/", "requires_dist": [ "jstyleson", "pyyaml" ], "requires_python": "", "summary": "A json-based configuration helper lib for python", "version": "0.10.2", "yanked": false, "yanked_reason": null }, "last_serial": 8086494, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "2f43cd2cb1cf3cf85482245fcf81a424", "sha256": "fc51c06e6b70f55080bb43eae1119cf5f7ff0ed3f091f47fc4925f6607385eca" }, "downloads": -1, "filename": "jcfg-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "2f43cd2cb1cf3cf85482245fcf81a424", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5795, "upload_time": "2018-11-29T14:04:25", "upload_time_iso_8601": "2018-11-29T14:04:25.727992Z", "url": "https://files.pythonhosted.org/packages/08/f3/8351074de894bac624374c562426a381d33244c70b9c395fd4255ccacd74/jcfg-0.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "c0affb9216ad51edc74b4f7b6c8e46f5", "sha256": "ee470accd87d466c5ce57580980bbcc6bba9c055b66ee45214bd158373d8cd76" }, "downloads": -1, "filename": "jcfg-0.1.tar.gz", "has_sig": false, "md5_digest": "c0affb9216ad51edc74b4f7b6c8e46f5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2681, "upload_time": "2018-11-29T14:04:27", "upload_time_iso_8601": "2018-11-29T14:04:27.995013Z", "url": "https://files.pythonhosted.org/packages/02/f2/9198d88e6c1d9b960a8fccb7f0b96b98c548bf54ab80c1b7894ec2fecfac/jcfg-0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "a43aed2f7a78cc5126349bc9caa1051a", "sha256": "6d9cb0f9d56554ea3e7afdfc5c9b8a32e679130f9e89c5a52431083211ab7ce1" }, "downloads": -1, "filename": "jcfg-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a43aed2f7a78cc5126349bc9caa1051a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6372, "upload_time": "2018-12-14T15:15:21", "upload_time_iso_8601": "2018-12-14T15:15:21.444349Z", "url": "https://files.pythonhosted.org/packages/60/8d/9f23de9c58480a6dc803a416cdd5eb572d6f5218e0c6e14caeb0750be14f/jcfg-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.10.0": [ { "comment_text": "", "digests": { "md5": "04a72f62cdc08841c66257ef495add78", "sha256": "11fbe2625dc87c5b97e31a361773684ee15b816725a00cd0ec04070147c0b0b8" }, "downloads": -1, "filename": "jcfg-0.10.0-py3-none-any.whl", "has_sig": false, "md5_digest": "04a72f62cdc08841c66257ef495add78", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7816, "upload_time": "2020-07-25T16:17:47", "upload_time_iso_8601": "2020-07-25T16:17:47.053596Z", "url": "https://files.pythonhosted.org/packages/bb/f5/a778d7f5ffce1d8ddcc301795f4cafdedab9ee4821dc9320c4030c29b0a0/jcfg-0.10.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.10.1": [ { "comment_text": "", "digests": { "md5": "85d66c3f9f87fbb42df1e53e0d9f4c55", "sha256": "27a4f1f74fc3d3065916d44572ba5a8a93d4c13c2472ee50a5500c5fe656959b" }, "downloads": -1, "filename": "jcfg-0.10.1-py3-none-any.whl", "has_sig": false, "md5_digest": "85d66c3f9f87fbb42df1e53e0d9f4c55", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7820, "upload_time": "2020-07-25T17:24:38", "upload_time_iso_8601": "2020-07-25T17:24:38.877865Z", "url": "https://files.pythonhosted.org/packages/9d/26/b343e0a77a982ee9e032b0ee8f406184ccc8e8136c7a19271aef4cb77a50/jcfg-0.10.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.10.2": [ { "comment_text": "", "digests": { "md5": "32f080a63fdb45a35d3f00d37367c7c8", "sha256": "9563ccc84633a29d1127ddd20139702c38ee659ce00235d4da5b7b8f865edc9a" }, "downloads": -1, "filename": "jcfg-0.10.2-py3-none-any.whl", "has_sig": false, "md5_digest": "32f080a63fdb45a35d3f00d37367c7c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7826, "upload_time": "2020-09-01T14:46:17", "upload_time_iso_8601": "2020-09-01T14:46:17.314386Z", "url": "https://files.pythonhosted.org/packages/33/ba/b54c607f2d20a5389b38e27e5bb6a7e40bd817e96f92b378248c00d794e5/jcfg-0.10.2-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "a2869974dfb19a172d20257b671e823a", "sha256": "5acc80c9412701b1165197a199227fca70d371b0cdb7b2af32179ae6da885557" }, "downloads": -1, "filename": "jcfg-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a2869974dfb19a172d20257b671e823a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6345, "upload_time": "2018-12-15T01:20:40", "upload_time_iso_8601": "2018-12-15T01:20:40.985115Z", "url": "https://files.pythonhosted.org/packages/de/10/6bbc33c46bcdd7e327766657cc80dfe66a33e2de74dbde091ff1abbe63c4/jcfg-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "40a7cd7fd2492577073ad4692884f44f", "sha256": "a97e80dbdc41bc4273bf05280fe4f7cb8c1202b44c91a3b70725a589ffa4d8a1" }, "downloads": -1, "filename": "jcfg-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "40a7cd7fd2492577073ad4692884f44f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6495, "upload_time": "2018-12-19T00:38:53", "upload_time_iso_8601": "2018-12-19T00:38:53.942863Z", "url": "https://files.pythonhosted.org/packages/ad/8d/7d1c3e6e7777df72c28f0e965100dec85df79387c52bf33cde6e34a9e851/jcfg-0.3.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "bbd82bddfdffa0b463d47c43d271ed1a", "sha256": "f17f26fe0bd751255171df8e013ad1aba8a3c9b0f948e0722a2e1a6a02c05f99" }, "downloads": -1, "filename": "jcfg-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "bbd82bddfdffa0b463d47c43d271ed1a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6611, "upload_time": "2018-12-23T15:42:51", "upload_time_iso_8601": "2018-12-23T15:42:51.577919Z", "url": "https://files.pythonhosted.org/packages/97/bc/a93505ffee69dd9617e80f506d77f04b73ec36759da19715fa40d4b7945c/jcfg-0.4.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "f70d2cc4c414ee02301be028de562c19", "sha256": "b6e4f9e26009ffb6eb501ec682ce24e91cb12e3c2c8dd4f65deee6794137b04b" }, "downloads": -1, "filename": "jcfg-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f70d2cc4c414ee02301be028de562c19", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6609, "upload_time": "2019-01-19T15:02:45", "upload_time_iso_8601": "2019-01-19T15:02:45.057222Z", "url": "https://files.pythonhosted.org/packages/b1/f3/975e833daa1918f5bc797cf2a1bce80d6003795fb8b8c46e2fc8e4b43b5e/jcfg-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "00fa3b289214eca4cf5891b45236ca32", "sha256": "747832caa2499ae7a1fac5e390a6d469c44c6cded655ed4462cdb844ec3d8cc0" }, "downloads": -1, "filename": "jcfg-0.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "00fa3b289214eca4cf5891b45236ca32", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5125, "upload_time": "2019-05-20T15:22:17", "upload_time_iso_8601": "2019-05-20T15:22:17.125284Z", "url": "https://files.pythonhosted.org/packages/37/2c/1b44ff07cfd05b1c936bb75aba3eaca136fc9128197833656a2ffe173779/jcfg-0.5.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "b6264687ba9585a75ae1b774ff219334", "sha256": "ab72dbc5f57f1b343b51afbab5dcbcff9c61c9c58c88aac969858316e4ad51ed" }, "downloads": -1, "filename": "jcfg-0.6.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b6264687ba9585a75ae1b774ff219334", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6915, "upload_time": "2019-10-24T16:48:41", "upload_time_iso_8601": "2019-10-24T16:48:41.357173Z", "url": "https://files.pythonhosted.org/packages/9b/74/c4aea58f375498c9b7fafb6020161aff8227aa7d3270bc80186f9e0587a3/jcfg-0.6.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "071d1ae368c3137d61979aa908a1fa0f", "sha256": "23bfb071d0f6caf9435dafe17d96ec8b8e72c51225f7b4b1e95adfbeab30b0a6" }, "downloads": -1, "filename": "jcfg-0.7.0-py3-none-any.whl", "has_sig": false, "md5_digest": "071d1ae368c3137d61979aa908a1fa0f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7061, "upload_time": "2020-04-03T20:00:26", "upload_time_iso_8601": "2020-04-03T20:00:26.079709Z", "url": "https://files.pythonhosted.org/packages/c4/e4/ca6dc8c606f989927e79da65e076786ddd1d6a00b656647c029f05108f04/jcfg-0.7.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.8.0": [ { "comment_text": "", "digests": { "md5": "c79912f8aaf55fc8249afb286e19d768", "sha256": "6030b005ee17e2e43b8d10be19951d287208a80befe4c8e88b295859814a770b" }, "downloads": -1, "filename": "jcfg-0.8.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c79912f8aaf55fc8249afb286e19d768", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10223, "upload_time": "2020-04-04T07:33:06", "upload_time_iso_8601": "2020-04-04T07:33:06.842640Z", "url": "https://files.pythonhosted.org/packages/0d/77/2b0ce7b8d53024cb7a013ac289311bfe625a800dc302fa5fc61636bfa62e/jcfg-0.8.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "b75b1669a94dca58d824ac8809ca6b8d", "sha256": "ca7fd5cb70be1c2c4c4f111b392f304d34c151f6e225d3e02e4c3e27520e2f73" }, "downloads": -1, "filename": "jcfg-0.9.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b75b1669a94dca58d824ac8809ca6b8d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7693, "upload_time": "2020-07-25T13:22:30", "upload_time_iso_8601": "2020-07-25T13:22:30.562777Z", "url": "https://files.pythonhosted.org/packages/b3/0f/769352434b8e89dc92bc94ff5832f3673053e29452ccacecae403932743d/jcfg-0.9.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "32f080a63fdb45a35d3f00d37367c7c8", "sha256": "9563ccc84633a29d1127ddd20139702c38ee659ce00235d4da5b7b8f865edc9a" }, "downloads": -1, "filename": "jcfg-0.10.2-py3-none-any.whl", "has_sig": false, "md5_digest": "32f080a63fdb45a35d3f00d37367c7c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7826, "upload_time": "2020-09-01T14:46:17", "upload_time_iso_8601": "2020-09-01T14:46:17.314386Z", "url": "https://files.pythonhosted.org/packages/33/ba/b54c607f2d20a5389b38e27e5bb6a7e40bd817e96f92b378248c00d794e5/jcfg-0.10.2-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }