Raw-payload schemas
The bundled raw-payload schemas (sportsdataverse/schemas/raw/*.yaml) and the validator that checks a captured payload against one before it is stored.
Release utilities
load_raw_schema
load_raw_schema(name: 'str') -> 'dict[str, Any]'
Load a raw-payload schema by name.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | A key of RAW_SCHEMAS, e.g. "espn_summary". |
Returns
The parsed schema: {name, description, additional_properties, required, optional}.
Raises
| Exception | Description |
|---|---|
KeyError | If name is not a declared payload family. |
ImportError | If PyYAML is not installed. |
TypeError | If the schema file does not parse to a mapping. |
Example
from sportsdataverse.schemas import load_raw_schema
schema = load_raw_schema("espn_summary")
print(sorted(schema["required"]))
# Inspect what a family tolerates
print(schema["additional_properties"]) # True -- unknown keys allowed
validate_payload
validate_payload(name: 'str', payload: 'Any') -> 'list[str]'
Check a payload against its declared shape.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | A key of RAW_SCHEMAS. | |
payload | Any | The parsed JSON payload. |
Returns
A list of human-readable problems. An empty list means the payload matches: every required key is present with a declared type, and every present optional key has a declared type. Unknown keys are ignored by design.
Raises
| Exception | Description |
|---|---|
KeyError | If name is not a declared payload family. |
Example
import json
from sportsdataverse.schemas import validate_payload
payload = json.loads(open("wbb/json/final/401811123.json").read())
problems = validate_payload("espn_summary", payload)
print(problems) # [] when the payload matches
# Fail a scrape on a bad capture
if validate_payload("espn_summary", payload):
raise AssertionError("refusing to persist a non-conforming payload")
# Scan an archive for damage
import glob
paths = glob.glob("wbb/json/final/*.json")
bad = [p for p in paths if validate_payload("espn_summary", json.loads(open(p).read()))]