{ "info": { "author": "Ilya Dunin", "author_email": "ilya.mirea@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "app\\_settings module\n====================\n\nSimplify usage of YAML files for application configuration.\n\nInspired by Ruby Gem \"config\" https://github.com/railsconfig/config But\nnot all features implemented yet.\n\nUsage example\n-------------\n\nInstallation: ``pip install app_settings``\n\nCreate sample app with following structure:\n\n.. code:: bash\n\n /my_app\n my_app.py\n /config\n settings.yml # at least one *.yml file required\n additional_settings.yml\n /settings # use this only in case if you need different settings for your environments\n production.yml\n production.db.yml\n development.yml\n development.db.yml \n\n``AppSettings`` -- singleton, so it is not possible to create more than\none instance of config object.\n\nBy default, script will try to load all ``./config/*.yml`` and, if exist\n``./config/settings/${APP_ENV}*.yml`` configuration files.\n\nTake note, that all variables defined in ``./config/*.yml`` files will\nbe overridden by variables from ``./config/settings/${APP_ENV}.yml``.\n\nAlso, ``./config/*.yml`` loaded in alphabetical order, so if you will\ndefine variable VAR in ``additional_settings.yml`` it will be redefined\nby VAR from ``settings.yml``.\n\nIf you have settings, which not depends on the environment, simply use\n``./config/{file name}.yml``; In case, when you need settings, which\ndepends on the environment, use ``./config/settings/{ENV}.yml``.\n\nEnvironment (development/stage/production etc)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf your application use more than one environment, for example\n``development`` and ``production``, you can specify what config file to\nload by setting env variable\n\n.. code:: python\n\n # before your application starts\n # export APP_ENV='production' or APP_ENV='production' python my_app.py \n\n from app_settings import AppSettings\n\n cfg = AppSettings()\n\nBy default, if no ``APP_ENV`` is given, file\n``./config/settings/development.yml`` will be loaded, that's why this\nfile is required.\n\nAlso it is possible to redefine name of variable.\n\n.. code:: python\n\n # export TEST_ENV='production'\n\n from app_settings import AppSettings\n\n cfg = AppSettings(env_name='TEST_ENV')\n\nWorking with environment variables\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIt is possible to redefine or set settings from environment variables.\nAppSettings will read all env variables with ``SETTINGS`` prefix (by\ndefault).\n\n.. code:: yaml\n\n # settings.yml\n level1:\n redefined: 'redefined'\n not_redefined: 'not redefined'\n\n.. code:: python\n\n # export SETTINGS__MY_VAR='test'\n # export SETTINGS__LEVEL1__REDEFINED='val'\n\n from app_settings import AppSettings\n\n cfg = AppSettings()\n print(cfg.my_var) # 'test'\n print(cfg.level1.redefined) # 'val'\n print(cfg.level1.not_redefined) # 'not redefined'\n\nYou can setup your own prefix:\n\n.. code:: python\n\n # export MYPREFIX__MY_VAR='test'\n # export MYPREFIX__LEVEL1__REDEFINED='val'\n\n from app_settings import AppSettings\n\n cfg = AppSettings(prefix='myprefix')\n print(cfg.my_var) # 'test'\n print(cfg.level1.redefined) # 'val'\n\nAlso it is possible to setup environment variable splitter (default:\n``__``).\n\n.. code:: python\n\n # export SETTINGS.MY_VAR='test'\n # export SETTINGS.LEVEL1.REDEFINED='val'\n\n from app_settings import AppSettings\n\n cfg = AppSettings(splitter='.')\n print(cfg.my_var) # 'test'\n print(cfg.level1.redefined) # 'val'\n\nIf you don't need to set/redefine settings from environment variables,\nuse ``use_env`` flag.\n\n.. code:: python\n\n from app_settings import AppSettings\n cfg = AppSettings(use_env=False)\n\nSuppress KeyError exception\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn case, if you don't want to receive KeyError exception if key not\ndefined in file, you can use ``raise_error`` flag. By default: True\n\n.. code:: python\n\n from app_settings import AppSettings\n cfg = AppSettings(raise_error=False)\n\n key = cfg.this_value_not_exist # key == None\n\nConfig path\n~~~~~~~~~~~\n\nYou can redefine default config path\n\n.. code:: python\n\n from app_settings import AppSettings\n\n cfg = AppSettings(configs_path='my_config_path')\n\nRun tests\n---------\n\n.. code:: bash\n\n cd app_settings\n python -m pytest -v --alluredir=./tests/results -n `nproc` --cov=app_settings --cov-config .coveragerc ./tests\n\nSample usage for tests\n~~~~~~~~~~~~~~~~~~~~~~\n\nRun these commands to create sample files structure\n\n.. code:: bash\n\n $ cd \n $ mkdir -p config/settings && \\ \n touch config/settings.yml && \\\n touch config/settings/{production.yml,testing.yml} && \\\n echo \"implicity_wait: 5\" > config/settings.yml && \\\n echo 'search_text: \"production environment\"' > config/settings/production.yml && \\\n echo 'search_text: \"testing environment\"' > config/settings/testing.yml\n $ touch test_with_app_settings.py\n\nInstall all python requirements:\n\n.. code:: bash\n\n pip install selenium pytest app_settings\n\nCopy code to ``test_with_app_settings.py``\n\n.. code:: python\n\n ### Example, don't use it in your code\n import os\n os.environ['TEST_ENV'] = 'production'\n ### example\n\n import pytest\n from app_settings import AppSettings\n from selenium import webdriver\n\n\n @pytest.fixture(scope='session')\n def settings():\n cfg = AppSettings(env_name='TEST_ENV')\n return cfg\n\n\n @pytest.fixture\n def browser(settings):\n driver = webdriver.Chrome()\n driver.implicitly_wait(settings.implicity_wait)\n yield driver\n driver.close()\n\n\n def test_example(browser, settings):\n browser.get(\"https://ya.ru\")\n search_field = browser.find_element_by_id('text')\n search_field.send_keys(settings.search_text) # depending on env\n search_button = browser.find_element_by_tag_name('button')\n search_button.click()\n browser.find_elements_by_css_selector(\"div ul li\")\n\nTODO\n----\n\n1. Add reload feature\n\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/ivdunin/app_settings", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "app-settings", "package_url": "https://pypi.org/project/app-settings/", "platform": "", "project_url": "https://pypi.org/project/app-settings/", "project_urls": { "Homepage": "https://github.com/ivdunin/app_settings" }, "release_url": "https://pypi.org/project/app-settings/1.3/", "requires_dist": [ "PyYAML (>=3.13)" ], "requires_python": "", "summary": "YAML for application configuration, lite version (inspired by Ruby gem \"config\")", "version": "1.3" }, "last_serial": 5744774, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "3c93435603d1254cf0a5a6c38d5bf285", "sha256": "6de12045ce668d66ff72811f9883b3090850bb546beee70e96037eee4f4047e0" }, "downloads": -1, "filename": "app_settings-1.0.tar.gz", "has_sig": false, "md5_digest": "3c93435603d1254cf0a5a6c38d5bf285", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6479, "upload_time": "2019-03-10T19:57:10", "url": "https://files.pythonhosted.org/packages/5a/5c/676a153b8c9fe47a8441be003cddff428edf3dd576778ae11520333fc1cb/app_settings-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "b642efe912c5fc9659939c8d5ab3086e", "sha256": "bcce753086919f6d738328b2c1a2a6f08b631247af021bb502f062719e6b939e" }, "downloads": -1, "filename": "app_settings-1.1.tar.gz", "has_sig": false, "md5_digest": "b642efe912c5fc9659939c8d5ab3086e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6681, "upload_time": "2019-03-10T20:57:57", "url": "https://files.pythonhosted.org/packages/91/5a/8e4155516f3e4c411c25016f9b940daee6e3656f88e78f3f337a3721624c/app_settings-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "86eb7e4697b4332ecfd872fd6157a954", "sha256": "4d0d3852327f87873e5a8352a7deee88be2ca1ab98d5175760fba99138170a88" }, "downloads": -1, "filename": "app_settings-1.2.tar.gz", "has_sig": false, "md5_digest": "86eb7e4697b4332ecfd872fd6157a954", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6839, "upload_time": "2019-03-13T16:03:42", "url": "https://files.pythonhosted.org/packages/4e/44/6c65372a83657f3de5f106f2aa02575de9501ded54c9ef67202379ea15b3/app_settings-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "5a65ab739501d9e13516f5032d91d632", "sha256": "5a0d35589d6a43ff62345a868d3d2dc6efe40431fc0072ad886d1df6bdace5e7" }, "downloads": -1, "filename": "app_settings-1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5a65ab739501d9e13516f5032d91d632", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5863, "upload_time": "2019-08-28T19:06:38", "url": "https://files.pythonhosted.org/packages/cc/22/2feee37be066cec711c911cea89681ca15e08101e498bc79c2a58fef6aa9/app_settings-1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b31d28c49f757a28a7421508baa667d2", "sha256": "d24ead302e5bb1736bf4bd74c9fa7b1cd6867d65fc94346875cc3a208aa1f7db" }, "downloads": -1, "filename": "app_settings-1.3.tar.gz", "has_sig": false, "md5_digest": "b31d28c49f757a28a7421508baa667d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5153, "upload_time": "2019-08-28T19:06:40", "url": "https://files.pythonhosted.org/packages/26/e9/5505fd74c8d60e51ecb8b945a00caacdf8703206393b860056eab5ab0846/app_settings-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5a65ab739501d9e13516f5032d91d632", "sha256": "5a0d35589d6a43ff62345a868d3d2dc6efe40431fc0072ad886d1df6bdace5e7" }, "downloads": -1, "filename": "app_settings-1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5a65ab739501d9e13516f5032d91d632", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5863, "upload_time": "2019-08-28T19:06:38", "url": "https://files.pythonhosted.org/packages/cc/22/2feee37be066cec711c911cea89681ca15e08101e498bc79c2a58fef6aa9/app_settings-1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b31d28c49f757a28a7421508baa667d2", "sha256": "d24ead302e5bb1736bf4bd74c9fa7b1cd6867d65fc94346875cc3a208aa1f7db" }, "downloads": -1, "filename": "app_settings-1.3.tar.gz", "has_sig": false, "md5_digest": "b31d28c49f757a28a7421508baa667d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5153, "upload_time": "2019-08-28T19:06:40", "url": "https://files.pythonhosted.org/packages/26/e9/5505fd74c8d60e51ecb8b945a00caacdf8703206393b860056eab5ab0846/app_settings-1.3.tar.gz" } ] }