Type checker helpers for Python.
Project description
# Type Checker
Type check Python types with support for nested lists and dictionaries.
[![coverage report](https://gitlab.com/robjampar/type-checker/badges/master/coverage.svg)](https://gitlab.com/robjampar/type-checker/commits/master)
[![pipeline status](https://gitlab.com/robjampar/type-checker/badges/master/pipeline.svg)](https://gitlab.com/robjampar/type-checker/commits/master)
## Installation
Type Checker is a Python package, and is compatible with `Python 3` only (for now). It can be installed through `pip`.
##### Pip
```
pip install type-checker
```
## Run the Unit Tests
To run the tests.
```
pip install pipenv
pipenv install --dev
pipenv run python -m pytest tests --cov=type_checker
```
## Docs
The documentation is public, and is generated using Sphinx.
[Type Checker Documentation](https://robjampar.gitlab.io/type-checker)
##### Build documentation
To build a local static HTML version of the documentation.
```
pip install pipenv
pipenv install sphinx
pipenv run sphinx-build docs ./public -b html
```
## Type Checking Example
``` python
from typing import Union
from type_checker import type_check
# the type defintion to check a value against
type_def = {
"hello": {
"world": int
},
"a_key": str,
"a_list": [
float
],
int: bool,
float: Union[bool, int]
}
# a valid test value
test_value = {
"hello": {
"world": 1
},
"a_key": "this_is_a_string",
"a_list": [
3.2,
4.7
5.9
],
5: True,
5.2: False,
5.7: 10
}
# use validate from the type_checker package to validate the value
is_valid = type_check(test_value, type_def)
print(f"is valid: {is_valid}")
```
``` text
$ python example.py
>>> is valid: True
```
Type check Python types with support for nested lists and dictionaries.
[![coverage report](https://gitlab.com/robjampar/type-checker/badges/master/coverage.svg)](https://gitlab.com/robjampar/type-checker/commits/master)
[![pipeline status](https://gitlab.com/robjampar/type-checker/badges/master/pipeline.svg)](https://gitlab.com/robjampar/type-checker/commits/master)
## Installation
Type Checker is a Python package, and is compatible with `Python 3` only (for now). It can be installed through `pip`.
##### Pip
```
pip install type-checker
```
## Run the Unit Tests
To run the tests.
```
pip install pipenv
pipenv install --dev
pipenv run python -m pytest tests --cov=type_checker
```
## Docs
The documentation is public, and is generated using Sphinx.
[Type Checker Documentation](https://robjampar.gitlab.io/type-checker)
##### Build documentation
To build a local static HTML version of the documentation.
```
pip install pipenv
pipenv install sphinx
pipenv run sphinx-build docs ./public -b html
```
## Type Checking Example
``` python
from typing import Union
from type_checker import type_check
# the type defintion to check a value against
type_def = {
"hello": {
"world": int
},
"a_key": str,
"a_list": [
float
],
int: bool,
float: Union[bool, int]
}
# a valid test value
test_value = {
"hello": {
"world": 1
},
"a_key": "this_is_a_string",
"a_list": [
3.2,
4.7
5.9
],
5: True,
5.2: False,
5.7: 10
}
# use validate from the type_checker package to validate the value
is_valid = type_check(test_value, type_def)
print(f"is valid: {is_valid}")
```
``` text
$ python example.py
>>> is valid: True
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
type-checker-1.0.2.tar.gz
(5.7 kB
view details)
File details
Details for the file type-checker-1.0.2.tar.gz
.
File metadata
- Download URL: type-checker-1.0.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31479d1a51ee4dde8b17a634e2329162a8586dc452723fe484651157747d119b |
|
MD5 | 206ee448c483f618e45f17b0133c95c3 |
|
BLAKE2b-256 | 3a4794e7f81589953ad1a2a33f8e4fb0f0987144ad7b395ddbc7f8dc61ca1415 |