validator.py


Namevalidator.py JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/mansam/validator.py
SummaryA library for appling schemas to data structures.
upload_time2019-01-30 20:43:22
maintainer
docs_urlNone
authorSamuel "mansam" Lucidi
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            validator.py |Build Status| |PyPI version| |Bitdeli Badge|
==========================================================

Schemas for data structures.

`Documentation <http://validatorpy.readthedocs.org/en/latest/index.html>`__
---------------------------------------------------------------------------

This README has some basic usage information, but more detailed
documentation may be found at
`ReadTheDocs <http://validatorpy.readthedocs.org/en/latest/index.html>`__.

Usage Example
-------------

First, install it from PyPI.

::

    pip install validator.py

.. code:: python


    from validator import Required, Not, Truthy, Blank, Range, Equals, In, validate

    # let's say that my dictionary needs to meet the following rules...
    rules = {
        "foo": [Required, Equals(123)],
        "bar": [Required, Truthy()],
        "baz": [In(["spam", "eggs", "bacon"])],
        "qux": [Not(Range(1, 100))] # by default, Range is inclusive
    }

    # then this following dict would pass:
    passes = {
        "foo": 123,
        "bar": True, # or a non-empty string, or a non-zero int, etc...
        "baz": "spam",
        "qux": 101
    }
    print validate(rules, passes)
    # (True, {}) 

    # but this one would fail
    fails = {
        "foo": 321,
        "bar": False, # or 0, or [], or an empty string, etc...
        "baz": "barf",
        "qux": 99
    }
    print validate(rules, fails)
    # (False,
    #  {
    #  'foo': ["must be equal to '123'"],
    #  'bar': ['must be True-equivalent value'],
    #  'baz': ["must be one of ['spam', 'eggs', 'bacon']"],
    #  'qux': ['must not fall between 1 and 100']
    #  })

.. |Build Status| image:: https://travis-ci.org/mansam/validator.py.png?branch=master
   :target: https://travis-ci.org/mansam/validator.py
.. |PyPI version| image:: https://badge.fury.io/py/validator.py.png
   :target: http://badge.fury.io/py/validator.py
.. |Bitdeli Badge| image:: https://d2weczhvl823v0.cloudfront.net/mansam/validator.py/trend.png
   :target: https://bitdeli.com/free



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mansam/validator.py",
    "name": "validator.py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Samuel \"mansam\" Lucidi",
    "author_email": "sam@samlucidi.com",
    "download_url": "https://files.pythonhosted.org/packages/20/fb/546ac431d08ea860f66ad4862c87f5ef0bc89485100ee63f82faf5480925/validator.py-1.3.0.tar.gz",
    "platform": "",
    "description": "validator.py |Build Status| |PyPI version| |Bitdeli Badge|\n==========================================================\n\nSchemas for data structures.\n\n`Documentation <http://validatorpy.readthedocs.org/en/latest/index.html>`__\n---------------------------------------------------------------------------\n\nThis README has some basic usage information, but more detailed\ndocumentation may be found at\n`ReadTheDocs <http://validatorpy.readthedocs.org/en/latest/index.html>`__.\n\nUsage Example\n-------------\n\nFirst, install it from PyPI.\n\n::\n\n    pip install validator.py\n\n.. code:: python\n\n\n    from validator import Required, Not, Truthy, Blank, Range, Equals, In, validate\n\n    # let's say that my dictionary needs to meet the following rules...\n    rules = {\n        \"foo\": [Required, Equals(123)],\n        \"bar\": [Required, Truthy()],\n        \"baz\": [In([\"spam\", \"eggs\", \"bacon\"])],\n        \"qux\": [Not(Range(1, 100))] # by default, Range is inclusive\n    }\n\n    # then this following dict would pass:\n    passes = {\n        \"foo\": 123,\n        \"bar\": True, # or a non-empty string, or a non-zero int, etc...\n        \"baz\": \"spam\",\n        \"qux\": 101\n    }\n    print validate(rules, passes)\n    # (True, {}) \n\n    # but this one would fail\n    fails = {\n        \"foo\": 321,\n        \"bar\": False, # or 0, or [], or an empty string, etc...\n        \"baz\": \"barf\",\n        \"qux\": 99\n    }\n    print validate(rules, fails)\n    # (False,\n    #  {\n    #  'foo': [\"must be equal to '123'\"],\n    #  'bar': ['must be True-equivalent value'],\n    #  'baz': [\"must be one of ['spam', 'eggs', 'bacon']\"],\n    #  'qux': ['must not fall between 1 and 100']\n    #  })\n\n.. |Build Status| image:: https://travis-ci.org/mansam/validator.py.png?branch=master\n   :target: https://travis-ci.org/mansam/validator.py\n.. |PyPI version| image:: https://badge.fury.io/py/validator.py.png\n   :target: http://badge.fury.io/py/validator.py\n.. |Bitdeli Badge| image:: https://d2weczhvl823v0.cloudfront.net/mansam/validator.py/trend.png\n   :target: https://bitdeli.com/free\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for appling schemas to data structures.",
    "version": "1.3.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b379d6e61f6876be260d1bd17fe58f11a1219196b15bfd67eb0939650e0680c4",
                "md5": "d90c49747e26c0716a63971c4989ba16",
                "sha256": "1bb388c6228e9cea665bd879372e44842baf63dda0751a99989068e4ac61ba21"
            },
            "downloads": -1,
            "filename": "validator.py-1.3.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d90c49747e26c0716a63971c4989ba16",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8246,
            "upload_time": "2019-01-30T20:43:20",
            "upload_time_iso_8601": "2019-01-30T20:43:20.133635Z",
            "url": "https://files.pythonhosted.org/packages/b3/79/d6e61f6876be260d1bd17fe58f11a1219196b15bfd67eb0939650e0680c4/validator.py-1.3.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20fb546ac431d08ea860f66ad4862c87f5ef0bc89485100ee63f82faf5480925",
                "md5": "b8a1a74e6e21e304101b9749d6c547d7",
                "sha256": "ab3b631630bcbc9b77735e81f7fd11fb20d31eab32ad74d3cdac2ba6e138037e"
            },
            "downloads": -1,
            "filename": "validator.py-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b8a1a74e6e21e304101b9749d6c547d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7206,
            "upload_time": "2019-01-30T20:43:22",
            "upload_time_iso_8601": "2019-01-30T20:43:22.803376Z",
            "url": "https://files.pythonhosted.org/packages/20/fb/546ac431d08ea860f66ad4862c87f5ef0bc89485100ee63f82faf5480925/validator.py-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-01-30 20:43:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mansam",
    "github_project": "validator.py",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "validator.py"
}
        
Elapsed time: 0.09270s