def validate ( datum , schema , field = None , raise_errors = True ) : record_type = extract_record_type ( schema ) result = None validator = VALIDATORS . get ( record_type ) if validator : result = validator ( datum , schema = schema , parent_ns = field , raise_errors = raise_errors ) elif record_type in SCHEMA_DEFS : result = validate ( datum , schema = SCHEMA_DEFS [ record_type ] , field = field , raise_errors = raise_errors ) else : raise UnknownType ( record_type ) if raise_errors and result is False : raise ValidationError ( ValidationErrorData ( datum , schema , field ) ) return result
validate avro schema with data in python
Determine if a python datum is an instance of a schema .
def validate(datum, schema, field=None, raise_errors=True):
    """
    Determine if a python datum is an instance of a schema.

    Parameters
    ----------
    datum: Any
        Data being validated
    schema: dict
        Schema
    field: str, optional
        Record field being validated
    raise_errors: bool, optional
        If true, errors are raised for invalid data. If false, a simple
        True (valid) or False (invalid) result is returned


    Example::

        from fastavro.validation import validate
        schema = {...}
        record = {...}
        validate(record, schema)
    """
    record_type = extract_record_type(schema)
    result = None

    validator = VALIDATORS.get(record_type)
    if validator:
        result = validator(datum, schema=schema,
                           parent_ns=field,
                           raise_errors=raise_errors)
    elif record_type in SCHEMA_DEFS:
        result = validate(datum,
                          schema=SCHEMA_DEFS[record_type],
                          field=field,
                          raise_errors=raise_errors)
    else:
        raise UnknownType(record_type)

    if raise_errors and result is False:
        raise ValidationError(ValidationErrorData(datum, schema, field))

    return result