validate()
Validate data against a schema dictionary.
Usage
validate(
schema,
data,
)Checks that all keys in the schema are present in data and that value types match the schema specification.
Parameters
schema: dict-
A dictionary mapping key names to expected types (e.g.,
{"name": str, "age": int}). data: dict-
The data dictionary to validate against the schema.
Returns
bool-
True if the data conforms to the schema.
Raises
KeyError-
If a required key from the schema is missing in the data.
TypeError-
If a value in data does not match the expected type from the schema.
Note
Only top-level keys are validated. Nested dicts are not recursively checked.