Skip to main content

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


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)

Uploaded Source

Built Distribution

typeschemalib-1.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page