yamlsettings


Nameyamlsettings JSON
Version 2.1.2 PyPI version JSON
download
home_pagehttps://github.com/KyleJamesWalker/yamlsettings
SummaryYaml Settings Configuration Module
upload_time2024-07-12 23:28:53
maintainerNone
docs_urlNone
authorKyle James Walker
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            YamlSettings
------------

A Settings Configuration Module.

.. image:: https://travis-ci.org/KyleJamesWalker/yamlsettings.svg?branch=master
    :target: https://travis-ci.org/KyleJamesWalker/yamlsettings

.. image:: https://codecov.io/gh/KyleJamesWalker/yamlsettings/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/KyleJamesWalker/yamlsettings

A library to help manage project settings, without having to worry about
accidentally checking non-public information, like api keys.  Along with
environment variable support.

Example setup
^^^^^^^^^^^^^
Python Code - Base Functions

.. code-block:: python

 import yamlsettings


 app_settings = yamlsettings.load('defaults.yaml')
 app_settings.update(yamlsettings.load('settings.yaml'))
 yamlsettings.update_from_env(app_settings)
 user = app_settings.myproj.databases.primary_sql.user

defaults.yml - Default Settings for Project (tracked)

.. code-block:: yaml

 ---
 # Program Defaults, do not edit this file!!!
 # All values should be overridden in the following ways:
 # 1. In the 'settings.yaml' file.
 # 2. With environment variables. Example myproj.databases.primary_sql.user can
 #    be overridden with MYPROJ_DATABASES_PRIMARY_SQL_USER.
 myproj:
   databases:
     primary_sql:
       user: my_user
       passwd: password_here
       host: db-bouncer-01.postgres.com:5432
       db: postgres
       compress: true
       engine: postgresql
     splunk:
       user: splunk_user_here
       passwd: password here
       host: splunk.com
       port: 8089
     redis:
       redis_host: 127.0.0.1
       redis_port: 6379
   flask_config:
     DEBUG: False
     SECRET_KEY: hard key to guess and keep values secret
   debug_sql: false
   debug_profiler: false
   cache_routes: true
   logging_config:
     version: 1
     disable_existing_loggers: False
     formatters:
       light:
         format: '%(asctime)s [%(levelname).1s] %(name)s: %(message)s'
         datefmt: '%Y-%m-%d %H:%M:%S'
       verbose:
         format: '%(asctime)s %(levelname) 8s(%(name)s): %(message)s'
         datefmt: ''
     handlers:
       console:
         class: logging.StreamHandler
         level: DEBUG
         formatter: light
         stream: ext://sys.stdout
       slack:
         class: api.slackLogHandler.BufferingSlackWebHookHandler
         level: INFO
         formatter: light
         capacity: 100
         organization: KyleJamesWalker
         token: need_this
         channel: '#services'
         username: my-proj-logger
         icon_emoji: ':happy_panda:'
       noid:
         class: logging.NullHandler
     loggers:
       requests:
         level: NOTSET
         handlers: [noid]
         propagate: no
     root:
       level: NOTSET
       handlers:
         - console

settings.yml - Custom Settings (untracked)

.. code-block:: yaml

 ---
 myproj:
   databases:
     primary_sql:
       user: root
       passwd: god
     splunk:
       user: real_user
       passwd: pa$$word
   flask_config:
     SECRET_KEY: sdfasjksdfASFAS23423f@#$%!$#VR@%UQ%
   logging_config:
     handlers:
       slack:
         token: 123243294832104981209
     root:
       handlers:
         - console
         - slack

Example package resource loading

.. code-block:: python

 """Parameters that can be passed are:
  resource: The resource to load from the package (default: settings.yaml)
  env: When set the yamldict will update with env variables (default: true)
  prefix: Prefix for environment loading (default: None)
  persist: When set the yamldict will only be loaded once. (default: true)
 """
 yamlsettings.load('package://example')
 yamlsettings.load('package://example?resource=diff.yaml')
 yamlsettings.load('package://example?prefix=MY_FUN&persist=false')


Plugins
^^^^^^^

This project also supports plugins. The base project has two plugins:

- file: Loads from the file system.
- package: Loads settings from a package resource.

Example Plugin:
===============

setup.py

.. code-block:: python

 from setuptools import setup

 setup(
     name='yamlsettings-example',
     version='1.0.0',
     author='Kyle Walker',
     author_email='KyleJamesWalker@gmail.com',
     description='Quick Example',
     requirements=['yamlsettings'],
     py_modules=['yamlsettings_example'],
     entry_points={
         'yamlsettings10': [
             'ext = yamlsettings_example:ZxcExtension',
         ],
     },
 )

yamlsettings_example.py

.. code-block:: python

 from yamlsettings.extensions.base import YamlSettingsExtension


 class ZxcExtension(YamlSettingsExtension):
     """Quick Example Plugin

     Standard file opener, but will merge in values passed to kwargs
     """
     protocols = ['zxc']

     @classmethod
     def load_target(cls, scheme, path, fragment, username,
                     password, hostname, port, query,
                     load_method, **kwargs):
         full_path = (hostname or '') + path
         obj = load_method(open(full_path, **query))

         # Load all returns a generator list of configurations
         many = isinstance(obj, types.GeneratorType)
         obj = list(obj) if many else obj

         if many:
             for x in obj:
                 x.update(kwargs)
         else:
             obj.update(kwargs)

         return obj

usage

.. code-block:: python

 import yamlsettings
 yamlsettings.load("zxc://defaults.yaml", foo='bar')

 # Note: this is automatically detected when the extension is installed
 # alternatively the extension can be manually registered with:
 yamlsettings.registry.add(ZxcExtension)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/KyleJamesWalker/yamlsettings",
    "name": "yamlsettings",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Kyle James Walker",
    "author_email": "KyleJamesWalker@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/00/f3/b6197c94ae1296855ed8e8ac85004d41a01990a9bf3f7cb32f2c854fc3cf/yamlsettings-2.1.2.tar.gz",
    "platform": null,
    "description": "YamlSettings\n------------\n\nA Settings Configuration Module.\n\n.. image:: https://travis-ci.org/KyleJamesWalker/yamlsettings.svg?branch=master\n    :target: https://travis-ci.org/KyleJamesWalker/yamlsettings\n\n.. image:: https://codecov.io/gh/KyleJamesWalker/yamlsettings/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/KyleJamesWalker/yamlsettings\n\nA library to help manage project settings, without having to worry about\naccidentally checking non-public information, like api keys.  Along with\nenvironment variable support.\n\nExample setup\n^^^^^^^^^^^^^\nPython Code - Base Functions\n\n.. code-block:: python\n\n import yamlsettings\n\n\n app_settings = yamlsettings.load('defaults.yaml')\n app_settings.update(yamlsettings.load('settings.yaml'))\n yamlsettings.update_from_env(app_settings)\n user = app_settings.myproj.databases.primary_sql.user\n\ndefaults.yml - Default Settings for Project (tracked)\n\n.. code-block:: yaml\n\n ---\n # Program Defaults, do not edit this file!!!\n # All values should be overridden in the following ways:\n # 1. In the 'settings.yaml' file.\n # 2. With environment variables. Example myproj.databases.primary_sql.user can\n #    be overridden with MYPROJ_DATABASES_PRIMARY_SQL_USER.\n myproj:\n   databases:\n     primary_sql:\n       user: my_user\n       passwd: password_here\n       host: db-bouncer-01.postgres.com:5432\n       db: postgres\n       compress: true\n       engine: postgresql\n     splunk:\n       user: splunk_user_here\n       passwd: password here\n       host: splunk.com\n       port: 8089\n     redis:\n       redis_host: 127.0.0.1\n       redis_port: 6379\n   flask_config:\n     DEBUG: False\n     SECRET_KEY: hard key to guess and keep values secret\n   debug_sql: false\n   debug_profiler: false\n   cache_routes: true\n   logging_config:\n     version: 1\n     disable_existing_loggers: False\n     formatters:\n       light:\n         format: '%(asctime)s [%(levelname).1s] %(name)s: %(message)s'\n         datefmt: '%Y-%m-%d %H:%M:%S'\n       verbose:\n         format: '%(asctime)s %(levelname) 8s(%(name)s): %(message)s'\n         datefmt: ''\n     handlers:\n       console:\n         class: logging.StreamHandler\n         level: DEBUG\n         formatter: light\n         stream: ext://sys.stdout\n       slack:\n         class: api.slackLogHandler.BufferingSlackWebHookHandler\n         level: INFO\n         formatter: light\n         capacity: 100\n         organization: KyleJamesWalker\n         token: need_this\n         channel: '#services'\n         username: my-proj-logger\n         icon_emoji: ':happy_panda:'\n       noid:\n         class: logging.NullHandler\n     loggers:\n       requests:\n         level: NOTSET\n         handlers: [noid]\n         propagate: no\n     root:\n       level: NOTSET\n       handlers:\n         - console\n\nsettings.yml - Custom Settings (untracked)\n\n.. code-block:: yaml\n\n ---\n myproj:\n   databases:\n     primary_sql:\n       user: root\n       passwd: god\n     splunk:\n       user: real_user\n       passwd: pa$$word\n   flask_config:\n     SECRET_KEY: sdfasjksdfASFAS23423f@#$%!$#VR@%UQ%\n   logging_config:\n     handlers:\n       slack:\n         token: 123243294832104981209\n     root:\n       handlers:\n         - console\n         - slack\n\nExample package resource loading\n\n.. code-block:: python\n\n \"\"\"Parameters that can be passed are:\n  resource: The resource to load from the package (default: settings.yaml)\n  env: When set the yamldict will update with env variables (default: true)\n  prefix: Prefix for environment loading (default: None)\n  persist: When set the yamldict will only be loaded once. (default: true)\n \"\"\"\n yamlsettings.load('package://example')\n yamlsettings.load('package://example?resource=diff.yaml')\n yamlsettings.load('package://example?prefix=MY_FUN&persist=false')\n\n\nPlugins\n^^^^^^^\n\nThis project also supports plugins. The base project has two plugins:\n\n- file: Loads from the file system.\n- package: Loads settings from a package resource.\n\nExample Plugin:\n===============\n\nsetup.py\n\n.. code-block:: python\n\n from setuptools import setup\n\n setup(\n     name='yamlsettings-example',\n     version='1.0.0',\n     author='Kyle Walker',\n     author_email='KyleJamesWalker@gmail.com',\n     description='Quick Example',\n     requirements=['yamlsettings'],\n     py_modules=['yamlsettings_example'],\n     entry_points={\n         'yamlsettings10': [\n             'ext = yamlsettings_example:ZxcExtension',\n         ],\n     },\n )\n\nyamlsettings_example.py\n\n.. code-block:: python\n\n from yamlsettings.extensions.base import YamlSettingsExtension\n\n\n class ZxcExtension(YamlSettingsExtension):\n     \"\"\"Quick Example Plugin\n\n     Standard file opener, but will merge in values passed to kwargs\n     \"\"\"\n     protocols = ['zxc']\n\n     @classmethod\n     def load_target(cls, scheme, path, fragment, username,\n                     password, hostname, port, query,\n                     load_method, **kwargs):\n         full_path = (hostname or '') + path\n         obj = load_method(open(full_path, **query))\n\n         # Load all returns a generator list of configurations\n         many = isinstance(obj, types.GeneratorType)\n         obj = list(obj) if many else obj\n\n         if many:\n             for x in obj:\n                 x.update(kwargs)\n         else:\n             obj.update(kwargs)\n\n         return obj\n\nusage\n\n.. code-block:: python\n\n import yamlsettings\n yamlsettings.load(\"zxc://defaults.yaml\", foo='bar')\n\n # Note: this is automatically detected when the extension is installed\n # alternatively the extension can be manually registered with:\n yamlsettings.registry.add(ZxcExtension)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Yaml Settings Configuration Module",
    "version": "2.1.2",
    "project_urls": {
        "Homepage": "https://github.com/KyleJamesWalker/yamlsettings"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a6157435f84f3bb3c68c958be0c47cb696cbf2b762df3888b0c9d59fd1c5bb4",
                "md5": "f8df7c864e62fa1bf07ca147c6b015f8",
                "sha256": "848399ff432a4c998f6dde5778d6669ef58a0c7d9aa4187621cec6a3ffa1bfa0"
            },
            "downloads": -1,
            "filename": "yamlsettings-2.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8df7c864e62fa1bf07ca147c6b015f8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13714,
            "upload_time": "2024-07-12T23:28:51",
            "upload_time_iso_8601": "2024-07-12T23:28:51.907156Z",
            "url": "https://files.pythonhosted.org/packages/2a/61/57435f84f3bb3c68c958be0c47cb696cbf2b762df3888b0c9d59fd1c5bb4/yamlsettings-2.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00f3b6197c94ae1296855ed8e8ac85004d41a01990a9bf3f7cb32f2c854fc3cf",
                "md5": "710401ee4080875735f3e0c3005276bd",
                "sha256": "c86da6bc70e1a9051e582e47b273b703d8ecb49d0850da04c7774680d85aa22a"
            },
            "downloads": -1,
            "filename": "yamlsettings-2.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "710401ee4080875735f3e0c3005276bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13532,
            "upload_time": "2024-07-12T23:28:53",
            "upload_time_iso_8601": "2024-07-12T23:28:53.393855Z",
            "url": "https://files.pythonhosted.org/packages/00/f3/b6197c94ae1296855ed8e8ac85004d41a01990a9bf3f7cb32f2c854fc3cf/yamlsettings-2.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-12 23:28:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "KyleJamesWalker",
    "github_project": "yamlsettings",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "yamlsettings"
}
        
Elapsed time: 0.60647s