A yaml like schema that can be used to check dictionaries for correct schema
Project description
typeschemalib
A yaml like schema that can be used to check dictionaries for correct schema
Schema file
schema example
point: Int
my_string: Str
grade: Float
data example
{"point": 45, "my_string": "Hey", "grade": 4.5}
Checking data for correct schema
from typeschemalib import typeschemalib
from termcolor import colored
"""Test parse with stml file"""
schema_file = "test.stml"
data = {"point": 45, "my_string": "Hey", "grade": 4.5}
lines = typeschemalib.StmlReader(schema_file).lines
schema_dict = typeschemalib.StmlParser(lines).schema_dict
dataChecker = typeschemalib.DataChecker(schema_dict, data)
valid = dataChecker.check_type()
if valid is True:
print(colored(valid, 'green'))
else:
print(colored(valid, 'red'))
"""Test parse with schema dictionary"""
data = {"point": 45, "my_string": "Hey", "grade": 4.5}
schema = {"point": "Int", "my_string": "Str", "grade": "Float"}
schema_dict = typeschemalib.StmlParser(lines).schema_dict
dataChecker = typeschemalib.DataChecker(schema, data)
valid = dataChecker.check_type()
if valid is True:
print(colored(valid, 'green'))
else:
print(colored(valid, 'red'))
Todo
Make schema have regex Make schema have functions or options to validate data
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
typeschemalib-0.9.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for typeschemalib-0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0530dec7a31d0d23e7076afbb16c8f14556b359de093ec10922908ac44d1c0b8 |
|
MD5 | 40ccf6f84f04930bf146673533cab9df |
|
BLAKE2b-256 | 274236ddaf39af21873d493033b3e58a371333643168c89bc91d175a00e96d8e |