{ "info": { "author": "Sergey Kozlov", "author_email": "dev@ludditelabs.io", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "config-source\n=============\n\n.. image:: https://travis-ci.org/LudditeLabs/config-source.svg?branch=master\n :target: https://travis-ci.org/LudditeLabs/config-source\n\nThis package provides extensible configuration loading from various sources.\n\nFeatures:\n\n* Dict-like configuration loading from:\n\n - python dictionaries\n - python objects\n - python files\n - environment variables\n - JSON files\n\n* Custom configuration sources and objects.\n\nBasically ``config-source`` provides a way to register configuration loaders and\ncall them by names. The loader accepts optional arguments, reads configuration\nfrom a specific source and populates a configuration object.\n\nExample::\n\n from config_source import DictConfig\n from config_source import DictConfigLoader\n\n config = DictConfig()\n config.load_from('pyfile', '/path/to/config.py')\n config.load_from('json', '/path/to/config.json')\n config.load_from('env', prefix='MYCFG_')\n\n loader = DictConfigLoader(config)\n loader.load('/path/to/config.py')\n loader.load('/path/to/config.json')\n loader.load(SomeClassWithConfigs)\n\nUsage\n-----\n\nOut of the box you could use:\n\n* Low level ``load_to()`` function.\n* ``DictConfig`` class.\n* ``DictConfigLoader`` class to assist in configurations loading.\n\n\n``load_to()`` calls a loader registered for a specific source and populates\na config object passed to it::\n\n load_to(config, 'source_name', ...)\n\n* ``config`` - configuration object to populate.\n* ``source_name`` - configuration source name.\n\n``DictConfig`` behaves like a regular python dictionary and provides\n``load_from`` method to load configurations from various sources (it uses\n``load_to()`` internally)::\n\n config = DictConfig()\n config.load_from(, *args, **kwargs)\n\n* ```` - configuration source name;\n\n* ``*args`` and ``**kwargs`` - arguments for configuration loader.\n\nThe following sources are provided out of the box for *dict-like*\nconfigurations.\n\n**Note**: *dict-like* means any object with mapping interface can be used as\nconfiguration object::\n\n config = {}\n load_to(config, 'env', ...)\n\n dictconfig = DictConfig()\n dictconfig.load_from('env', ...)\n load_to(dictconfig, 'env', ...)\n\n* ``object`` - load configuration from a python ``object``. It reads attributes\n with uppercase names::\n\n\n config.load_from('object', )\n\n Example::\n\n class MyConfig:\n SECRET_KEY = 123\n DEBUG = False\n\n ...\n\n config.load_from('object', MyConfig)\n\n* ``dict`` - load configuration from a python dictionary. Reads only uppercase\n keys::\n\n config.load_from('dict', )\n\n Example::\n\n myconfig = dict(SECRET_KEY=123, DEBUG=False)\n config.load_from('dict', myconfig)\n\n* ``env`` - load configuration from current runtime environment::\n\n config.load_from('env', prefix=, trim_prefix=True)\n\n\n - ``prefix`` - Environment variable name prefix.\n\n - ``trim_prefix`` - Include or not prefix to result config name\n\n Example::\n\n # Load vars with names MYCFG_*, like MYCFG_SECRET.\n config.load_from('env', prefix='MYCFG_')\n\n* ``pyfile`` - load configuration from a python file. Reads only uppercase\n attributes::\n\n config.load_from('env', filename, silent=False)\n\n - ``filename`` - filename to load.\n\n - ``silent`` - Don't raise an error on missing files.\n\n Example::\n\n config.load_from('pyfile', 'config.py')\n\n* ``json`` - load configuration from a json file. Reads only uppercase keys::\n\n config.load_from('json', filename, silent=False)\n\n - ``filename`` - filename to load.\n\n - ``silent`` - Don't raise an error on missing files.\n\n Example::\n\n config.load_from('json', '/path/to/config.json')\n\n``DictConfigLoader`` auto-detects source name from input configuration source::\n\n loader = DictConfigLoader(config)\n loader.load('/path/to/file.py')\n\n # Same as:\n config.load_from('pyfile', '/path/to/file.py')\n\nYou may subclass to extend auto-detection.\n\nAdd source\n----------\n\n``config_source`` decorator is used to register additional configuration\nsources::\n\n from config_source import config_source\n\n @config_source('source_name')\n def myloader(config, arg1, arg2):\n config['XX'] = arg1 + arg2\n\n config.load_from('source_name', 1, arg2=2)\n\nConfiguration loader must be a callable with at least one argument -\nconfiguration object to populate. Other arguments are optional and loader specific.\n\nThere is a possibility to register configuration sources by implementing\na package with entry point::\n\n setup(\n ...\n entry_points={'config_source.sources': ' = '},\n ...\n )\n\nIn the package you use ``config_source`` decorator.\n\nFor more info on entry points see\n\n* https://packaging.python.org/guides/creating-and-discovering-plugins/\n* http://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points\n* http://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins\n\n**Note**: you could specify single entry point even if your package adds\nmultiple sources.\n\nDefaults\n--------\n\nInstead of always passing parameters to configuration loaders you could set\ndefaults in ``DictConfig``::\n\n config = DictConfig(defaults={\n 'env': {'prefix': 'MYAPP_'},\n 'pyfile': {'filename': '/path/to/file.py'}\n })\n\n # 'prefix' will be set to MYAPP_ for 'env' config source.\n # Load from 'MYAPP_*' vars by default.\n config.load_from('env')\n\n # Load from 'MY_*' vars\n config.load_from('env', 'MY_')\n\n # Load from '/path/to/file.py' by default.\n config.load_from('pyfile')\n\n # Load from '/path/to/another/file.py'.\n config.load_from('pyfile', '/path/to/another/file.py')\n\n``defaults`` is a map where keys are source names and values are keyword\nparameters to be passed to loaders.\n\nCustom configuration type\n-------------------------\n\nYou can register configuration source for specific type\n(by default it's a ``dict``)::\n\n @config_source('source_name', config_type='mytype')\n def mytype_loader(config):\n ....\n\n``config_type`` here is a string defining configuration object type.\n\nNow you populate your config object using that loader::\n\n load_to(config, 'source_name', config_type='mytype')\n\nwhere ``config`` is object implementing ``mytype`` interface.\n\n``list`` configuration example::\n\n from config_source import config_source, load_to\n\n\n @config_source('object', config_type='list')\n def object_loader(config, obj):\n has = False\n for key in dir(obj):\n if key.isupper():\n has = True\n config.append(getattr(obj, key))\n return has\n\n\n class MyConfig:\n SECRET = 1\n DEBUG = False\n\n\n cfg = []\n load_to(cfg, 'object', config_type='list')\n\n # cfg = [1, False]\n\n # Fails because by default it calls loader for 'dict' configuration.\n # load_to(cfg, 'object')\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "config-source", "package_url": "https://pypi.org/project/config-source/", "platform": "", "project_url": "https://pypi.org/project/config-source/", "project_urls": null, "release_url": "https://pypi.org/project/config-source/0.0.7/", "requires_dist": [ "future (>=0.16.0)" ], "requires_python": "", "summary": "Simple configurations management for applications.", "version": "0.0.7" }, "last_serial": 5718725, "releases": { "0.0.5": [ { "comment_text": "", "digests": { "md5": "5f91143c4c4ff75b11ed41ab8c06c10d", "sha256": "cb5d564642da36b5f66284958765959626e5ba6d5c8aba4c80be18d258568e9f" }, "downloads": -1, "filename": "config_source-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "5f91143c4c4ff75b11ed41ab8c06c10d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10573, "upload_time": "2019-02-04T12:30:55", "url": "https://files.pythonhosted.org/packages/c1/fa/f6362c5fd5a945e4cfed482ed5676e1940d75901be332e35d4c72fff0059/config_source-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "82c17085d0469c476e5795f5cf055133", "sha256": "5c31b9a0f8e3ab05d8666e75859ecc42da394deb1dd02ce0d3e3ff5777d420ca" }, "downloads": -1, "filename": "config_source-0.0.5.tar.gz", "has_sig": false, "md5_digest": "82c17085d0469c476e5795f5cf055133", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6540, "upload_time": "2019-02-04T12:30:57", "url": "https://files.pythonhosted.org/packages/31/11/241c4aad7ba8b95125b1b88e4acb06f8f1258432632b74bac6a5fcb1db90/config_source-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "0d5e7677c100e638cb10a8a3567cb79c", "sha256": "ae158ffeac73a8d6bf391c674d726f549c201bc51c6ef2dc7378fb5c15c2f5be" }, "downloads": -1, "filename": "config_source-0.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "0d5e7677c100e638cb10a8a3567cb79c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11017, "upload_time": "2019-02-05T09:47:28", "url": "https://files.pythonhosted.org/packages/35/b8/05f73d3439aa96a7ca9c0523d7e14a7cee34122c83def4a8419b84fadfe5/config_source-0.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8c11ac82f6b8a5f783066aee3b835c0a", "sha256": "01819de949e41d0c53e252b7ff73fd951220fb61208cba98e1109134422752ed" }, "downloads": -1, "filename": "config-source-0.0.6.tar.gz", "has_sig": false, "md5_digest": "8c11ac82f6b8a5f783066aee3b835c0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6999, "upload_time": "2019-02-05T09:47:30", "url": "https://files.pythonhosted.org/packages/19/d5/0417e14c9c032aa458863c6fd7ff150dfd92fa4516b6b4907c96d8920abd/config-source-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "ace547bb2309883989bc8b93beb98d80", "sha256": "724997e80f9819ee341d26b5540f52b3c04fbf2be92bb2c054bce4d95bb9275d" }, "downloads": -1, "filename": "config_source-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "ace547bb2309883989bc8b93beb98d80", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11013, "upload_time": "2019-08-23T04:11:46", "url": "https://files.pythonhosted.org/packages/0f/01/0ef8d41b3fe2f7c262b806a017505adffdfb522fdb4d1df98e0f068af885/config_source-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d38fcb4a604d6daf2d1abd4ca902361d", "sha256": "5c6dd8797e76f51e6e9cab4e1dc297fd5c04a0c2ad9f926ea0df903e298fe05a" }, "downloads": -1, "filename": "config-source-0.0.7.tar.gz", "has_sig": false, "md5_digest": "d38fcb4a604d6daf2d1abd4ca902361d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7002, "upload_time": "2019-08-23T04:11:48", "url": "https://files.pythonhosted.org/packages/c9/5a/b60d65b88f56306c673994294e8e78a17f00039a350107997b036a52d627/config-source-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ace547bb2309883989bc8b93beb98d80", "sha256": "724997e80f9819ee341d26b5540f52b3c04fbf2be92bb2c054bce4d95bb9275d" }, "downloads": -1, "filename": "config_source-0.0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "ace547bb2309883989bc8b93beb98d80", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11013, "upload_time": "2019-08-23T04:11:46", "url": "https://files.pythonhosted.org/packages/0f/01/0ef8d41b3fe2f7c262b806a017505adffdfb522fdb4d1df98e0f068af885/config_source-0.0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d38fcb4a604d6daf2d1abd4ca902361d", "sha256": "5c6dd8797e76f51e6e9cab4e1dc297fd5c04a0c2ad9f926ea0df903e298fe05a" }, "downloads": -1, "filename": "config-source-0.0.7.tar.gz", "has_sig": false, "md5_digest": "d38fcb4a604d6daf2d1abd4ca902361d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7002, "upload_time": "2019-08-23T04:11:48", "url": "https://files.pythonhosted.org/packages/c9/5a/b60d65b88f56306c673994294e8e78a17f00039a350107997b036a52d627/config-source-0.0.7.tar.gz" } ] }