{ "info": { "author": "Kevin Conway", "author_email": "kevinjacobconway@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "======\nconfpy\n======\n\n**Config file parsing and option management.**\n\nProject Status\n==============\n\n**Consider this project to be in maintenance mode.**\n\nI do not expect and am not entertaining new feature asks. I will still respond\nto PRs and issues that address bugs or security issues. Please send these to\nhttps://github.com/kevinconway/confpy.\n\nI continue to maintain this library because it is used in\nhttps://github.com/kevinconway/rpmvenv.\n\nDefining Configuration Options\n==============================\n\n.. code-block:: python\n\n # Example conf.py\n\n from confpy.api import Configuration\n from confpy.api import Namespace\n from confpy.api import StringOption\n\n cfg = Configuration(\n http_options=Namespace(\n description=\"Options related to HTTP functions.\",\n endpoint=StringOption(\n description=\"The HTTP endpoint to fetch.\",\n default=\"https://some-api.com\",\n required=True,\n ),\n ),\n )\n\nThe above models a configuration file with one section named \"http_options\"\nwhich contains on option named \"endpoint\". Any number of options can be added\nto a namespace and any number of namespaces can be added to a configuration\n\nAll options have the same core keyword arguments. You may set a default value\nfor the option using the 'default' keyword and mark the option as required with\nthe 'required' keyword. Marking an option as required which already has a\ndefault value is redundant and will have no effect.\n\nThe description keyword arguments may be given as shown above. These do not\ndirectly impact the functionality of the object. Instead, descriptions are used\nwhen generating sample config files to help document what different options\nrepresent.\n\nConfiguration definitions like the one above can be defined anywhere within\nyour code. However, it is strongly recommended that you have one module, or\nvery few modules, in your project which contain *only* these definitions.\nThey should be separate from all other code and logic in your project. This is\nsuggested because these definitions must be loaded into a Python process\n*before* they are used by other code. Techniques for doing this are below in\nthe 'Loading Configuration Options' section.\n\nUsing Options In Your Code\n==========================\n\nAny module which imports your configuration definition can access the options\nyou have defined. Continuing the example from above:\n\n.. code-block:: python\n\n # some other python file in your project\n from myproject.conf import cfg\n\n def get_api_data(endpoint=None):\n endpoint = endpoint or cfg.http_options.endpoint\n return requests.get(endpoint)\n\nAll confpy options are automatically converted to the appropriate Python type\nbased on the option used. Accessing the option through its namespace will\nretrieve the currently set configuration value.\n\nLoading Configuration Options\n=============================\n\nOnce the options are defined and used in the code they must be set before they\nare useful. Setting values can be done with one, or more, configuration files,\nenvironment variables, and command line arguments. Here are all of the ways to\ndefine the \"endpoint\" option from our example:\n\nExample INI:\n\n.. code-block::\n\n [http_options]\n endpoint = \"https://some-other-api.com\"\n\n\nExample JSON:\n\n.. code-block:: javascript\n\n {\n \"http_options\": {\n \"endpoint\": \"https://some-other-api.com\"\n }\n }\n\n\nExample Python:\n\n.. code-block:: python\n\n from myproject.conf import cfg\n cfg.http_options.endpoint = \"https://some-other-api.com\"\n\n\nExample Env Var:\n\n.. code-block:: shell\n\n # Note: The CONFPY prefix is configurable.\n export CONFPY_HTTP_OPTIONS_ENDPOINT=\"https://some-other-api.com\"\n\n\nExample CLI Flag:\n\n.. code-block:: shell\n\n some_executable --http_options_endpoint=\"https://some-other-api.com\"\n\nAll of the above examples set the same option to the same value. Any\ncombination of these may be used to set or overwrite options. The option parser\nwill follow a simple pattern for setting and overwrite option values.\nConfiguration files are parsed first with later files overwriting values from\nearlier files. Environment variables are parsed next and can overwrite any\nvalues set by configuration files. CLI flags are parsed last and can overwrite\nany value set.\n\nIn order to bring these values into your Python process you need to add a line\nin your \"main\" (or equivalent) method which imports your configuration\ndefinition and another line which parses and loads the option values. As stated\nabove, the importing of configuration definitions must happen before all other\ncode logic. After the definitions are loaded, but before any other project\ncode, the option values must also be parsed and loaded. For example:\n\n.. code-block:: python\n\n def main():\n\n from myproject.conf import cfg\n # import other configuration definitions if needed.\n\n from confpy.api import parse_options\n # Files are loaded in order. Later values can overwrite earlier values.\n # Pass an 'env_prefix' keyword argument to change the prefix used\n # in environment variables.\n parse_options(files=('example.ini', 'example.json', 'example.py'))\n\n # start your service or WSGI app or CLI call.\n from myproject.wsgi import app\n print(cfg.my_options.http_endpoint)\n app.run(8888)\n\nOption Types\n============\n\nValues from configuration files are automatically converted to the appropriate\nPython type based on the option object used in the configuration definition.\nThe currently available types are:\n\n- BoolOption(description=None, required=False, default=None)\n\n An option which represents a True or False value. The text values of\n 'yes', 'true', and '1' are converted to True. The text values of 'no',\n 'false', and '0' are converted to False. All values are case-insensitive.\n\n- ListOption(description=None, option=None, required=False, default=None)\n\n An option which represents a list of values. The 'option' parameter must\n be an option object which will be used to load/validate each item in the\n list.\n\n- IntegerOption(description=None, required=False, default=None)\n\n An option which represents an integer value.\n\n- FloatOption(description=None, required=False, default=None)\n\n An option which represents a floating point value.\n\n- StringOption(description=None, required=False, default=None)\n\n An option which represents any string value.\n\n- PatternOption(description=None, pattern=None, required=False, default=None)\n\n An option which represents a string constrained by a regex pattern. The\n 'pattern' attribute must be a string which represent the regexp to use.\n\nGenerating Sample Configuration Files\n=====================================\n\nThere is a programmatic API for generating sample configurations in the\n'confpy.example' module. However, the easiest way to generate samples is by\nusing the 'confpy-generate' script that is installed with this package.\n\n::\n\n $ confpy-generate --help\n usage: confpy-generate [-h] [--module MODULE] [--file FILE]\n [--format {JSON,INI}]\n\n Confpy example generator.\n\n optional arguments:\n -h, --help show this help message and exit\n --module MODULE A python module which should be imported.\n --file FILE A python file which should be evaled.\n --format {JSON,INI} The output format of the configuration file.\n\nMultiple '--module' and '--file' flags may be added to load additional\nconfiguration definitions before generating the sample. Module should be\nimportable on the Python path while files must be paths for which the current\nuser has read permissions. By default the generator will create a JSON file.\nUse the '--format' flag to override this behaviour. Our running example would\ngenerate the following:\n\n::\n\n confpy-generate --module=\"myproject.conf\"\n {\n \"http_options\": {\n \"endpoint\": \"https://some-api.com\"\n }\n }\n\n confpy-generate --module=\"myproject.conf\" --format=\"INI\"\n # Options related to HTTP functions.\n [http_options]\n endpoint = \"https://some-api.com\" # The HTTP endpoint to fetch.\n\nWhile developing, it may be easier to use the file path rather than the module\npath if your file is not installed on the Python path.\n\n::\n\n confpy-generate --file ./my_project/conf.py\n\nTesting\n=======\n\nAll tests are organized in the 'tests' subdirectory. The layout of the test\nmodules is paired one-to-one with the modules they test. For example, the tests\nfor confpy.core.config are found in tests/core/test_config.py. Attempt to\nmaintain this organization when adding new tests.\n\nThis repository comes with a tox.ini file which is configured to run a fairly\nexhaustive set of tests. All the current unit tests run, and pass, under Python\n2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6, and 3.7 interpreters. Running the default tox\ncommand will attempt to run the tests in all these environments. In addition,\ntox is also configured to run PEP8, PyFlakes, and PyLint checks. The PyLint\nchecks will make use of the .pylintrc file also included in this repository.\n\nNote that testing for legacy and unsupported Python versions is done on a best\neffort basis. As time passes it becomes more and more difficult to both find\na CI provider who will support old Python versions and to determine the\ncompatible versions of all the test dependencies of the project.\n\nLicense\n=======\n\n::\n\n (MIT License)\n\n Copyright (C) 2015 Kevin Conway\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to\n deal in the Software without restriction, including without limitation the\n rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n sell copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n IN THE SOFTWARE.\n\n\nContributing\n============\n\nAll contributions to this project are protected under the agreement found in\nthe `CONTRIBUTING` file. All contributors should read the agreement but, as\na summary::\n\n You give us the rights to maintain and distribute your code and we promise\n to maintain an open source distribution of anything you contribute.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kevinconway/confpy", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "confpy", "package_url": "https://pypi.org/project/confpy/", "platform": "", "project_url": "https://pypi.org/project/confpy/", "project_urls": { "Homepage": "https://github.com/kevinconway/confpy" }, "release_url": "https://pypi.org/project/confpy/0.11.0/", "requires_dist": [ "Jinja2 ; extra == 'generator'" ], "requires_python": "", "summary": "Config file parsing and option management.", "version": "0.11.0" }, "last_serial": 5725874, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ed36e732c7e095094a5b512d63661f03", "sha256": "cda7d71c13276555c9a613ce011279f02d4c91dd31b8ca66f383fdf94b38e2b1" }, "downloads": -1, "filename": "confpy-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ed36e732c7e095094a5b512d63661f03", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12707, "upload_time": "2015-01-04T06:39:52", "url": "https://files.pythonhosted.org/packages/fe/06/48a19dd0bc4f01b64812a955678cb9cb4c942a54d90ba0afeff04dd32c59/confpy-0.1.0.tar.gz" } ], "0.10.0": [ { "comment_text": "", "digests": { "md5": "4eee8efa6d564d8ec36a5005b25d3c16", "sha256": "f51537149cac3e82d7a99d0eee04cdc3283e363457a8f01c9447ebd0c5a27da9" }, "downloads": -1, "filename": "confpy-0.10.0.tar.gz", "has_sig": false, "md5_digest": "4eee8efa6d564d8ec36a5005b25d3c16", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18204, "upload_time": "2015-03-06T08:30:21", "url": "https://files.pythonhosted.org/packages/89/8d/7c0a08f0f1d0690398e4dfc58564ea28c4dc3bc8617cfd1d5119d5cf2c7c/confpy-0.10.0.tar.gz" } ], "0.11.0": [ { "comment_text": "", "digests": { "md5": "27037b13ff5a42fd244749dc781a1ce5", "sha256": "afea3307c819a8f3f063e6e4da9ab336b6cd55663235bf01b0a07328d4b21532" }, "downloads": -1, "filename": "confpy-0.11.0-py2-none-any.whl", "has_sig": false, "md5_digest": "27037b13ff5a42fd244749dc781a1ce5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 151324, "upload_time": "2019-08-25T03:02:16", "url": "https://files.pythonhosted.org/packages/74/35/e246562a567ab3cc06f10f8598020e38375a066f8ce0763f18b31b731463/confpy-0.11.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10bd798d624c099402d35057d0f5bd0e", "sha256": "78e2f49a1bb4848c88f0183e53abca5e3c0456ad5286bc7769aff64bf8ca6c5e" }, "downloads": -1, "filename": "confpy-0.11.0-py3-none-any.whl", "has_sig": false, "md5_digest": "10bd798d624c099402d35057d0f5bd0e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 151325, "upload_time": "2019-08-25T03:02:17", "url": "https://files.pythonhosted.org/packages/18/fc/5cf9d26226944b9aa6eed360ff5ff28cf53ac02afb725abe1763eed1d2a5/confpy-0.11.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "11ed49389319bd94d39a8bef2247eaf8", "sha256": "d6eecb631bab7a9de51952ad93b57dbb8eae3bef6d68477463a4a4e25f2fdf1e" }, "downloads": -1, "filename": "confpy-0.11.0.tar.gz", "has_sig": false, "md5_digest": "11ed49389319bd94d39a8bef2247eaf8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 55970, "upload_time": "2019-08-25T03:02:19", "url": "https://files.pythonhosted.org/packages/dc/c0/3a195738f762b006e416991a610d9e6d8b3bf727cdef01d0a798a74b2dda/confpy-0.11.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "71ba68a35a4733b27215b58605616f85", "sha256": "640aac142716ee79cf2936558b56bb4570388ef61a7c766ae1d7fc20724234b9" }, "downloads": -1, "filename": "confpy-0.4.0.tar.gz", "has_sig": false, "md5_digest": "71ba68a35a4733b27215b58605616f85", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21772, "upload_time": "2015-01-06T03:42:17", "url": "https://files.pythonhosted.org/packages/c1/51/51854e94e2a4f0d1f6e3df30497a4af7e8c2144d0660192679fedb1255bf/confpy-0.4.0.tar.gz" } ], "0.7.1": [ { "comment_text": "", "digests": { "md5": "ef481e8ac4fdf4a64f6a27f1e918a0af", "sha256": "0c18f9e56b6b988ea92e86141a43b11b25812b88a0cbf71b89657915107b4cb7" }, "downloads": -1, "filename": "confpy-0.7.1.tar.gz", "has_sig": false, "md5_digest": "ef481e8ac4fdf4a64f6a27f1e918a0af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17763, "upload_time": "2015-01-07T14:11:35", "url": "https://files.pythonhosted.org/packages/11/61/9921dd6d505babca5630d84b20abc5d690643e3cbc12b9663f493ac2c32e/confpy-0.7.1.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "105f60ae91f2f5583b3a368f8d2d4088", "sha256": "a9938c4cc67924dcad397067cdeac31ef77511cd476928af792cd412e6ebb7f9" }, "downloads": -1, "filename": "confpy-0.9.1.tar.gz", "has_sig": false, "md5_digest": "105f60ae91f2f5583b3a368f8d2d4088", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17944, "upload_time": "2015-03-06T03:36:03", "url": "https://files.pythonhosted.org/packages/f6/e0/c4cade4381a05414d5e4a8ed0f1267fe2c8d3819ed18760f6d0995939ac8/confpy-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "7c7cc2e4d14ff7303e3bee644afa9796", "sha256": "5c519da132d74be203ba2bd5f322a0406290cec7f4a73693a610a7f902c9a8c5" }, "downloads": -1, "filename": "confpy-0.9.2.tar.gz", "has_sig": false, "md5_digest": "7c7cc2e4d14ff7303e3bee644afa9796", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17953, "upload_time": "2015-03-06T05:44:25", "url": "https://files.pythonhosted.org/packages/6d/9e/6e9d0a7f10e8387508eff165bffd1192727873d775a87c211d5232918610/confpy-0.9.2.tar.gz" } ], "0.9.3": [ { "comment_text": "", "digests": { "md5": "bfe53eafaa02b4ed2faa692a304dc2a4", "sha256": "08adfbc44132aa440548ad695fb7e672496462d8c43fd7f53599fbc84d84af42" }, "downloads": -1, "filename": "confpy-0.9.3.tar.gz", "has_sig": false, "md5_digest": "bfe53eafaa02b4ed2faa692a304dc2a4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18117, "upload_time": "2015-03-06T06:27:37", "url": "https://files.pythonhosted.org/packages/ec/f3/3fc85c86e691c65adcbc2379f33bc2cd91c3a228bfc32515658192f3efe5/confpy-0.9.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "27037b13ff5a42fd244749dc781a1ce5", "sha256": "afea3307c819a8f3f063e6e4da9ab336b6cd55663235bf01b0a07328d4b21532" }, "downloads": -1, "filename": "confpy-0.11.0-py2-none-any.whl", "has_sig": false, "md5_digest": "27037b13ff5a42fd244749dc781a1ce5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 151324, "upload_time": "2019-08-25T03:02:16", "url": "https://files.pythonhosted.org/packages/74/35/e246562a567ab3cc06f10f8598020e38375a066f8ce0763f18b31b731463/confpy-0.11.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "10bd798d624c099402d35057d0f5bd0e", "sha256": "78e2f49a1bb4848c88f0183e53abca5e3c0456ad5286bc7769aff64bf8ca6c5e" }, "downloads": -1, "filename": "confpy-0.11.0-py3-none-any.whl", "has_sig": false, "md5_digest": "10bd798d624c099402d35057d0f5bd0e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 151325, "upload_time": "2019-08-25T03:02:17", "url": "https://files.pythonhosted.org/packages/18/fc/5cf9d26226944b9aa6eed360ff5ff28cf53ac02afb725abe1763eed1d2a5/confpy-0.11.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "11ed49389319bd94d39a8bef2247eaf8", "sha256": "d6eecb631bab7a9de51952ad93b57dbb8eae3bef6d68477463a4a4e25f2fdf1e" }, "downloads": -1, "filename": "confpy-0.11.0.tar.gz", "has_sig": false, "md5_digest": "11ed49389319bd94d39a8bef2247eaf8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 55970, "upload_time": "2019-08-25T03:02:19", "url": "https://files.pythonhosted.org/packages/dc/c0/3a195738f762b006e416991a610d9e6d8b3bf727cdef01d0a798a74b2dda/confpy-0.11.0.tar.gz" } ] }