Teams¶
Team-related functionality in Edgework.
Team Methods¶
Fetch team stats for a given season. Args: season (str): The season to fetch stats for (e.g., "2024-2025"). report (str): The type of report to fetch (e.g., "summary", "detailed"). sort (dict): The field to sort the results by (e.g., "points", "wins"). limit (int): The maximum number of results to return. Defaults to 10. aggregate (bool): Whether to aggregate the stats. Defaults to False.
Returns:
| Name | Type | Description |
|---|---|---|
TeamStats |
TeamStats
|
An instance of the TeamStats model, populated with the fetched data.
The actual team statistics can be accessed via |
Fetch a list of all NHL teams.
Returns:
| Type | Description |
|---|---|
list[Team]
|
list[Team]: A list of Team objects. |
Fetch a roster for a specific team.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
team_code
|
str
|
The team code (e.g., 'TOR', 'NYR'). |
required |
season
|
str
|
The season in format "YYYY-YYYY" (e.g., "2023-2024"). If None, gets current roster. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Roster |
Roster
|
A Roster object containing the team's players. |
Team Model¶
edgework.models.team.Team(edgework_client=None, obj_id=None, **kwargs)
¶
Bases: BaseNHLModel
Team model to store team information.
Initialize a Team object with dynamic attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edgework_client
|
The Edgework client (optional for team data from API) |
None
|
|
obj_id
|
The ID of the team object |
None
|
|
**kwargs
|
Dynamic attributes for team properties |
{}
|
name
property
¶
Get the team's name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's name. Example: "Toronto Maple Leafs". |
abbrev
property
¶
Get the team's abbreviation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's abbreviation. Example: "TOR". |
full_name
property
¶
Get the team's full name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's full name. Example: "Toronto Maple Leafs". |
location
property
¶
Get the team's location.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's location/city. Example: "Toronto". |
common_name
property
¶
Get the team's common name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's common name. Example: "Maple Leafs". |
__str__()
¶
String representation showing team name and abbreviation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formatted string with team name and abbreviation. Examples: "Toronto Maple Leafs (TOR)", "Edmonton Oilers (EDM)", or just "Toronto Maple Leafs" if no abbreviation available. |
__repr__()
¶
Developer representation of the Team object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Developer-friendly string representation showing the team ID. Example: "Team(id=10)". |
__eq__(other)
¶
Compare teams by their team_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
The other object to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both objects are Team instances with the same team_id, False otherwise. |
__hash__()
¶
Hash based on team_id for use in sets and dicts.
Returns:
| Name | Type | Description |
|---|---|---|
int |
Hash value based on the team_id. |
fetch_data()
¶
Fetch the data for the team from the API.
Uses the NHL Stats API team endpoint to get detailed team information.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no client is available to fetch team data. |
ValueError
|
If no team ID is available to fetch data. |
get_roster(season=None)
¶
Get the roster for this team.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current roster. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Roster |
Roster
|
The team's roster. |
get_stats(season=None, game_type=2)
¶
Get team stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current season. |
None
|
game_type
|
int
|
Game type (2 for regular season, 3 for playoffs). |
2
|
Returns:
| Type | Description |
|---|---|
|
Response with team stats. |
get_schedule(season=None)
¶
Get team schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current season. |
None
|
Returns:
| Type | Description |
|---|---|
|
Response with team schedule. |
get_prospects()
¶
Get team prospects.
Returns:
| Type | Description |
|---|---|
|
Response with team prospects. |
Roster Model¶
edgework.models.team.Roster(edgework_client, obj_id=None, **kwargs)
¶
Bases: BaseNHLModel
Roster model to store a team's roster information.
Initialize a Roster object with dynamic attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edgework_client
|
The Edgework client |
required | |
obj_id
|
The ID of the roster (team_id) |
None
|
|
**kwargs
|
Dynamic attributes for roster properties |
{}
|
players
property
¶
Get all players in the roster.
Returns:
| Type | Description |
|---|---|
List[Player]
|
List[Player]: List of all players in the roster. |
forwards
property
¶
Get the forwards from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of forwards in the roster. |
defensemen
property
¶
Get the defensemen from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of defensemen in the roster. |
goalies
property
¶
Get the goalies from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of goalies in the roster. |
get_player_by_number(sweater_number)
¶
Get a player by their sweater number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sweater_number
|
int
|
The player's sweater number |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Player |
Optional[Player]
|
The player with the given number, or None if not found. |
get_player_by_name(name)
¶
Get a player by their full name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The player's full name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Player |
Optional[Player]
|
The player with the given name, or None if not found. |
fetch_data()
¶
Fetch the roster data from the API.
Team Client¶
edgework.clients.team_client.TeamClient(client)
¶
Client for team-related API operations.
get_team(team_id)
¶
get_roster(team_code, season=None)
¶
get_team_stats(team_code, season=None, game_type=2)
¶
Get team statistics.
Parameters¶
team_code : str The team code for the team (e.g., 'TOR', 'NYR') season : Optional[int] The season in YYYYYYYY format (e.g., 20232024). If None, gets current stats. game_type : int Game type (2 for regular season, 3 for playoffs). Default is 2.
Returns¶
dict Team statistics data.
get_team_schedule(team_code, season=None)
¶
get_team_prospects(team_code)
¶
Team Model¶
edgework.models.team.Team(edgework_client=None, obj_id=None, **kwargs)
¶
Bases: BaseNHLModel
Team model to store team information.
Initialize a Team object with dynamic attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edgework_client
|
The Edgework client (optional for team data from API) |
None
|
|
obj_id
|
The ID of the team object |
None
|
|
**kwargs
|
Dynamic attributes for team properties |
{}
|
name
property
¶
Get the team's name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's name. Example: "Toronto Maple Leafs". |
abbrev
property
¶
Get the team's abbreviation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's abbreviation. Example: "TOR". |
full_name
property
¶
Get the team's full name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's full name. Example: "Toronto Maple Leafs". |
location
property
¶
Get the team's location.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's location/city. Example: "Toronto". |
common_name
property
¶
Get the team's common name.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The team's common name. Example: "Maple Leafs". |
__str__()
¶
String representation showing team name and abbreviation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formatted string with team name and abbreviation. Examples: "Toronto Maple Leafs (TOR)", "Edmonton Oilers (EDM)", or just "Toronto Maple Leafs" if no abbreviation available. |
__repr__()
¶
Developer representation of the Team object.
Returns:
| Name | Type | Description |
|---|---|---|
str |
Developer-friendly string representation showing the team ID. Example: "Team(id=10)". |
__eq__(other)
¶
Compare teams by their team_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
The other object to compare with. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both objects are Team instances with the same team_id, False otherwise. |
__hash__()
¶
Hash based on team_id for use in sets and dicts.
Returns:
| Name | Type | Description |
|---|---|---|
int |
Hash value based on the team_id. |
fetch_data()
¶
Fetch the data for the team from the API.
Uses the NHL Stats API team endpoint to get detailed team information.
Raises:
| Type | Description |
|---|---|
ValueError
|
If no client is available to fetch team data. |
ValueError
|
If no team ID is available to fetch data. |
get_roster(season=None)
¶
Get the roster for this team.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current roster. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Roster |
Roster
|
The team's roster. |
get_stats(season=None, game_type=2)
¶
Get team stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current season. |
None
|
game_type
|
int
|
Game type (2 for regular season, 3 for playoffs). |
2
|
Returns:
| Type | Description |
|---|---|
|
Response with team stats. |
get_schedule(season=None)
¶
Get team schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
season
|
Optional[int]
|
Optional season (e.g., 20232024). If None, gets current season. |
None
|
Returns:
| Type | Description |
|---|---|
|
Response with team schedule. |
get_prospects()
¶
Get team prospects.
Returns:
| Type | Description |
|---|---|
|
Response with team prospects. |
Roster Model¶
edgework.models.team.Roster(edgework_client, obj_id=None, **kwargs)
¶
Bases: BaseNHLModel
Roster model to store a team's roster information.
Initialize a Roster object with dynamic attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edgework_client
|
The Edgework client |
required | |
obj_id
|
The ID of the roster (team_id) |
None
|
|
**kwargs
|
Dynamic attributes for roster properties |
{}
|
players
property
¶
Get all players in the roster.
Returns:
| Type | Description |
|---|---|
List[Player]
|
List[Player]: List of all players in the roster. |
forwards
property
¶
Get the forwards from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of forwards in the roster. |
defensemen
property
¶
Get the defensemen from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of defensemen in the roster. |
goalies
property
¶
Get the goalies from the roster.
Returns:
| Type | Description |
|---|---|
list[Player]
|
list[Player]: List of goalies in the roster. |
get_player_by_number(sweater_number)
¶
Get a player by their sweater number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sweater_number
|
int
|
The player's sweater number |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Player |
Optional[Player]
|
The player with the given number, or None if not found. |
get_player_by_name(name)
¶
Get a player by their full name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The player's full name |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Player |
Optional[Player]
|
The player with the given name, or None if not found. |
fetch_data()
¶
Fetch the roster data from the API.
Usage Examples¶
Getting Team Information¶
from edgework import Edgework
client = Edgework()
# Get team statistics
team_stats = client.team_stats(
season="2023-2024",
sort="points",
limit=10
)
for team in team_stats:
print(f"{team.name}: {team.points} points")
Working with Team Objects¶
# Assuming you have a Team object
team = team_stats[0] # First team from stats
print(f"Team: {team.full_name}")
print(f"Abbreviation: {team.abbrev}")
print(f"Location: {team.location}")
Getting Team Rosters¶
from edgework import Edgework
client = Edgework()
# Get team statistics first to get team objects
team_stats = client.team_stats(season="2023-2024", limit=1)
team = team_stats[0]
# Get current roster
roster = team.get_roster()
print(f"Roster for {team.name}:")
print(f"Forwards: {len(roster.forwards)}")
print(f"Defensemen: {len(roster.defensemen)}")
print(f"Goalies: {len(roster.goalies)}")
Team Schedule¶
# Get team schedule
schedule = team.get_schedule(season="2023-2024")
# Get current season schedule
current_schedule = team.get_schedule()
Team Prospects¶
Team Properties¶
Basic Information¶
team_id- Unique team identifierteam_abbrev- Team abbreviation (e.g., "TOR", "MTL")team_name- Team namefull_name- Full team namelocation_name- Team locationteam_common_name- Common team nameteam_place_name- Team place name
Branding¶
logo- Team logo URLdark_logo- Dark version of team logowebsite- Team website URL
League Information¶
conference- Conference namedivision- Division namefranchise_id- Franchise identifieractive- Whether team is active
Localization¶
french_name- French team namefrench_place_name- French place name
Roster Properties¶
Basic Information¶
season- Season for the rosterroster_type- Type of rosterteam_abbrev- Team abbreviationteam_id- Team identifier
Players¶
players- List of all playersforwards- List of forwardsdefensemen- List of defensemengoalies- List of goalies
Advanced Usage¶
Working with Rosters¶
from edgework import Edgework
client = Edgework()
# Get a team
team_stats = client.team_stats(season="2023-2024", limit=1)
team = team_stats[0]
# Get roster
roster = team.get_roster()
# Analyze roster composition
print(f"Forwards:")
for player in roster.forwards:
print(f" {player.first_name} {player.last_name} - #{player.sweater_number}")
print(f"\nDefensemen:")
for player in roster.defensemen:
print(f" {player.first_name} {player.last_name} - #{player.sweater_number}")
print(f"\nGoalies:")
for player in roster.goalies:
print(f" {player.first_name} {player.last_name} - #{player.sweater_number}")
Historical Rosters¶
# Get roster for a specific season
historical_roster = team.get_roster(season=20222023)
print(f"Roster for {team.name} in 2022-2023:")
print(f"Total players: {len(historical_roster.players)}")
Team Statistics Analysis¶
from edgework import Edgework
client = Edgework()
# Get all team stats
all_teams = client.team_stats(season="2023-2024")
# Sort by different metrics
by_points = sorted(all_teams, key=lambda t: t.points, reverse=True)
by_goals = sorted(all_teams, key=lambda t: t.goals_for, reverse=True)
by_defense = sorted(all_teams, key=lambda t: t.goals_against)
print("Top 5 teams by points:")
for i, team in enumerate(by_points[:5], 1):
print(f"{i}. {team.name}: {team.points} points")
print("\nTop 5 teams by goals:")
for i, team in enumerate(by_goals[:5], 1):
print(f"{i}. {team.name}: {team.goals_for} goals")
print("\nTop 5 defensive teams:")
for i, team in enumerate(by_defense[:5], 1):
print(f"{i}. {team.name}: {team.goals_against} goals against")