HockeyTech core
The shared HockeyTech / LeagueStat client behind the PWHL and the 19 minor and junior league families (sportsdataverse.hockey.<league>): the request chokepoint, the league registry, season-id resolution and the play-by-play enrichment (game meta, coordinates, clock, shot geometry, on-ice skaters) every family's <league>_pbp applies.
HockeyTech / LeagueStat
LeagueConfig
LeagueConfig(name: 'str', client_code: 'str', api_key: 'str', league_id: 'int', site_id: 'int', base_url: 'str', pbp_style: "Literal['hockeytech_a', 'hockeytech_b']", ot_period_length: 'int') -> None
One HockeyTech league's connection settings (a frozen dataclass).
The registry LEAGUES maps each league code to one of these; every request the
league's family makes is built from it (PWHL play-by-play uses its own key).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | Display name ("PWHL", "ECHL"). | |
client_code | str | The feed's client_code query value (QMJHL's is "lhjmq"). | |
api_key | str | The public web-client key shipped in the league site's JavaScript. SDV_<LEAGUE>_API_KEY overrides it at request time, and PWHL's gameCenterPlayByPlay requests use a separate key. | |
league_id | int | The league_id the standings query takes (not the scorebar row's league_id, which is a different namespace). | |
site_id | int | The feed's site_id query value. | |
base_url | str | The feed endpoint (lscluster.hockeytech.com or cluster.leaguestat.com). | |
pbp_style | Literal['hockeytech_a', 'hockeytech_b'] | Payload-dialect label, "hockeytech_a" or "hockeytech_b". Both parse through the same play-by-play parser onto one 600x300 canvas. | |
ot_period_length | int | Regular-season overtime length in seconds, from the league's rulebook. Informational: no parser reads it. |
Example
from sportsdataverse.hockeytech import LEAGUES
cfg = LEAGUES["echl"]
cfg.name, cfg.league_id, cfg.pbp_style
enrich_pbp
enrich_pbp(df: 'pl.DataFrame', league: 'str', game_id: 'int', *, meta_payload: 'Optional[Any]' = None, shifts_payload: 'Optional[Any]' = None, return_as_pandas: 'bool' = False) -> 'Any'
Enrich a parsed HockeyTech PBP frame — league-generic.
Applies the full enrichment pipeline:
- Game-meta join (
game_date,game_season,game_season_id,home_team,home_team_id,away_team,away_team_id) fromgc/gamesummary. - Coordinate transforms (
*_original,*_neutral,*_fixed,*_right,*_vertical— 10 columns) viaadd_coord_transforms, which also overwritesx_coord/y_coordwith feet (the raw canvas stays in*_original). - Clock columns (
minute_start,second_start,clock,sec_from_start) viaadd_clock_columns. - Shot geometry (
shot_distance,shot_angle,scoring_chance) viaadd_shot_distance_angle+scoring_chances. - On-ice player tracking (
on_ice_home,on_ice_away) frommodulekit/gameshiftsviabuild_on_ice.
This function is pure when meta_payload and shifts_payload are
injected (no network calls). When either is None the corresponding
feed is fetched via hockeytech_api using the supplied league code.
Callers that need test isolation should fetch both payloads via their own
(patchable) hockeytech_api reference and pass them in.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
df | DataFrame | Raw frame produced by parse_pbp. | |
league | str | HockeyTech league code (e.g. "pwhl", "ohl", "whl"). | |
game_id | int | Numeric game identifier. | |
meta_payload | Optional[Any] | None | Optional pre-fetched gc/gamesummary JSON dict. Fetched live when None. |
shifts_payload | Optional[Any] | None | Optional pre-fetched modulekit/gameshifts JSON dict. Fetched live when None. Pass {} to suppress on-ice computation entirely. |
return_as_pandas | bool | False | When True return a pandas.DataFrame; otherwise a polars.DataFrame. |
Returns
polars.DataFrame or pandas.DataFrame: The play-by-play frame with the columns above added, one row per event, the same rows as df.
| col_name | type | description |
|---|---|---|
game_id | Int64 | Unique game identifier. |
event | String | Event description label. |
team_id | Int64 | Unique team identifier. |
period_of_game | String | Period in which the event occurred. |
time_of_period | String | Elapsed time within the period (MM:SS). |
x_coord | Float64 | Transformed x-coordinate of the event (feet scale). |
y_coord | Float64 | Transformed y-coordinate of the event (feet scale). |
player_id | Int64 | Unique player identifier. |
player_name_first | String | Primary player first name. |
player_name_last | String | Primary player last name. |
player_position | String | Primary player position. |
goal | Boolean | Flag for whether the event was a goal. |
is_goal_twin | Boolean | True on the feed's twin shot row of a goal (the feed writes a goal as a goal row plus a shot row); drop these rows for a deduplicated event stream, keep them for official shots-on-goal counts. |
goalie_id | Int64 | Goalie identifier on the play. |
goalie_first | String | Goalie first name. |
goalie_last | String | Goalie last name. |
home_win | String | Whether the home player won the faceoff. |
player_team_id | Int64 | Unique team identifier of the primary player. |
event_type | String | Standardized event type code. |
shot_quality | String | Shot quality descriptor. |
empty_net | String | Whether the net was empty. |
game_winner | String | Whether the goal was the game-winning goal. |
penalty_shot | String | Whether the goal came on a penalty shot. |
insurance | String | Whether the goal was an insurance goal. |
short_handed | String | Whether the event occurred while short-handed. |
power_play | String | Whether the event occurred on a power play. |
player_two_id | Int64 | Second player's unique identifier. |
player_two_name_first | String | Second player first name. |
player_two_name_last | String | Second player last name. |
player_two_position | String | Second player position. |
plus_player_one_id | Int64 | On-ice plus player one unique identifier. |
plus_player_one_first | String | On-ice plus player one first name. |
plus_player_one_last | String | On-ice plus player one last name. |
plus_player_one_position | String | On-ice plus player one position. |
plus_player_two_id | Int64 | On-ice plus player two unique identifier. |
plus_player_two_first | String | On-ice plus player two first name. |
plus_player_two_last | String | On-ice plus player two last name. |
plus_player_two_position | String | On-ice plus player two position. |
plus_player_three_id | Int64 | On-ice plus player three unique identifier. |
plus_player_three_first | String | On-ice plus player three first name. |
plus_player_three_last | String | On-ice plus player three last name. |
plus_player_three_position | String | On-ice plus player three position. |
plus_player_four_id | Int64 | On-ice plus player four unique identifier. |
plus_player_four_first | String | On-ice plus player four first name. |
plus_player_four_last | String | On-ice plus player four last name. |
plus_player_four_position | String | On-ice plus player four position. |
plus_player_five_id | Int64 | On-ice plus player five unique identifier. |
plus_player_five_first | String | On-ice plus player five first name. |
plus_player_five_last | String | On-ice plus player five last name. |
plus_player_five_position | String | On-ice plus player five position. |
minus_player_one_id | Int64 | On-ice minus player one unique identifier. |
minus_player_one_first | String | On-ice minus player one first name. |
minus_player_one_last | String | On-ice minus player one last name. |
minus_player_one_position | String | On-ice minus player one position. |
minus_player_two_id | Int64 | On-ice minus player two unique identifier. |
minus_player_two_first | String | On-ice minus player two first name. |
minus_player_two_last | String | On-ice minus player two last name. |
minus_player_two_position | String | On-ice minus player two position. |
minus_player_three_id | Int64 | On-ice minus player three unique identifier. |
minus_player_three_first | String | On-ice minus player three first name. |
minus_player_three_last | String | On-ice minus player three last name. |
minus_player_three_position | String | On-ice minus player three position. |
minus_player_four_id | Int64 | On-ice minus player four unique identifier. |
minus_player_four_first | String | On-ice minus player four first name. |
minus_player_four_last | String | On-ice minus player four last name. |
minus_player_four_position | String | On-ice minus player four position. |
minus_player_five_id | Int64 | On-ice minus player five unique identifier. |
minus_player_five_first | String | On-ice minus player five first name. |
minus_player_five_last | String | On-ice minus player five last name. |
minus_player_five_position | String | On-ice minus player five position. |
penalty_length | String | Penalty length in minutes. |
player_three_id | Int64 | Third player's unique identifier. |
player_three_name_first | String | Third player first name. |
player_three_name_last | String | Third player last name. |
player_three_position | String | Third player position. |
game_date | String | Game date. |
game_season | Int64 | Calendar year of game_date, not the season's end year (a game on 2024-12-01 gives 2024); game_season_id identifies the season itself. |
game_season_id | Int64 | HockeyTech season identifier. |
home_team | String | Home team name. |
home_team_id | Int64 | Home team identifier. |
away_team | String | Away team name. |
away_team_id | Int64 | Away team identifier. |
x_coord_original | Float64 | Original raw x-coordinate from the feed. |
y_coord_original | Float64 | Original raw y-coordinate from the feed. |
x_coord_neutral | Float64 | Neutral-zone-centered x-coordinate. |
y_coord_neutral | Float64 | Neutral-zone-centered y-coordinate. |
x_coord_fixed | Float64 | Fixed-orientation x-coordinate. |
y_coord_fixed | Float64 | Fixed-orientation y-coordinate. |
x_coord_right | Float64 | Right-orientation x-coordinate. |
y_coord_right | Float64 | Right-orientation y-coordinate. |
x_coord_vertical | Float64 | Vertical-orientation x-coordinate. |
y_coord_vertical | Float64 | Vertical-orientation y-coordinate. |
minute_start | Int64 | Minute mark of the period when the event started. |
second_start | Int64 | Second mark of the period when the event started. |
clock | String | Game clock time remaining (MM:SS). |
sec_from_start | Int64 | Seconds elapsed since the start of the game. |
shot_distance | Float64 | Distance of the shot from the net. |
shot_angle | Float64 | Angle of the shot relative to the net. |
scoring_chance | Boolean | TRUE when event is a shot-type within 25 ft of the net. |
on_ice_home | String | Comma-joined sorted player_ids on ice for the home team. |
on_ice_away | String | Comma-joined sorted player_ids on ice for the away team. |
Raises
| Exception | Description |
|---|---|
ValueError | A live fetch was needed and league is not registered, or the host answered HTTP 400 / 422. |
AssetFetchError | A live gamesummary or gameshifts fetch failed (only when that payload was not passed in). |
NoDataError | A live fetch answered HTTP 404. |
Example
from sportsdataverse.hockeytech import enrich_pbp, hockeytech_api
from sportsdataverse.hockeytech._parsers import parse_pbp
raw = hockeytech_api("pwhl", "statviewfeed", "gameCenterPlayByPlay", {"game_id": 2, "league_id": ""})
df = enrich_pbp(parse_pbp(raw, pbp_style="hockeytech_a", game_id=2), "pwhl", 2)
df.select("event", "shot_distance", "shot_angle").head()
hockeytech_api
hockeytech_api(league: 'str', feed: 'str', view: 'str', params: 'Optional[Dict[str, Any]]' = None, *, timeout: 'int' = 30, max_retries: 'int' = 3, **kwargs) -> 'Union[Dict[str, Any], list]'
Fetch and parse one HockeyTech feed call: the chokepoint every league family requests through.
Adds the league's key, client_code and site_id, strips the JSONP wrapper,
and spaces the calls this process starts by at least the client's rate-limit
interval (retries inside one call are not spaced). The key never appears in an
error message.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
league | str | HockeyTech league code ("pwhl", "ahl", "echl", ...). | |
feed | str | The feed name: "modulekit", "gc" or "statviewfeed". | |
view | str | The view within the feed ("seasons", "schedule", "gamesummary", "gameCenterPlayByPlay", ...). The gc feed sends it as tab=, the others as view=. | |
params | Optional[Dict[str, Any]] | None | Extra query parameters ({"season_id": 5}, {"game_id": 2}). A None value is dropped. |
timeout | int | 30 | Seconds to wait for each response. |
max_retries | int | 3 | Retries on a transport error or a retryable status. |
Returns
dict or list: The parsed JSON. The one reply the source sends for "this key never has that feed" -- the plain-text Feed type access denied. (MJHL's public key on gc) -- returns {}, which every parser reads as a zero-row frame. Passed to enrich_pbp as the game summary, it leaves the game-meta columns null on otherwise enriched rows.
Raises
| Exception | Description |
|---|---|
ValueError | league is not in the registry (before any request), or the host answered HTTP 400 / 422 (the request itself is wrong). |
NoDataError | The host answered HTTP 404. |
AssetFetchError | The fetch failed and the answer is unknown -- a transport error, a non-2xx status that outlived the retries (403, 429, 5xx), an empty or unparseable body, or an HTTP-200 error sentinel (Undefined Tab <view> / InvalidView error: <view>). |
Example
from sportsdataverse.hockeytech import hockeytech_api
payload = hockeytech_api("pwhl", "modulekit", "seasons")
[s["season_name"] for s in payload["SiteKit"]["Seasons"]][:3]
Dates and seasons
resolve_season_id
resolve_season_id(league: 'str', season=None, game_type: 'str' = 'regular', season_id=None)
Resolve an end-year season (e.g. 2025) to the integer HockeyTech season_id.
An explicit season_id short-circuits. PWHL falls back to a
hardcoded table if the live feed lacks the season, or if the feed fails (with a
UserWarning naming the failure; a season the table lacks re-raises the fetch
error); every other league re-raises the fetch error (AssetFetchError / NoDataError).
Of the rows with that season_yr and game_type_label ("regular", "playoffs",
"preseason" or "exhibition"), regular and playoff lookups drop one-off events, then the
first row wins in this order: no other registered league's code in the name ("CCHL
2009/2010" in the OJHL feed ranks last), the name says its game type, the name spans two
years, feed order. Divisions listed side by side for one year with neither marker are
not told apart: BCHL 2024 resolves to "2023-24 BC Regular Season" but "2024 AB
Playoffs", GOJHL 2008 to its GHL conference; pass season_id for the others.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
league | str | HockeyTech league code ("pwhl", "ahl", "echl", ...). | |
season | None | End year of the season (2025 = the 2024-25 season). Required unless season_id is given. | |
game_type | str | 'regular' | "regular" (default), "playoffs", "preseason" or "exhibition". |
season_id | None | A known HockeyTech season id, returned as is without a request. |
Returns
The HockeyTech season_id.
Raises
| Exception | Description |
|---|---|
ValueError | Neither season nor season_id was given, league is not registered, the feed lists no season matching season and game_type, or the seasons feed answered HTTP 400 / 422. |
AssetFetchError | The seasons feed failed (outside the PWHL fallback table). |
NoDataError | The seasons feed answered HTTP 404 (outside the PWHL fallback table). |
Example
from sportsdataverse.hockeytech import resolve_season_id
sid = resolve_season_id("echl", season=2025, game_type="playoffs")