configchecker


Nameconfigchecker JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/victorsamun/configvalidator
SummaryINI-config validator
upload_time2023-10-20 20:50:37
maintainer
docs_urlNone
authorSamun Victor
requires_python
licenseMIT
keywords configparser configchecker checking validate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            configchecker
-------------
|pyversions|

|DwnMonth| |DwnWeek| |DwnDay|

|license|

This module helps to check ``configparser``-loaded configurations.

Usage
=====

1. Initialize description of valid configuration:
   ``schema = configchecker.ConfigSchema()``
2. Add an information of possible sections by calling ``schema.section`` with section name validator and boolean flag „section required“.
3. In every section describe possible section's values by calling ``sect.value``.

Name/value validators
=====================

There are basic validators:

* ``ItemDefaultValidator`` — always returns true
* ``ItemStringValidator`` — checks if a string equals to given (probably, case-insensitive)
* ``ItemRegexValidator`` — checks matching a string to given regexp
* ``ItemNumberValidator`` — checks that a string is a non-negative integer

And validator-composers which allow to create more complex checks:

* ``ItemNotValidator``, ``ItemAndValidator``, ``ItemOrValidator`` — first-order logic on validators
* ``ItemCountValidator`` — takes a validator and a function that check number of validator's true positives (i.e. returns ``True``)

Examples
========

.. code-block:: py

    import configparser
    import configchecker as v

    config = configparser.ConfigParser()
    config.read_file("config")

    schema = v.ConfigSchema()

    # Section with name „REQUIRED“ will be mandatory
    with schema.section("REQUIRED") as s:
        # It must have keys matching regexp r'item_\d+' and numeric value and nothing more
        s.value(v.ItemRegexValidator(r'item_\d+', value_val=v.ItemNumberValidator()).no_other()

    # Section with name r'OPT_\w+' (check by regexp) will be optional
    with schema.section(v.ItemRegexValidator(r'OPT_\w+'), required=False) as s:
        # And it may have anything
        pass

    # Other sections will be restricted
    schema.no_other()

    # Run checks
    v.ConfigSchemaValidator(schema).validate(config)


Also, you can find lots of examples in tests (``test_configchecker.py``)


Author
======

Samun Victor, victor.samun@gmail.com

.. |license| image::  https://img.shields.io/pypi/l/configchecker.svg
   :target: https://github.com/victorsamun/configvalidator/blob/master/LICENSE
.. |DwnMonth| image:: https://img.shields.io/pypi/dm/configchecker.svg
.. |DwnWeek| image:: https://img.shields.io/pypi/dw/configchecker.svg
.. |DwnDay| image:: https://img.shields.io/pypi/dd/configchecker.svg
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/configchecker.svg

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/victorsamun/configvalidator",
    "name": "configchecker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "configparser configchecker checking validate",
    "author": "Samun Victor",
    "author_email": "victor.samun@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e1/19/042d9fdfa5b686e77ae7af721a85700abf8cff37beb5bc486817df7d29bc/configchecker-1.0.1.tar.gz",
    "platform": null,
    "description": "configchecker\n-------------\n|pyversions|\n\n|DwnMonth| |DwnWeek| |DwnDay|\n\n|license|\n\nThis module helps to check ``configparser``-loaded configurations.\n\nUsage\n=====\n\n1. Initialize description of valid configuration:\n   ``schema = configchecker.ConfigSchema()``\n2. Add an information of possible sections by calling ``schema.section`` with section name validator and boolean flag \u201esection required\u201c.\n3. In every section describe possible section's values by calling ``sect.value``.\n\nName/value validators\n=====================\n\nThere are basic validators:\n\n* ``ItemDefaultValidator`` \u2014 always returns true\n* ``ItemStringValidator`` \u2014 checks if a string equals to given (probably, case-insensitive)\n* ``ItemRegexValidator`` \u2014 checks matching a string to given regexp\n* ``ItemNumberValidator`` \u2014 checks that a string is a non-negative integer\n\nAnd validator-composers which allow to create more complex checks:\n\n* ``ItemNotValidator``, ``ItemAndValidator``, ``ItemOrValidator`` \u2014 first-order logic on validators\n* ``ItemCountValidator`` \u2014 takes a validator and a function that check number of validator's true positives (i.e. returns ``True``)\n\nExamples\n========\n\n.. code-block:: py\n\n    import configparser\n    import configchecker as v\n\n    config = configparser.ConfigParser()\n    config.read_file(\"config\")\n\n    schema = v.ConfigSchema()\n\n    # Section with name \u201eREQUIRED\u201c will be mandatory\n    with schema.section(\"REQUIRED\") as s:\n        # It must have keys matching regexp r'item_\\d+' and numeric value and nothing more\n        s.value(v.ItemRegexValidator(r'item_\\d+', value_val=v.ItemNumberValidator()).no_other()\n\n    # Section with name r'OPT_\\w+' (check by regexp) will be optional\n    with schema.section(v.ItemRegexValidator(r'OPT_\\w+'), required=False) as s:\n        # And it may have anything\n        pass\n\n    # Other sections will be restricted\n    schema.no_other()\n\n    # Run checks\n    v.ConfigSchemaValidator(schema).validate(config)\n\n\nAlso, you can find lots of examples in tests (``test_configchecker.py``)\n\n\nAuthor\n======\n\nSamun Victor, victor.samun@gmail.com\n\n.. |license| image::  https://img.shields.io/pypi/l/configchecker.svg\n   :target: https://github.com/victorsamun/configvalidator/blob/master/LICENSE\n.. |DwnMonth| image:: https://img.shields.io/pypi/dm/configchecker.svg\n.. |DwnWeek| image:: https://img.shields.io/pypi/dw/configchecker.svg\n.. |DwnDay| image:: https://img.shields.io/pypi/dd/configchecker.svg\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/configchecker.svg\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "INI-config validator",
    "version": "1.0.1",
    "project_urls": {
        "Download": "https://github.com/victorsamun/configvalidator/archive/master.zip",
        "Homepage": "https://github.com/victorsamun/configvalidator"
    },
    "split_keywords": [
        "configparser",
        "configchecker",
        "checking",
        "validate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "65b2a0aa401877bdfbd0d30e5c6356ddf43c2c07469a124b20dfba93908fa8f6",
                "md5": "8573f854a1ab63443389e0810f1d211d",
                "sha256": "3a06c341921e1dc839dab0e5135cca60310a4b617d3e2f1df7dd9cfd3ed808c0"
            },
            "downloads": -1,
            "filename": "configchecker-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8573f854a1ab63443389e0810f1d211d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5759,
            "upload_time": "2023-10-20T20:50:36",
            "upload_time_iso_8601": "2023-10-20T20:50:36.016145Z",
            "url": "https://files.pythonhosted.org/packages/65/b2/a0aa401877bdfbd0d30e5c6356ddf43c2c07469a124b20dfba93908fa8f6/configchecker-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e119042d9fdfa5b686e77ae7af721a85700abf8cff37beb5bc486817df7d29bc",
                "md5": "783693ce6fe1b952a09dd6d19fde7d6f",
                "sha256": "953f7d230967f096e3a72934674fab67eb4aa39ce2c96ddd0cee2edba413605d"
            },
            "downloads": -1,
            "filename": "configchecker-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "783693ce6fe1b952a09dd6d19fde7d6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6920,
            "upload_time": "2023-10-20T20:50:37",
            "upload_time_iso_8601": "2023-10-20T20:50:37.925523Z",
            "url": "https://files.pythonhosted.org/packages/e1/19/042d9fdfa5b686e77ae7af721a85700abf8cff37beb5bc486817df7d29bc/configchecker-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-20 20:50:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "victorsamun",
    "github_project": "configvalidator",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "configchecker"
}
        
Elapsed time: 2.18340s