League Class Documentation
Represents a sports league with associated data such as teams, events, rankings, betting futures, and statistical leaders.
This class provides methods for loading and managing league-level data retrieved from the ESPN API, including season-specific information, betting data, and statistical leaderboards.
Attributes:
Name | Type | Description |
---|---|---|
espn_instance |
PyESPN
|
The main interface for interacting with ESPN's API. |
league_json |
dict
|
The raw JSON data representing the league. |
ref |
str
|
Reference URL for the league. |
id |
str
|
The unique identifier for the league. |
name |
str
|
Full name of the league. |
display_name |
str
|
Human-readable display name for the league. |
abbreviation |
str
|
Abbreviated name of the league. |
short_name |
str
|
Shortened name version of the league. |
slug |
str
|
URL-friendly version of the league's name. |
is_tournament |
bool
|
Whether the league is a tournament format. |
season |
dict
|
Details for the current season. |
seasons |
list
|
A list of past and present seasons. |
franchises |
list
|
Franchises associated with the league. |
teams |
list
|
List of teams in the league. |
group |
dict
|
Group metadata the league is associated with. |
groups |
list
|
Collection of groups within the league. |
events |
list
|
Events related to the league. |
notes |
str
|
Additional notes or commentary on the league. |
rankings |
list
|
Ranking data for the league. |
draft |
dict
|
Draft data associated with the league. |
links |
list
|
External or internal links related to the league. |
league_leaders |
dict
|
Cached leader category objects per season. |
betting_futures |
dict
|
Cached betting futures data per season. |
Methods:
Name | Description |
---|---|
__repr__ |
Returns a formatted string representation of the league. |
_set_league_json |
Internal method to populate league attributes from JSON. |
load_season_free_agents |
Placeholder for loading free agent data for a season. |
get_all_seasons_futures |
Loads and processes all betting futures for the given season. |
_process_bet |
Internal helper to create a Betting object from a bet JSON. |
fetch_leader_category |
Loads and returns a LeaderCategory object. |
load_season_league_leaders |
Loads statistical leaders for a given season. |
Source code in pyespn/classes/league.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
betting_futures
property
dict: a dict of seasons with a key for season with a Betting objects
espn_instance
property
PYESPN: the espn client instance associated with the class
league_leaders
property
dict: dict with key of season with list of Categories
schedules
property
dict: a dict of seasons with a key for season with a Schedule object with Week objects
__init__(espn_instance, league_json)
Initializes a League instance using the provided ESPN API instance and league JSON data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
espn_instance
|
PyESPN
|
The ESPN API instance. |
required |
league_json
|
dict
|
The raw JSON data representing the league. |
required |
Source code in pyespn/classes/league.py
__repr__()
Returns a string representation of the betting Provider instance.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string with the Providers information . |
fetch_leader_category(category, season)
Fetches leader category data for a specific category in the given season.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
dict
|
The category data to be processed. |
required |
season
|
str
|
The season for which the leader data is fetched. |
required |
Returns:
Name | Type | Description |
---|---|---|
LeaderCategory |
LeaderCategory
|
The LeaderCategory object created for this category. |
Source code in pyespn/classes/league.py
get_all_seasons_futures(season)
Loads and processes betting futures for a given season.
This method retrieves betting futures data for the specified season using the ESPN API.
It handles pagination and concurrent data fetching using thread pools for improved performance.
Each betting item is processed individually through _process_bet
and collected into a list.
The processed futures are stored in self._betting_futures
under the specified season key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
season
|
int or str
|
The season year to fetch futures data for. |
required |
Raises:
Type | Description |
---|---|
API400Error
|
If the ESPN API returns a 400-level error during data fetching, an error message will be printed including the season, team name, and team ID. |
Source code in pyespn/classes/league.py
get_event_by_season(season, event_id)
Finds and returns the Team object that matches the given team_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
season
|
int or str
|
the season to pull the athlete from |
required |
event_id
|
int or str
|
The ID of the event to find. |
required |
Returns:
Name | Type | Description |
---|---|---|
Event |
Event
|
The matching Event object, or None if not found. |
Source code in pyespn/classes/league.py
load_regular_season_schedule(season, load_game_odds=False, load_game_play_by_play=False)
Loads and stores the regular season schedule for the specified season.
This method fetches the full regular season schedule for the league associated with the current
ESPN instance and stores it in the internal _schedules
dictionary under the provided season key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
season
|
int or str
|
The season year for which to load the schedule (e.g., 2023). |
required |
load_game_odds
|
bool
|
Whether to include betting odds for each game. Defaults to False. |
False
|
load_game_play_by_play
|
bool
|
Whether to include play-by-play data for each game. Defaults to False. |
False
|
Side Effects
- Updates the
_schedules
dictionary with aSchedule
object containing all weeks and events for the specified season.
Example
espn.load_regular_season_schedule(2024, load_game_odds=True) schedule = espn._schedules[2024] print(schedule.weeks)
Source code in pyespn/classes/league.py
load_season_league_leaders(season)
Fetches the league leaders for the given season using futures to process categories concurrently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
season
|
str
|
The season for which the league leaders are fetched. |
required |
Source code in pyespn/classes/league.py
to_dict()
Converts the League instance to its original JSON dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The league's raw JSON data. |