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
Test parse with stml file
from typeschemalib import typeschemalib
from termcolor import colored
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
from typeschemalib import typeschemalib
from termcolor import colored
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-1.0.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for typeschemalib-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 314272bc5609f35d906c4fcb775ce35a662833c01d8d889b4b87c55ce8147f43 |
|
MD5 | 1127b89a9597e5c3014f0d48aec12aff |
|
BLAKE2b-256 | 45417b7468905bbd68fa1ea7db6c7dcd45716d1052146262cd16d56ff20a33d6 |