typing-validation: Validation using Type Hints
==============================================
.. image:: https://img.shields.io/badge/python-3.7+-green.svg
:target: https://docs.python.org/3.7/
:alt: Python versions
.. image:: https://img.shields.io/pypi/v/typing-validation.svg
:target: https://pypi.python.org/pypi/typing-validation/
:alt: PyPI version
.. image:: https://img.shields.io/pypi/status/typing-validation.svg
:target: https://pypi.python.org/pypi/typing-validation/
:alt: PyPI status
.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
:target: https://github.com/python/mypy
:alt: Checked with Mypy
.. image:: https://readthedocs.org/projects/typing-validation/badge/?version=latest
:target: https://typing-validation.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://github.com/hashberg-io/typing-validation/actions/workflows/python-pytest.yml/badge.svg
:target: https://github.com/hashberg-io/typing-validation/actions/workflows/python-pytest.yml
:alt: Python package status
.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square
:target: https://github.com/RichardLitt/standard-readme
:alt: standard-readme compliant
Typing-validation is a small library to perform runtime validation of Python objects using `PEP 484 type hints <https://www.python.org/dev/peps/pep-0484/>`_.
.. contents::
Install
-------
You can install the latest release from `PyPI <https://pypi.org/project/typing-validation/>`_ as follows:
.. code-block::
pip install --upgrade typing-validation
Usage
-----
The core functionality of this library is provided by the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function:
>>> from typing_validation import validate
The `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function is invoked with a value and a type as its arguments and it returns nothing when the given value is valid for the given type:
>>> validate(12, int)
True # no error raised => 12 is a valid int
If the value is invalid for the given type, the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function raises a `TypeError <https://docs.python.org/3/library/exceptions.html#TypeError>`_:
>>> validate(12, str)
TypeError: Runtime validation error raised by validate(val, t), details below.
For type <class 'str'>, invalid value: 12
For nested types (e.g. parametric collection/mapping types), the full chain of validation failures is shown by the type error:
>>> validate([0, 1, "hi"], list[int])
TypeError: Runtime validation error raised by validate(val, t), details below.
For type list[int], invalid value at idx: 2
For type <class 'int'>, invalid value: 'hi'
The function `is_valid` is a variant of the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function which returns `False` in case of validation failure, instead of raising `TypeError <https://docs.python.org/3/library/exceptions.html#TypeError>`_:
>>> from typing_validation import is_valid
>>> is_valid([0, 1, "hi"], list[int])
False
The function `latest_validation_failure <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation_failure.latest_validation_failure>`_ can be used to access detailed information immediately after a failure:
>>> from typing_validation import latest_validation_failure
>>> is_valid([0, 1, "hi"], list[int])
False
>>> failure = latest_validation_failure()
>>> print(failure)
Runtime validation error raised by validate(val, t), details below.
For type list[int], invalid value at idx: 2
For type <class 'int'>, invalid value: 'hi'
Please note that `latest_validation_failure <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation_failure.latest_validation_failure>`_ clears the internal failure logs after returning the latest failure, so the latter must be manually stored if it needs to be accessed multiple times.
API
---
For the full API documentation, see https://typing-validation.readthedocs.io/
Contributing
------------
Please see `<CONTRIBUTING.md>`_.
License
-------
`MIT © Hashberg Ltd. <LICENSE>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/hashberg-io/typing-validation",
"name": "typing-validation",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "hashberg",
"author_email": "sg495@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/d7/60/d5adede183c24549e8fdc941ec152efea42a4f580c159b702aabbf72b7d6/typing_validation-1.2.11.post4.tar.gz",
"platform": null,
"description": "\r\ntyping-validation: Validation using Type Hints\r\n==============================================\r\n\r\n.. image:: https://img.shields.io/badge/python-3.7+-green.svg\r\n :target: https://docs.python.org/3.7/\r\n :alt: Python versions\r\n\r\n.. image:: https://img.shields.io/pypi/v/typing-validation.svg\r\n :target: https://pypi.python.org/pypi/typing-validation/\r\n :alt: PyPI version\r\n\r\n.. image:: https://img.shields.io/pypi/status/typing-validation.svg\r\n :target: https://pypi.python.org/pypi/typing-validation/\r\n :alt: PyPI status\r\n\r\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\r\n :target: https://github.com/python/mypy\r\n :alt: Checked with Mypy\r\n\r\n.. image:: https://readthedocs.org/projects/typing-validation/badge/?version=latest\r\n :target: https://typing-validation.readthedocs.io/en/latest/?badge=latest\r\n :alt: Documentation Status\r\n\r\n.. image:: https://github.com/hashberg-io/typing-validation/actions/workflows/python-pytest.yml/badge.svg\r\n :target: https://github.com/hashberg-io/typing-validation/actions/workflows/python-pytest.yml\r\n :alt: Python package status\r\n\r\n.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square\r\n :target: https://github.com/RichardLitt/standard-readme\r\n :alt: standard-readme compliant\r\n\r\nTyping-validation is a small library to perform runtime validation of Python objects using `PEP 484 type hints <https://www.python.org/dev/peps/pep-0484/>`_.\r\n\r\n.. contents::\r\n\r\n\r\nInstall\r\n-------\r\n\r\nYou can install the latest release from `PyPI <https://pypi.org/project/typing-validation/>`_ as follows:\r\n\r\n.. code-block::\r\n\r\n pip install --upgrade typing-validation\r\n\r\n\r\nUsage\r\n-----\r\n\r\nThe core functionality of this library is provided by the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function:\r\n\r\n\r\n>>> from typing_validation import validate\r\n\r\nThe `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function is invoked with a value and a type as its arguments and it returns nothing when the given value is valid for the given type:\r\n\r\n>>> validate(12, int)\r\nTrue # no error raised => 12 is a valid int\r\n\r\nIf the value is invalid for the given type, the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function raises a `TypeError <https://docs.python.org/3/library/exceptions.html#TypeError>`_:\r\n\r\n>>> validate(12, str)\r\nTypeError: Runtime validation error raised by validate(val, t), details below.\r\nFor type <class 'str'>, invalid value: 12\r\n\r\nFor nested types (e.g. parametric collection/mapping types), the full chain of validation failures is shown by the type error:\r\n\r\n>>> validate([0, 1, \"hi\"], list[int])\r\nTypeError: Runtime validation error raised by validate(val, t), details below.\r\nFor type list[int], invalid value at idx: 2\r\n For type <class 'int'>, invalid value: 'hi'\r\n\r\n\r\nThe function `is_valid` is a variant of the `validate <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation.validate>`_ function which returns `False` in case of validation failure, instead of raising `TypeError <https://docs.python.org/3/library/exceptions.html#TypeError>`_:\r\n\r\n>>> from typing_validation import is_valid\r\n>>> is_valid([0, 1, \"hi\"], list[int])\r\nFalse\r\n\r\nThe function `latest_validation_failure <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation_failure.latest_validation_failure>`_ can be used to access detailed information immediately after a failure:\r\n\r\n>>> from typing_validation import latest_validation_failure\r\n>>> is_valid([0, 1, \"hi\"], list[int])\r\nFalse\r\n>>> failure = latest_validation_failure()\r\n>>> print(failure)\r\nRuntime validation error raised by validate(val, t), details below.\r\nFor type list[int], invalid value at idx: 2\r\n For type <class 'int'>, invalid value: 'hi'\r\n\r\nPlease note that `latest_validation_failure <https://typing-validation.readthedocs.io/en/latest/api/typing_validation.validation.html#typing_validation.validation_failure.latest_validation_failure>`_ clears the internal failure logs after returning the latest failure, so the latter must be manually stored if it needs to be accessed multiple times.\r\n\r\n\r\nAPI\r\n---\r\n\r\nFor the full API documentation, see https://typing-validation.readthedocs.io/\r\n\r\n\r\nContributing\r\n------------\r\n\r\nPlease see `<CONTRIBUTING.md>`_.\r\n\r\n\r\nLicense\r\n-------\r\n\r\n`MIT \u00a9 Hashberg Ltd. <LICENSE>`_\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple library for runtime type-checking.",
"version": "1.2.11.post4",
"project_urls": {
"Bug Tracker": "https://github.com/hashberg-io/typing-validation/issues",
"Homepage": "https://github.com/hashberg-io/typing-validation"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7d7263e3a07107232462dd585e91cdd8032669578b026bca44d76f307bb8c6c7",
"md5": "7a05bfdab78493e7c7b41c5db31f3c74",
"sha256": "73dd504ddebf5210e80d5f65ba9b30efbd0fa42f266728fda7c4f0ba335c699c"
},
"downloads": -1,
"filename": "typing_validation-1.2.11.post4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7a05bfdab78493e7c7b41c5db31f3c74",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 20748,
"upload_time": "2024-07-20T12:18:35",
"upload_time_iso_8601": "2024-07-20T12:18:35.119945Z",
"url": "https://files.pythonhosted.org/packages/7d/72/63e3a07107232462dd585e91cdd8032669578b026bca44d76f307bb8c6c7/typing_validation-1.2.11.post4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d760d5adede183c24549e8fdc941ec152efea42a4f580c159b702aabbf72b7d6",
"md5": "2c7a8d1cf6b220f95ad941df36ed1e6c",
"sha256": "7aed04ecfbda07e63b7266f90e5d096f96344f7facfe04bb081b21e4a9781670"
},
"downloads": -1,
"filename": "typing_validation-1.2.11.post4.tar.gz",
"has_sig": false,
"md5_digest": "2c7a8d1cf6b220f95ad941df36ed1e6c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 774691,
"upload_time": "2024-07-20T12:18:37",
"upload_time_iso_8601": "2024-07-20T12:18:37.284220Z",
"url": "https://files.pythonhosted.org/packages/d7/60/d5adede183c24549e8fdc941ec152efea42a4f580c159b702aabbf72b7d6/typing_validation-1.2.11.post4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-20 12:18:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hashberg-io",
"github_project": "typing-validation",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "typing-validation"
}