yapconf


Nameyapconf JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/loganasherjones/yapconf
SummaryYet Another Python Configuration
upload_time2022-03-30 00:29:26
maintainer
docs_urlNone
authorLogan Asher Jones
requires_python
licenseMIT license
keywords yapconf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            =======
Yapconf
=======


.. image:: https://img.shields.io/pypi/v/yapconf.svg
        :target: https://pypi.python.org/pypi/yapconf

.. image:: https://img.shields.io/travis/loganasherjones/yapconf.svg
        :target: https://travis-ci.org/loganasherjones/yapconf

.. image:: https://codecov.io/gh/loganasherjones/yapconf/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/loganasherjones/yapconf

.. image:: https://readthedocs.org/projects/yapconf/badge/?version=latest
        :target: https://yapconf.readthedocs.io/en/latest/?badge=latest
        :alt: Documentation Status

.. image:: https://pyup.io/repos/github/loganasherjones/yapconf/shield.svg
     :target: https://pyup.io/repos/github/loganasherjones/yapconf/
     :alt: Updates


Yet Another Python Configuration. A simple way to manage configurations for python applications.


Yapconf allows you to easily manage your python application's configuration. It handles everything involving your
application's configuration. Often times exposing your configuration in sensible ways can be difficult. You have to
consider loading order, and lots of boilerplate code to update your configuration correctly. Now what about CLI
support? Migrating old configs to the new config? Yapconf can help you.


Features
--------
Yapconf helps manage your python application's configuration

* JSON/YAML config file support
* Etcd config support
* Kubernetes ConfigMap support
* Argparse integration
* Environment Loading
* Configuration watching
* Migrate old configurations to new configurations
* Generate documentation for your configuration


Quick Start
-----------

To install Yapconf, run this command in your terminal:

.. code-block:: console

    $ pip install yapconf

Then you can use Yapconf yourself!


**Load your first config**

.. code-block:: python

    from yapconf import YapconfSpec

    # First define a specification
    spec_def = {
        "foo": {"type": "str", "default": "bar"},
    }
    my_spec = YapconfSpec(spec_def)

    # Now add your source
    my_spec.add_source('my yaml config', 'yaml', filename='./config.yaml')

    # Then load the configuration!
    config = my_spec.load_config('config.yaml')

    print(config.foo)
    print(config['foo'])

In this example ``load_config`` will look for the 'foo' value in the file
./config.yaml and will fall back to the default from the specification
definition ("bar") if it's not found there.

Try running with an empty file at ./config.yaml, and then try running with

.. code-block:: yaml

   foo: baz


**Load from Environment Variables**

.. code-block:: python

    from yapconf import YapconfSpec

    # First define a specification
    spec_def = {
        "foo-dash": {"type": "str", "default": "bar"},
    }
    my_spec = YapconfSpec(spec_def, env_prefix='MY_APP_')

    # Now add your source
    my_spec.add_source('env', 'environment')

    # Then load the configuration!
    config = my_spec.load_config('env')

    print(config.foo)
    print(config['foo'])

In this example ``load_config`` will look for the 'foo' value in the
environment and will fall back to the default from the specification
definition ("bar") if it's not found there.

Try running once, and then run ``export MY_APP_FOO_DASH=BAZ`` in the shell
and run again.

Note that the name yapconf is searching the environment for has been modified.
The env_prefix ``MY_APP_`` as been applied to the name, and the name itself has
been capitalized and converted to snake-case.


**Load from CLI arguments**

.. code-block:: python

    import argparse
    from yapconf import YapconfSpec

    # First define a specification
    spec_def = {
        "foo": {"type": "str", "default": "bar"},
    }
    my_spec = YapconfSpec(spec_def)

    # This will add --foo as an argument to your python program
    parser = argparse.ArgumentParser()
    my_spec.add_arguments(parser)

    # Now you can load these via load_config:
    cli_args = vars(parser.parse_args(sys.argv[1:]))
    config = my_spec.load_config(cli_args)

    print(config.foo)
    print(config['foo'])


**Load from multiple sources**

.. code-block:: python

    from yapconf import YapconfSpec

    # First define a specification
    spec_def = {
        "foo": {"type": "str", "default": "bar"},
    }
    my_spec = YapconfSpec(spec_def, env_prefix='MY_APP_')

    # Now add your sources (order does not matter)
    my_spec.add_source('env', 'environment')
    my_spec.add_source('my yaml file', 'yaml', filename='./config.yaml')

    # Now load your configuration using the sources in the order you want!
    config = my_spec.load_config('my yaml file', 'env')

    print(config.foo)
    print(config['foo'])

In this case ``load_config`` will look for 'foo' in ./config.yaml. If not
found it will look for ``MY_APP_FOO`` in the environment, and if stil not
found it will fall back to the default.
Since the 'my yaml file' label comes first in the load_config arguments
yapconf will look there for values first, even though add_source was
called with 'env' first.


**Watch your config for changes**

.. code-block:: python

    def my_handler(old_config, new_config):
        print("TODO: Something interesting goes here.")

    my_spec.spawn_watcher('config.yaml', target=my_handler)


**Generate documentation for your config**

.. code-block:: python

    # Show me some sweet Markdown documentation
    my_spec(spec.generate_documentation())

    # Or write it to a file
    spec.generate_documentation(output_file_name='configuration_docs.md')


For more detailed information and better walkthroughs, checkout the documentation!

Documentation
-------------
Documentation is available at https://yapconf.readthedocs.io


Credits
---------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage



=======
History
=======

0.3.7 (2019-12-02)
------------------
* Fixed broken test
* Adding CLI source
* Fixed adding cli_name to items

0.3.6 (2019-09-17)
------------------
* Adding `dump_data` to `__all__`

0.3.5 (2019-09-03)
------------------
* Adding initial support for loading specific config items.

0.3.4 (2019-09-02)
------------------
* Fixed deprecation warning (#96)


0.3.3 (2018-06-25)
------------------
* Fixed an issue with dumping unicode in python 2 (#82)

0.3.2 (2018-06-11)
------------------
* Fixed an issue with dumping box data to YAML (#78)

0.3.1 (2018-06-07)
------------------
* Fixed an issue with environment loading (#74)
* Fixed an issue with watching in-memory dictionaries (#75)

0.3.0 (2018-06-02)
------------------
* Fixed an issue where utf-8 migrations would break (#46)
* Added support for etcd (#47)
* Added support for kubernetes (#47)
* Added support for fallbacks for config values (#45)
* Added the ability to generate documentation for your configuration (#63)
* Added config watching capabilities (#36)

0.2.4 (2018-05-21)
------------------
* Flattened configs before loading (#54)
* Fixed bug where the ``fq_name`` was not correctly set for complex objects
* Added ``dump_kwargs`` to ``migrate_config`` (#53)
* Better error message when validation fails (#55)
* Made all argparse items optional (#42)
* Added support for ``long_description`` on config items (#44)
* Added support for ``validator`` on config items (#43)

0.2.3 (2018-04-03)
------------------
* Fixed Python2 unicode error (#41)

0.2.2 (2018-03-28)
------------------
* Fixed Python2 compatibility error (#35)

0.2.1 (2018-03-11)
------------------
* Added item to YapconfItemNotFound (#21)
* Removed pytest-runner from setup_requires (#22)

0.2.0 (2018-03-11)
------------------

* Added auto kebab-case for CLI arguments (#7)
* Added the flag to apply environment prefixes (#11)
* Added ``choices`` to item specification (#14)
* Added ``alt_env_names`` to item specification (#13)

0.1.1 (2018-02-08)
------------------

* Fixed bug where ``None`` was a respected value.

0.1.0 (2018-02-01)
------------------

* First release on PyPI.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/loganasherjones/yapconf",
    "name": "yapconf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "yapconf",
    "author": "Logan Asher Jones",
    "author_email": "loganasherjones@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/75/49/2bc8ccd5631db797d5f276fc098c5559395658aba9bc9268ddd167011acf/yapconf-1.0.0.tar.gz",
    "platform": null,
    "description": "=======\nYapconf\n=======\n\n\n.. image:: https://img.shields.io/pypi/v/yapconf.svg\n        :target: https://pypi.python.org/pypi/yapconf\n\n.. image:: https://img.shields.io/travis/loganasherjones/yapconf.svg\n        :target: https://travis-ci.org/loganasherjones/yapconf\n\n.. image:: https://codecov.io/gh/loganasherjones/yapconf/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/loganasherjones/yapconf\n\n.. image:: https://readthedocs.org/projects/yapconf/badge/?version=latest\n        :target: https://yapconf.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n.. image:: https://pyup.io/repos/github/loganasherjones/yapconf/shield.svg\n     :target: https://pyup.io/repos/github/loganasherjones/yapconf/\n     :alt: Updates\n\n\nYet Another Python Configuration. A simple way to manage configurations for python applications.\n\n\nYapconf allows you to easily manage your python application's configuration. It handles everything involving your\napplication's configuration. Often times exposing your configuration in sensible ways can be difficult. You have to\nconsider loading order, and lots of boilerplate code to update your configuration correctly. Now what about CLI\nsupport? Migrating old configs to the new config? Yapconf can help you.\n\n\nFeatures\n--------\nYapconf helps manage your python application's configuration\n\n* JSON/YAML config file support\n* Etcd config support\n* Kubernetes ConfigMap support\n* Argparse integration\n* Environment Loading\n* Configuration watching\n* Migrate old configurations to new configurations\n* Generate documentation for your configuration\n\n\nQuick Start\n-----------\n\nTo install Yapconf, run this command in your terminal:\n\n.. code-block:: console\n\n    $ pip install yapconf\n\nThen you can use Yapconf yourself!\n\n\n**Load your first config**\n\n.. code-block:: python\n\n    from yapconf import YapconfSpec\n\n    # First define a specification\n    spec_def = {\n        \"foo\": {\"type\": \"str\", \"default\": \"bar\"},\n    }\n    my_spec = YapconfSpec(spec_def)\n\n    # Now add your source\n    my_spec.add_source('my yaml config', 'yaml', filename='./config.yaml')\n\n    # Then load the configuration!\n    config = my_spec.load_config('config.yaml')\n\n    print(config.foo)\n    print(config['foo'])\n\nIn this example ``load_config`` will look for the 'foo' value in the file\n./config.yaml and will fall back to the default from the specification\ndefinition (\"bar\") if it's not found there.\n\nTry running with an empty file at ./config.yaml, and then try running with\n\n.. code-block:: yaml\n\n   foo: baz\n\n\n**Load from Environment Variables**\n\n.. code-block:: python\n\n    from yapconf import YapconfSpec\n\n    # First define a specification\n    spec_def = {\n        \"foo-dash\": {\"type\": \"str\", \"default\": \"bar\"},\n    }\n    my_spec = YapconfSpec(spec_def, env_prefix='MY_APP_')\n\n    # Now add your source\n    my_spec.add_source('env', 'environment')\n\n    # Then load the configuration!\n    config = my_spec.load_config('env')\n\n    print(config.foo)\n    print(config['foo'])\n\nIn this example ``load_config`` will look for the 'foo' value in the\nenvironment and will fall back to the default from the specification\ndefinition (\"bar\") if it's not found there.\n\nTry running once, and then run ``export MY_APP_FOO_DASH=BAZ`` in the shell\nand run again.\n\nNote that the name yapconf is searching the environment for has been modified.\nThe env_prefix ``MY_APP_`` as been applied to the name, and the name itself has\nbeen capitalized and converted to snake-case.\n\n\n**Load from CLI arguments**\n\n.. code-block:: python\n\n    import argparse\n    from yapconf import YapconfSpec\n\n    # First define a specification\n    spec_def = {\n        \"foo\": {\"type\": \"str\", \"default\": \"bar\"},\n    }\n    my_spec = YapconfSpec(spec_def)\n\n    # This will add --foo as an argument to your python program\n    parser = argparse.ArgumentParser()\n    my_spec.add_arguments(parser)\n\n    # Now you can load these via load_config:\n    cli_args = vars(parser.parse_args(sys.argv[1:]))\n    config = my_spec.load_config(cli_args)\n\n    print(config.foo)\n    print(config['foo'])\n\n\n**Load from multiple sources**\n\n.. code-block:: python\n\n    from yapconf import YapconfSpec\n\n    # First define a specification\n    spec_def = {\n        \"foo\": {\"type\": \"str\", \"default\": \"bar\"},\n    }\n    my_spec = YapconfSpec(spec_def, env_prefix='MY_APP_')\n\n    # Now add your sources (order does not matter)\n    my_spec.add_source('env', 'environment')\n    my_spec.add_source('my yaml file', 'yaml', filename='./config.yaml')\n\n    # Now load your configuration using the sources in the order you want!\n    config = my_spec.load_config('my yaml file', 'env')\n\n    print(config.foo)\n    print(config['foo'])\n\nIn this case ``load_config`` will look for 'foo' in ./config.yaml. If not\nfound it will look for ``MY_APP_FOO`` in the environment, and if stil not\nfound it will fall back to the default.\nSince the 'my yaml file' label comes first in the load_config arguments\nyapconf will look there for values first, even though add_source was\ncalled with 'env' first.\n\n\n**Watch your config for changes**\n\n.. code-block:: python\n\n    def my_handler(old_config, new_config):\n        print(\"TODO: Something interesting goes here.\")\n\n    my_spec.spawn_watcher('config.yaml', target=my_handler)\n\n\n**Generate documentation for your config**\n\n.. code-block:: python\n\n    # Show me some sweet Markdown documentation\n    my_spec(spec.generate_documentation())\n\n    # Or write it to a file\n    spec.generate_documentation(output_file_name='configuration_docs.md')\n\n\nFor more detailed information and better walkthroughs, checkout the documentation!\n\nDocumentation\n-------------\nDocumentation is available at https://yapconf.readthedocs.io\n\n\nCredits\n---------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\n\n\n=======\nHistory\n=======\n\n0.3.7 (2019-12-02)\n------------------\n* Fixed broken test\n* Adding CLI source\n* Fixed adding cli_name to items\n\n0.3.6 (2019-09-17)\n------------------\n* Adding `dump_data` to `__all__`\n\n0.3.5 (2019-09-03)\n------------------\n* Adding initial support for loading specific config items.\n\n0.3.4 (2019-09-02)\n------------------\n* Fixed deprecation warning (#96)\n\n\n0.3.3 (2018-06-25)\n------------------\n* Fixed an issue with dumping unicode in python 2 (#82)\n\n0.3.2 (2018-06-11)\n------------------\n* Fixed an issue with dumping box data to YAML (#78)\n\n0.3.1 (2018-06-07)\n------------------\n* Fixed an issue with environment loading (#74)\n* Fixed an issue with watching in-memory dictionaries (#75)\n\n0.3.0 (2018-06-02)\n------------------\n* Fixed an issue where utf-8 migrations would break (#46)\n* Added support for etcd (#47)\n* Added support for kubernetes (#47)\n* Added support for fallbacks for config values (#45)\n* Added the ability to generate documentation for your configuration (#63)\n* Added config watching capabilities (#36)\n\n0.2.4 (2018-05-21)\n------------------\n* Flattened configs before loading (#54)\n* Fixed bug where the ``fq_name`` was not correctly set for complex objects\n* Added ``dump_kwargs`` to ``migrate_config`` (#53)\n* Better error message when validation fails (#55)\n* Made all argparse items optional (#42)\n* Added support for ``long_description`` on config items (#44)\n* Added support for ``validator`` on config items (#43)\n\n0.2.3 (2018-04-03)\n------------------\n* Fixed Python2 unicode error (#41)\n\n0.2.2 (2018-03-28)\n------------------\n* Fixed Python2 compatibility error (#35)\n\n0.2.1 (2018-03-11)\n------------------\n* Added item to YapconfItemNotFound (#21)\n* Removed pytest-runner from setup_requires (#22)\n\n0.2.0 (2018-03-11)\n------------------\n\n* Added auto kebab-case for CLI arguments (#7)\n* Added the flag to apply environment prefixes (#11)\n* Added ``choices`` to item specification (#14)\n* Added ``alt_env_names`` to item specification (#13)\n\n0.1.1 (2018-02-08)\n------------------\n\n* Fixed bug where ``None`` was a respected value.\n\n0.1.0 (2018-02-01)\n------------------\n\n* First release on PyPI.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Yet Another Python Configuration",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/loganasherjones/yapconf"
    },
    "split_keywords": [
        "yapconf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2cc9c685a81873c4078e1bcd4257d0bb18b806efefd30789a94caab591c4671",
                "md5": "f0967b13d433dc21613d38f1c8ce1419",
                "sha256": "20453746e4e7fdd8329a1a513d0a9b245306bb5e053df0fe9dd2acc37fd28c67"
            },
            "downloads": -1,
            "filename": "yapconf-1.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0967b13d433dc21613d38f1c8ce1419",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 32375,
            "upload_time": "2022-03-30T00:29:24",
            "upload_time_iso_8601": "2022-03-30T00:29:24.849997Z",
            "url": "https://files.pythonhosted.org/packages/f2/cc/9c685a81873c4078e1bcd4257d0bb18b806efefd30789a94caab591c4671/yapconf-1.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75492bc8ccd5631db797d5f276fc098c5559395658aba9bc9268ddd167011acf",
                "md5": "7ac908b31a487f14e6dbdd9a77bed13d",
                "sha256": "8154b78cc3ac3724982f124844c4593109c8f0ab62b0e0299c9853097a4b8b21"
            },
            "downloads": -1,
            "filename": "yapconf-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7ac908b31a487f14e6dbdd9a77bed13d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 64678,
            "upload_time": "2022-03-30T00:29:26",
            "upload_time_iso_8601": "2022-03-30T00:29:26.801403Z",
            "url": "https://files.pythonhosted.org/packages/75/49/2bc8ccd5631db797d5f276fc098c5559395658aba9bc9268ddd167011acf/yapconf-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-30 00:29:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "loganasherjones",
    "github_project": "yapconf",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "yapconf"
}
        
Elapsed time: 0.38358s