Summary
typepy is a Python library for variable type checker/validator/converter at a run time.
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:
Python Type |
typepy: Type Class |
|---|---|
bool |
|
datetime |
|
dict |
|
float/decimal.Decimal (not infinity/NaN) |
|
float/decimal.Decimal (infinity) |
|
float/decimal.Decimal (NaN) |
|
int |
|
list |
|
None |
|
str (not null) |
|
str (null) |
|
str (IP address) |
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
Optional 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 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.
Documentation
Release files for typepy 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typepy-2.0.0.tar.gz | 39.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typepy-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 71.3 kB
Release files / typepy-2.0.0.tar.gz
| Download URL | typepy-2.0.0.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
413fec52a54a010e2e20d6e18eef68840ebf13b95b719e17b5e2e81c6e85e4a6
|
|
BLAKE2b-256 checksum How to use checksums |
28c30c4382a6c70d0aa119bbf45c56340609c3f206b68756e7ff6b91abf83cd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency logRelease files / typepy-2.0.0-py3-none-any.whl
| Download URL | typepy-2.0.0-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f97d3d26d5643a0aeccefb5f5ebadf64610e53eb2d0fa14133e5929a63314cfc
|
|
BLAKE2b-256 checksum How to use checksums |
808602e36d19ad12e27af63b99062f552c6a1eae030753926223c9575c8f5458
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency log