This is the reverse of to_dict(). Use it when the contract comes from somewhere other than a YAML file: a JSON document, an API response, a database record, or a dictionary built in code. To read a YAML file directly, use from_yaml().
The dictionary uses the contract’s parameter names as keys. Only "name" is required. "schema" should map column names to type strings, "steps" should be a list of single-key mappings from method name to arguments, and "thresholds" should map any of "warning", "error", and "critical" to a value. The parsed contract is checked as usual, so an invalid direction, on_violation, or step method raises an error.
Parameters
data:dict[str, Any]
A dictionary describing a contract, in the form produced by to_dict().
If "name" is missing or empty, if "direction" or "on_violation" has an invalid value, or if a step names a method that contracts don’t support.
TypeError
If "steps" isn’t a list, or if a step’s arguments aren’t a dictionary.
Examples
Suppose a contract definition arrives as JSON from a configuration service. After parsing, it’s a dictionary that from_dict() can turn into a Contract.