typepy


Nametypepy JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/thombashi/typepy
Summarytypepy is a Python library for variable type checker/validator/converter at a run time.
upload_time2023-06-10 13:28:17
maintainer
docs_urlNone
authorTsuyoshi Hombashi
requires_python>=3.7
licenseMIT License
keywords library type-checking type-conversion validator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. contents:: **typepy**
   :backlinks: top
   :depth: 2

Summary
=========
`typepy <https://github.com/thombashi/typepy>`__ is a Python library for variable type checker/validator/converter at a run time.

.. image:: https://badge.fury.io/py/typepy.svg
    :target: https://badge.fury.io/py/typepy
    :alt: PyPI package version

.. image:: https://anaconda.org/conda-forge/typepy/badges/version.svg
    :target: https://anaconda.org/conda-forge/typepy
    :alt: conda-forge package version

.. image:: https://img.shields.io/pypi/pyversions/typepy.svg
    :target: https://pypi.org/project/typepy
    :alt: Supported Python versions

.. image:: https://img.shields.io/pypi/implementation/typepy.svg
    :target: https://pypi.org/project/typepy
    :alt: Supported Python implementations

.. image:: https://github.com/thombashi/typepy/workflows/Tests/badge.svg
    :target: https://github.com/thombashi/typepy/actions?query=workflow%3ATests
    :alt: Linux/macOS/Windows CI status

.. image:: https://coveralls.io/repos/github/thombashi/typepy/badge.svg?branch=master
    :target: https://coveralls.io/github/thombashi/typepy?branch=master
    :alt: Test coverage

.. image:: https://github.com/thombashi/typepy/actions/workflows/github-code-scanning/codeql/badge.svg
    :target: https://github.com/thombashi/typepy/actions/workflows/github-code-scanning/codeql
    :alt: CodeQL

Features
==========
- checking a value type
- validate a value for a type
- convert a value from one type to the other type

The correspondence between Python types and ``typepy`` classes are as follows:

.. table:: Supported Types

    ================================================  =======================================================================================================
    Python Type                                       typepy: Type Class
    ================================================  =======================================================================================================
    ``bool``                                          `Bool <https://typepy.rtfd.io/en/latest/pages/reference/type.html#bool-type>`__
    ``datetime``                                      `DateTime <https://typepy.rtfd.io/en/latest/pages/reference/type.html#datetime-type>`__
    ``dict``                                          `Dictionary <https://typepy.rtfd.io/en/latest/pages/reference/type.html#dictionary-type>`__
    ``float``/``decimal.Decimal`` (not infinity/NaN)  `RealNumber <https://typepy.rtfd.io/en/latest/pages/reference/type.html#real-number-type>`__
    ``float``/``decimal.Decimal`` (infinity)          `Infinity <https://typepy.rtfd.io/en/latest/pages/reference/type.html#infinity-type>`__
    ``float``/``decimal.Decimal`` (NaN)               `Nan <https://typepy.rtfd.io/en/latest/pages/reference/type.html#nan-type>`__
    ``int``                                           `Integer <https://typepy.rtfd.io/en/latest/pages/reference/type.html#integer-type>`__
    ``list``                                          `List <https://typepy.rtfd.io/en/latest/pages/reference/type.html#list-type>`__
    ``None``                                          `None <https://typepy.rtfd.io/en/latest/pages/reference/type.html#none-type>`__
    ``str`` (not null)                                `String <https://typepy.rtfd.io/en/latest/pages/reference/type.html#string-type>`__
    ``str`` (null)                                    `NullString <https://typepy.rtfd.io/en/latest/pages/reference/type.html#null-string-type>`__
    ``str`` (IP address)                              `IpAddress <https://typepy.rtfd.io/en/latest/pages/reference/type.html#ip-address-type>`__
    ================================================  =======================================================================================================

Installation
============

Installation: pip
------------------------------
::

    pip install typepy

Install additional dependency packages with the following command if using ``typepy.DateTime`` class

::

    pip install typepy[datetime]

Installation: conda
------------------------------
::

    conda install -c conda-forge typepy

Installation: apt
------------------------------
::

    sudo add-apt-repository ppa:thombashi/ppa
    sudo apt update
    sudo apt install python3-typepy


Dependencies
============
- Python 3.7+
- `Python package dependencies (automatically installed) <https://github.com/thombashi/typepy/network/dependencies>`__

Optional dependencies
----------------------------------
These packages can be installed via ``pip install typepy[datetime]``:

- `python-dateutil <https://dateutil.readthedocs.io/en/stable/>`__
- `pytz <https://pypi.org/project/pytz/>`__

Usage
=======
Type Check Method
----------------------
:Examples:
    .. code-block:: pycon

        >>> from typepy import Integer
        >>> Integer(1).is_type()
        True
        >>> Integer(1.1).is_type()
        False


Type Validation Method
--------------------------------------------
:Examples:
    .. code-block:: pycon

        >>> from typepy import Integer
        >>> Integer(1).validate()
        >>> try:
        ...     Integer(1.1).validate()
        ... except TypeError as e:
        ...     # validate() raised TypeError when the value unmatched the type class
        ...     print(e)
        ...
        invalid value type: expected=INTEGER, actual=<type 'float'>


Type Conversion Methods
--------------------------------------------

convert method
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Examples:
    .. code-block:: pycon

        >>> from typepy import Integer, TypeConversionError
        >>> Integer("1").convert()
        1
        >>> try:
        ...     Integer(1.1).convert()
        ... except TypeConversionError as e:
        ...     # convert() raised TypeConversionError when conversion failed
        ...     print(e)
        ...
        failed to convert from float to INTEGER

try_convert method
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Examples:
    .. code-block:: pycon

        >>> from typepy import Integer
        >>> Integer("1").try_convert()
        1
        >>> print(Integer(1.1).try_convert())  # try_convert() returned None when conversion failed
        None

force_convert
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Examples:
    .. code-block:: pycon

        >>> from typepy import Integer, TypeConversionError
        >>> Integer("1").force_convert()  # force_convert() forcibly convert the value
        1
        >>> Integer(1.1).force_convert()
        1
        >>> try:
        ...     Integer("abc").force_convert()
        ... except TypeConversionError as e:
        ...     # force_convert() raised TypeConversionError when the value was not convertible
        ...     print(e)
        ...
        failed to force_convert to int: type=<class 'str'>


For more information
--------------------------------------------
Type check/validate/convert results differed according to
``strict_level`` value which can pass to typepy class constructors as an argument.
More information can be found in the
`API reference <https://typepy.rtfd.io/en/latest/pages/reference/index.html>`__.

Documentation
===============
https://typepy.rtfd.io/


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thombashi/typepy",
    "name": "typepy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "library,type-checking,type-conversion,validator",
    "author": "Tsuyoshi Hombashi",
    "author_email": "tsuyoshi.hombashi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/68/bb1320314d249de81ea5ec77092d9266dbbc05f91422e87266dc52beb484/typepy-1.3.1.tar.gz",
    "platform": null,
    "description": ".. contents:: **typepy**\n   :backlinks: top\n   :depth: 2\n\nSummary\n=========\n`typepy <https://github.com/thombashi/typepy>`__ is a Python library for variable type checker/validator/converter at a run time.\n\n.. image:: https://badge.fury.io/py/typepy.svg\n    :target: https://badge.fury.io/py/typepy\n    :alt: PyPI package version\n\n.. image:: https://anaconda.org/conda-forge/typepy/badges/version.svg\n    :target: https://anaconda.org/conda-forge/typepy\n    :alt: conda-forge package version\n\n.. image:: https://img.shields.io/pypi/pyversions/typepy.svg\n    :target: https://pypi.org/project/typepy\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/implementation/typepy.svg\n    :target: https://pypi.org/project/typepy\n    :alt: Supported Python implementations\n\n.. image:: https://github.com/thombashi/typepy/workflows/Tests/badge.svg\n    :target: https://github.com/thombashi/typepy/actions?query=workflow%3ATests\n    :alt: Linux/macOS/Windows CI status\n\n.. image:: https://coveralls.io/repos/github/thombashi/typepy/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/typepy?branch=master\n    :alt: Test coverage\n\n.. image:: https://github.com/thombashi/typepy/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/typepy/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\nFeatures\n==========\n- checking a value type\n- validate a value for a type\n- convert a value from one type to the other type\n\nThe correspondence between Python types and ``typepy`` classes are as follows:\n\n.. table:: Supported Types\n\n    ================================================  =======================================================================================================\n    Python Type                                       typepy: Type Class\n    ================================================  =======================================================================================================\n    ``bool``                                          `Bool <https://typepy.rtfd.io/en/latest/pages/reference/type.html#bool-type>`__\n    ``datetime``                                      `DateTime <https://typepy.rtfd.io/en/latest/pages/reference/type.html#datetime-type>`__\n    ``dict``                                          `Dictionary <https://typepy.rtfd.io/en/latest/pages/reference/type.html#dictionary-type>`__\n    ``float``/``decimal.Decimal`` (not infinity/NaN)  `RealNumber <https://typepy.rtfd.io/en/latest/pages/reference/type.html#real-number-type>`__\n    ``float``/``decimal.Decimal`` (infinity)          `Infinity <https://typepy.rtfd.io/en/latest/pages/reference/type.html#infinity-type>`__\n    ``float``/``decimal.Decimal`` (NaN)               `Nan <https://typepy.rtfd.io/en/latest/pages/reference/type.html#nan-type>`__\n    ``int``                                           `Integer <https://typepy.rtfd.io/en/latest/pages/reference/type.html#integer-type>`__\n    ``list``                                          `List <https://typepy.rtfd.io/en/latest/pages/reference/type.html#list-type>`__\n    ``None``                                          `None <https://typepy.rtfd.io/en/latest/pages/reference/type.html#none-type>`__\n    ``str`` (not null)                                `String <https://typepy.rtfd.io/en/latest/pages/reference/type.html#string-type>`__\n    ``str`` (null)                                    `NullString <https://typepy.rtfd.io/en/latest/pages/reference/type.html#null-string-type>`__\n    ``str`` (IP address)                              `IpAddress <https://typepy.rtfd.io/en/latest/pages/reference/type.html#ip-address-type>`__\n    ================================================  =======================================================================================================\n\nInstallation\n============\n\nInstallation: pip\n------------------------------\n::\n\n    pip install typepy\n\nInstall additional dependency packages with the following command if using ``typepy.DateTime`` class\n\n::\n\n    pip install typepy[datetime]\n\nInstallation: conda\n------------------------------\n::\n\n    conda install -c conda-forge typepy\n\nInstallation: apt\n------------------------------\n::\n\n    sudo add-apt-repository ppa:thombashi/ppa\n    sudo apt update\n    sudo apt install python3-typepy\n\n\nDependencies\n============\n- Python 3.7+\n- `Python package dependencies (automatically installed) <https://github.com/thombashi/typepy/network/dependencies>`__\n\nOptional dependencies\n----------------------------------\nThese packages can be installed via ``pip install typepy[datetime]``:\n\n- `python-dateutil <https://dateutil.readthedocs.io/en/stable/>`__\n- `pytz <https://pypi.org/project/pytz/>`__\n\nUsage\n=======\nType Check Method\n----------------------\n:Examples:\n    .. code-block:: pycon\n\n        >>> from typepy import Integer\n        >>> Integer(1).is_type()\n        True\n        >>> Integer(1.1).is_type()\n        False\n\n\nType Validation Method\n--------------------------------------------\n:Examples:\n    .. code-block:: pycon\n\n        >>> from typepy import Integer\n        >>> Integer(1).validate()\n        >>> try:\n        ...     Integer(1.1).validate()\n        ... except TypeError as e:\n        ...     # validate() raised TypeError when the value unmatched the type class\n        ...     print(e)\n        ...\n        invalid value type: expected=INTEGER, actual=<type 'float'>\n\n\nType Conversion Methods\n--------------------------------------------\n\nconvert method\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n:Examples:\n    .. code-block:: pycon\n\n        >>> from typepy import Integer, TypeConversionError\n        >>> Integer(\"1\").convert()\n        1\n        >>> try:\n        ...     Integer(1.1).convert()\n        ... except TypeConversionError as e:\n        ...     # convert() raised TypeConversionError when conversion failed\n        ...     print(e)\n        ...\n        failed to convert from float to INTEGER\n\ntry_convert method\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n:Examples:\n    .. code-block:: pycon\n\n        >>> from typepy import Integer\n        >>> Integer(\"1\").try_convert()\n        1\n        >>> print(Integer(1.1).try_convert())  # try_convert() returned None when conversion failed\n        None\n\nforce_convert\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n:Examples:\n    .. code-block:: pycon\n\n        >>> from typepy import Integer, TypeConversionError\n        >>> Integer(\"1\").force_convert()  # force_convert() forcibly convert the value\n        1\n        >>> Integer(1.1).force_convert()\n        1\n        >>> try:\n        ...     Integer(\"abc\").force_convert()\n        ... except TypeConversionError as e:\n        ...     # force_convert() raised TypeConversionError when the value was not convertible\n        ...     print(e)\n        ...\n        failed to force_convert to int: type=<class 'str'>\n\n\nFor more information\n--------------------------------------------\nType check/validate/convert results differed according to\n``strict_level`` value which can pass to typepy class constructors as an argument.\nMore information can be found in the\n`API reference <https://typepy.rtfd.io/en/latest/pages/reference/index.html>`__.\n\nDocumentation\n===============\nhttps://typepy.rtfd.io/\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "typepy is a Python library for variable type checker/validator/converter at a run time.",
    "version": "1.3.1",
    "project_urls": {
        "Changlog": "https://github.com/thombashi/typepy/releases",
        "Documentation": "https://typepy.rtfd.io/",
        "Homepage": "https://github.com/thombashi/typepy",
        "Source": "https://github.com/thombashi/typepy",
        "Tracker": "https://github.com/thombashi/typepy/issues"
    },
    "split_keywords": [
        "library",
        "type-checking",
        "type-conversion",
        "validator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f310c7a66aa315cc8b2d1915fdd163283ba704307d7c0cf15b31e08c51aedba",
                "md5": "0193e8a17420e34710d86283164bcb6d",
                "sha256": "892566bff279368d63f02901aba0a3ce78cd7a319ec1f2bf6c8baab3520207a3"
            },
            "downloads": -1,
            "filename": "typepy-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0193e8a17420e34710d86283164bcb6d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 31389,
            "upload_time": "2023-06-10T13:28:15",
            "upload_time_iso_8601": "2023-06-10T13:28:15.785173Z",
            "url": "https://files.pythonhosted.org/packages/7f/31/0c7a66aa315cc8b2d1915fdd163283ba704307d7c0cf15b31e08c51aedba/typepy-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff68bb1320314d249de81ea5ec77092d9266dbbc05f91422e87266dc52beb484",
                "md5": "e34c06df2c506b090786dcac96165b28",
                "sha256": "dfc37b888d6eed8542208389efa60ec8454e06fd84b276b45b2e33897f9d7825"
            },
            "downloads": -1,
            "filename": "typepy-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e34c06df2c506b090786dcac96165b28",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 23833,
            "upload_time": "2023-06-10T13:28:17",
            "upload_time_iso_8601": "2023-06-10T13:28:17.852014Z",
            "url": "https://files.pythonhosted.org/packages/ff/68/bb1320314d249de81ea5ec77092d9266dbbc05f91422e87266dc52beb484/typepy-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-10 13:28:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thombashi",
    "github_project": "typepy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "typepy"
}
        
Elapsed time: 0.07326s