Skip to main content

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

ParameterTypeDefaultDescription
namestrDisplay name ("PWHL", "ECHL").
client_codestrThe feed's client_code query value (QMJHL's is "lhjmq").
api_keystrThe 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_idintThe league_id the standings query takes (not the scorebar row's league_id, which is a different namespace).
site_idintThe feed's site_id query value.
base_urlstrThe feed endpoint (lscluster.hockeytech.com or cluster.leaguestat.com).
pbp_styleLiteral['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_lengthintRegular-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:

  1. Game-meta join (game_date, game_season, game_season_id, home_team, home_team_id, away_team, away_team_id) from gc/gamesummary.
  2. Coordinate transforms (*_original, *_neutral, *_fixed, *_right, *_vertical — 10 columns) via add_coord_transforms, which also overwrites x_coord / y_coord with feet (the raw canvas stays in *_original).
  3. Clock columns (minute_start, second_start, clock, sec_from_start) via add_clock_columns.
  4. Shot geometry (shot_distance, shot_angle, scoring_chance) via add_shot_distance_angle + scoring_chances.
  5. On-ice player tracking (on_ice_home, on_ice_away) from modulekit/gameshifts via build_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

ParameterTypeDefaultDescription
dfDataFrameRaw frame produced by parse_pbp.
leaguestrHockeyTech league code (e.g. "pwhl", "ohl", "whl").
game_idintNumeric game identifier.
meta_payloadOptional[Any]NoneOptional pre-fetched gc/gamesummary JSON dict. Fetched live when None.
shifts_payloadOptional[Any]NoneOptional pre-fetched modulekit/gameshifts JSON dict. Fetched live when None. Pass {} to suppress on-ice computation entirely.
return_as_pandasboolFalseWhen 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_nametypedescription
game_idInt64Unique game identifier.
eventStringEvent description label.
team_idInt64Unique team identifier.
period_of_gameStringPeriod in which the event occurred.
time_of_periodStringElapsed time within the period (MM:SS).
x_coordFloat64Transformed x-coordinate of the event (feet scale).
y_coordFloat64Transformed y-coordinate of the event (feet scale).
player_idInt64Unique player identifier.
player_name_firstStringPrimary player first name.
player_name_lastStringPrimary player last name.
player_positionStringPrimary player position.
goalBooleanFlag for whether the event was a goal.
is_goal_twinBooleanTrue 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_idInt64Goalie identifier on the play.
goalie_firstStringGoalie first name.
goalie_lastStringGoalie last name.
home_winStringWhether the home player won the faceoff.
player_team_idInt64Unique team identifier of the primary player.
event_typeStringStandardized event type code.
shot_qualityStringShot quality descriptor.
empty_netStringWhether the net was empty.
game_winnerStringWhether the goal was the game-winning goal.
penalty_shotStringWhether the goal came on a penalty shot.
insuranceStringWhether the goal was an insurance goal.
short_handedStringWhether the event occurred while short-handed.
power_playStringWhether the event occurred on a power play.
player_two_idInt64Second player's unique identifier.
player_two_name_firstStringSecond player first name.
player_two_name_lastStringSecond player last name.
player_two_positionStringSecond player position.
plus_player_one_idInt64On-ice plus player one unique identifier.
plus_player_one_firstStringOn-ice plus player one first name.
plus_player_one_lastStringOn-ice plus player one last name.
plus_player_one_positionStringOn-ice plus player one position.
plus_player_two_idInt64On-ice plus player two unique identifier.
plus_player_two_firstStringOn-ice plus player two first name.
plus_player_two_lastStringOn-ice plus player two last name.
plus_player_two_positionStringOn-ice plus player two position.
plus_player_three_idInt64On-ice plus player three unique identifier.
plus_player_three_firstStringOn-ice plus player three first name.
plus_player_three_lastStringOn-ice plus player three last name.
plus_player_three_positionStringOn-ice plus player three position.
plus_player_four_idInt64On-ice plus player four unique identifier.
plus_player_four_firstStringOn-ice plus player four first name.
plus_player_four_lastStringOn-ice plus player four last name.
plus_player_four_positionStringOn-ice plus player four position.
plus_player_five_idInt64On-ice plus player five unique identifier.
plus_player_five_firstStringOn-ice plus player five first name.
plus_player_five_lastStringOn-ice plus player five last name.
plus_player_five_positionStringOn-ice plus player five position.
minus_player_one_idInt64On-ice minus player one unique identifier.
minus_player_one_firstStringOn-ice minus player one first name.
minus_player_one_lastStringOn-ice minus player one last name.
minus_player_one_positionStringOn-ice minus player one position.
minus_player_two_idInt64On-ice minus player two unique identifier.
minus_player_two_firstStringOn-ice minus player two first name.
minus_player_two_lastStringOn-ice minus player two last name.
minus_player_two_positionStringOn-ice minus player two position.
minus_player_three_idInt64On-ice minus player three unique identifier.
minus_player_three_firstStringOn-ice minus player three first name.
minus_player_three_lastStringOn-ice minus player three last name.
minus_player_three_positionStringOn-ice minus player three position.
minus_player_four_idInt64On-ice minus player four unique identifier.
minus_player_four_firstStringOn-ice minus player four first name.
minus_player_four_lastStringOn-ice minus player four last name.
minus_player_four_positionStringOn-ice minus player four position.
minus_player_five_idInt64On-ice minus player five unique identifier.
minus_player_five_firstStringOn-ice minus player five first name.
minus_player_five_lastStringOn-ice minus player five last name.
minus_player_five_positionStringOn-ice minus player five position.
penalty_lengthStringPenalty length in minutes.
player_three_idInt64Third player's unique identifier.
player_three_name_firstStringThird player first name.
player_three_name_lastStringThird player last name.
player_three_positionStringThird player position.
game_dateStringGame date.
game_seasonInt64Calendar 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_idInt64HockeyTech season identifier.
home_teamStringHome team name.
home_team_idInt64Home team identifier.
away_teamStringAway team name.
away_team_idInt64Away team identifier.
x_coord_originalFloat64Original raw x-coordinate from the feed.
y_coord_originalFloat64Original raw y-coordinate from the feed.
x_coord_neutralFloat64Neutral-zone-centered x-coordinate.
y_coord_neutralFloat64Neutral-zone-centered y-coordinate.
x_coord_fixedFloat64Fixed-orientation x-coordinate.
y_coord_fixedFloat64Fixed-orientation y-coordinate.
x_coord_rightFloat64Right-orientation x-coordinate.
y_coord_rightFloat64Right-orientation y-coordinate.
x_coord_verticalFloat64Vertical-orientation x-coordinate.
y_coord_verticalFloat64Vertical-orientation y-coordinate.
minute_startInt64Minute mark of the period when the event started.
second_startInt64Second mark of the period when the event started.
clockStringGame clock time remaining (MM:SS).
sec_from_startInt64Seconds elapsed since the start of the game.
shot_distanceFloat64Distance of the shot from the net.
shot_angleFloat64Angle of the shot relative to the net.
scoring_chanceBooleanTRUE when event is a shot-type within 25 ft of the net.
on_ice_homeStringComma-joined sorted player_ids on ice for the home team.
on_ice_awayStringComma-joined sorted player_ids on ice for the away team.

Raises

ExceptionDescription
ValueErrorA live fetch was needed and league is not registered, or the host answered HTTP 400 / 422.
AssetFetchErrorA live gamesummary or gameshifts fetch failed (only when that payload was not passed in).
NoDataErrorA 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

ParameterTypeDefaultDescription
leaguestrHockeyTech league code ("pwhl", "ahl", "echl", ...).
feedstrThe feed name: "modulekit", "gc" or "statviewfeed".
viewstrThe view within the feed ("seasons", "schedule", "gamesummary", "gameCenterPlayByPlay", ...). The gc feed sends it as tab=, the others as view=.
paramsOptional[Dict[str, Any]]NoneExtra query parameters ({"season_id": 5}, {"game_id": 2}). A None value is dropped.
timeoutint30Seconds to wait for each response.
max_retriesint3Retries 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

ExceptionDescription
ValueErrorleague is not in the registry (before any request), or the host answered HTTP 400 / 422 (the request itself is wrong).
NoDataErrorThe host answered HTTP 404.
AssetFetchErrorThe 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

ParameterTypeDefaultDescription
leaguestrHockeyTech league code ("pwhl", "ahl", "echl", ...).
seasonNoneEnd year of the season (2025 = the 2024-25 season). Required unless season_id is given.
game_typestr'regular'"regular" (default), "playoffs", "preseason" or "exhibition".
season_idNoneA known HockeyTech season id, returned as is without a request.

Returns

The HockeyTech season_id.

Raises

ExceptionDescription
ValueErrorNeither 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.
AssetFetchErrorThe seasons feed failed (outside the PWHL fallback table).
NoDataErrorThe 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")