All Projects → thombashi → typepy

thombashi / typepy

Licence: MIT license
A Python library for variable type checker/validator/converter at a run time.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to typepy

valite
🔥 Concurrently execute your validators in a simple, practical and light validator engine.
Stars: ✭ 20 (+25%)
Mutual labels:  validator
codeowners-validator
The GitHub CODEOWNERS file validator
Stars: ✭ 142 (+787.5%)
Mutual labels:  validator
max-validator
Advanced validation library for Javascript & React | Inspired by laravel validation
Stars: ✭ 29 (+81.25%)
Mutual labels:  validator
national-code
Simple implementation of Iranian national code validation
Stars: ✭ 31 (+93.75%)
Mutual labels:  validator
ZUV
ZUgferd validator using Verapdf
Stars: ✭ 22 (+37.5%)
Mutual labels:  validator
Natours
An awesome tour booking web app written in NodeJS, Express, MongoDB 🗽
Stars: ✭ 94 (+487.5%)
Mutual labels:  validator
hey-validator
Data validator
Stars: ✭ 14 (-12.5%)
Mutual labels:  validator
validator
Yii validator library
Stars: ✭ 47 (+193.75%)
Mutual labels:  validator
volder
volder is powerful Object schema validation lets you describe your data using a simple and readable schema and transform a value to match the requirements
Stars: ✭ 106 (+562.5%)
Mutual labels:  validator
toi
A TypeScript validation library capable of inferring types
Stars: ✭ 25 (+56.25%)
Mutual labels:  validator
utf8-validator
UTF-8 Validator
Stars: ✭ 18 (+12.5%)
Mutual labels:  validator
python-sshpubkeys
OpenSSH public key parser for Python
Stars: ✭ 85 (+431.25%)
Mutual labels:  validator
vayder
Easy and concise validations for Express routes
Stars: ✭ 26 (+62.5%)
Mutual labels:  validator
simple-validator
Simple Validator is an awesome and easy to use validator for php
Stars: ✭ 73 (+356.25%)
Mutual labels:  validator
micropython-stubs
Stubs of common micropython modules to aid in code completion, static typechecking and overall development
Stars: ✭ 46 (+187.5%)
Mutual labels:  type-checking
Hammer
Simple, reliable FHIR validator
Stars: ✭ 27 (+68.75%)
Mutual labels:  validator
formurai
Lightweight and powerfull library for declarative form validation
Stars: ✭ 49 (+206.25%)
Mutual labels:  validator
strongtyping
Decorator which checks whether the function is called with the correct type of parameters.
Stars: ✭ 85 (+431.25%)
Mutual labels:  type-checking
romans
A Simple PHP Roman Numerals Library
Stars: ✭ 40 (+150%)
Mutual labels:  validator
swagger-object-validator
Node-Module to validate your model against a swagger spec and receive in-depth error traces
Stars: ✭ 27 (+68.75%)
Mutual labels:  validator

Summary

typepy is a Python library for variable type checker/validator/converter at a run time.

PyPI package version conda-forge package version Supported Python versions Supported Python implementations Linux/macOS/Windows CI status Test coverage CodeQL

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:

Supported Types
Python Type typepy: Type Class
bool Bool
datetime DateTime
dict Dictionary
float/decimal.Decimal (not infinity/NaN) RealNumber
float/decimal.Decimal (infinity) Infinity
float/decimal.Decimal (NaN) Nan
int Integer
list List
None None
str (not null) String
str (null) NullString
str (IP address) IpAddress

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

Optioal dependencies

These packages can be installed via pip install typepy[datetime]:

Usage

Type Check Method

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

Type Validation Method

Examples:
>>> 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:
>>> 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:
>>> 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:
>>> 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.

Documentation

https://typepy.rtfd.io/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].