Metadata-Version: 2.1
Name: typepy
Version: 0.3.0
Summary: A Python library for variable type checker/validator/converter at a run time.
Home-page: https://github.com/thombashi/typepy
Author: Tsuyoshi Hombashi
Author-email: tsuyoshi.hombashi@gmail.com
License: MIT License
Project-URL: Documentation, https://typepy.rtfd.io/
Project-URL: Tracker, https://github.com/thombashi/typepy/issues
Keywords: library,type-checking,type-conversion,validator
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=2.7,!=3.0.*,!=3.1.*,!=3.2.*
Requires-Dist: setuptools (>=38.3.0)
Requires-Dist: mbstrdecoder (>=0.5.0)
Requires-Dist: six (>=1.11.0)
Requires-Dist: ipaddress; python_version < "3.3"
Requires-Dist: enum34; python_version < "3.4"
Provides-Extra: build
Requires-Dist: wheel; extra == 'build'
Provides-Extra: datetime
Requires-Dist: python-dateutil (>=2.7.5); extra == 'datetime'
Requires-Dist: pytz (>=2018.7); extra == 'datetime'
Provides-Extra: docs
Requires-Dist: path.py; extra == 'docs'
Requires-Dist: readmemaker (>=0.6.1); extra == 'docs'
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
Requires-Dist: Sphinx; extra == 'docs'
Provides-Extra: release
Requires-Dist: releasecmd (>=0.0.12); extra == 'release'
Provides-Extra: test
Requires-Dist: pytest-runner; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Requires-Dist: termcolor; extra == 'test'
Requires-Dist: tox; extra == 'test'

**typepy**

.. contents:: Table of Contents
   :depth: 2

Summary
=========
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

.. image:: https://img.shields.io/pypi/pyversions/typepy.svg
   :target: https://pypi.org/project/typepy

.. image:: https://img.shields.io/travis/thombashi/typepy/master.svg?label=Linux/macOS
    :target: https://travis-ci.org/thombashi/typepy

.. image:: https://img.shields.io/appveyor/ci/thombashi/typepy/master.svg?label=Windows
    :target: https://ci.appveyor.com/project/thombashi/typepy

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

.. image:: https://img.shields.io/github/stars/thombashi/typepy.svg?style=social&label=Star
   :target: https://github.com/thombashi/typepy

Features
==========
- checking a value type
- validate a value for a type
- convert a value from a 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>`__
    ================================================  =======================================================================================================

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 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 classes constructors as an argument.
More information can be found in the
`API reference <https://typepy.rtfd.io/en/latest/pages/reference/index.html>`__.

Installation
============
::

    pip install typepy

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

::

    pip install typepy[datetime]


Dependencies
============
Python 2.7+ or 3.4+

- `mbstrdecoder <https://github.com/thombashi/mbstrdecoder>`__
- `six <https://pypi.org/project/six/>`__

Optioal 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/>`__

Test dependencies
----------------------------------
- `pytest <https://docs.pytest.org/en/latest/>`__
- `pytest-runner <https://github.com/pytest-dev/pytest-runner>`__
- `tox <https://testrun.org/tox/latest/>`__

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



