Skip to main content

A python library for variable type checker/validator/converter at run time.

Project description

pytypeutil

https://badge.fury.io/py/pytypeutil.svg https://img.shields.io/pypi/pyversions/pytypeutil.svg https://img.shields.io/travis/thombashi/pytypeutil/master.svg?label=Linux https://img.shields.io/appveyor/ci/thombashi/pytypeutil/master.svg?label=Windows https://coveralls.io/repos/github/thombashi/pytypeutil/badge.svg?branch=master https://img.shields.io/github/stars/thombashi/pytypeutil.svg?style=social&label=Star

Summary

A python library for variable type checker/validator/converter at run time.

Usage

Type Check

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

Type Validation

>>> from pytypeutil.type import Integer
>>> Integer(1).validate()
>>> try:
...     Integer(1.1).validate()
... except TypeError as e:
...     print(e)
...
invalid value type: expected=INTEGER, actual=<type 'float'>

Type Conversion

convert

>>> from pytypeutil.type import Integer
>>> from pytypeutil import TypeConversionError
>>> Integer("1").convert()
1
>>> try:
...     Integer(1.1).convert()
... except TypeConversionError as e:
...     print(e)
...
failed to convert from float to INTEGER

try_convert

>>> from pytypeutil.type import Integer
>>> Integer("1").try_convert()
1
>>> print(Integer(1.1).try_convert())
None

force_convert

>>> from pytypeutil.type import Integer
>>> Integer("1").force_convert()
1
>>> Integer(1.1).force_convert()
1

For more information

More examples are available at http://pytypeutil.rtfd.io/en/latest/pages/reference/index.html

Features

Supported types are as follows:

  • bool
  • datetime
  • dict
  • int
  • float
    • Real number
    • Infinite
    • Not a number
  • None
  • str
    • null string

Type check/validate/convert results will be decided according to strict_level which can be passed to constructors. API reference can be found at the document.

Installation

pip install pytypeutil

Dependencies

Python 2.7+ or 3.3+

Test dependencies

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytypeutil, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size pytypeutil-0.0.1-py2.py3-none-any.whl (26.6 kB) File type Wheel Python version 2.7 Upload date Hashes View hashes
Filename, size pytypeutil-0.0.1.tar.gz (17.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page