Schemalite Modules

Core

Main module.

schemalite.core.func_and_desc(func, desc)[source]
schemalite.core.instance_of(item, type_)[source]

This method is an enhanced version of isinstance

It can handle cases where a number like string is meant to be treated as a number or where a datetime like string is meant to be treated as a datetime

schemalite.core.json_encoder(obj)[source]
schemalite.core.schema_to_json(schema)[source]
schemalite.core.validate_dict(dictionary, schema, allow_unknown_fields=None, allow_required_fields_to_be_skipped=None, polymorphic_identity=None, context=None, parent_contexts=None, siblings_list=None, curr_obj_idx_in_siblings_list=None, schemas_registry=None)[source]

The main method to be used to validate a dictionary against a schema

This method accepts the dictionary to be validated as the first argument and validates it against the schema which is passed as the second argument

Parameters:
  • dictionary (dict) – The dict object which is to be validated
  • schema (dict) – The schema against which the validation has to be done.
  • allow_unknown_fields (bool) – If this is set to True, the validator will allow the dictionary to have fields which are not specified in the schema. The validation will be done only on those fields whose behavior is specified by the schema. The rest would be ignored.
  • allow_required_fields_to_be_skipped (bool) – Sometimes even if a field is marked as required, it might become necessary to skip that check when the validator is called in certain contexts (Consider POST vs PUT for example. A field might be required for the POST request, but might be optional for the PUT request. If you are re-using the same validation logic for both, it will be convenient if you can allow the PUT request to allow the required fields to be skipped)
Returns:

  • validation_status (bool) – A boolean flag which says if the validation succeeded or failed
  • validation_errors (dict or str or None) – The errors if any, outputted as a string or a dict based on the schema

schemalite.core.validate_list_of_dicts(list_of_dicts, dict_schema, allow_unknown_fields=None, allow_required_fields_to_be_skipped=None, context=None, parent_contexts=None, schemas_registry=None)[source]
schemalite.core.validate_schema(schema)[source]

Validators

schemalite.validators.is_a_list_of_types_of(*types)[source]
schemalite.validators.is_a_type_of(*types)[source]