Event
Event Class
Represents a sports event within the ESPN API framework.
This class acts as a central unit for encapsulating all relevant data associated with a sporting event, including participating teams, venue details, drives (football), play-by-play actions (basketball), competition metadata, and betting odds.
Attributes:
Name | Type | Description |
---|---|---|
event_json |
dict
|
The raw JSON data from ESPN describing the event. |
espn_instance |
PYESPN
|
The active ESPN API interface used for data lookups. |
url_ref |
str
|
ESPN API reference URL to this event. |
event_id |
int
|
Unique identifier for the event. |
date |
str
|
Date and time of the event in ISO format. |
event_name |
str
|
Full name of the event. |
short_name |
str
|
Abbreviated name of the event. |
competition_type |
str
|
Type of competition (e.g. "regular", "postseason"). |
venue_json |
dict
|
Raw JSON data representing the venue. |
event_venue |
Venue
|
Venue object built from the venue JSON. |
event_notes |
list
|
Optional notes or metadata about the event. |
home_team |
Team
|
Team object representing the home team. |
away_team |
Team
|
Team object representing the away team. |
api_info |
dict
|
League-specific metadata used to construct ESPN URLs. |
competition |
Competition
|
An object containing metadata about the specific competition. |
odds |
list[GameOdds]
|
List of betting odds (if available). |
drives |
list[Drive] or None
|
A list of |
plays |
list[Play] or None
|
A list of |
Methods:
Name | Description |
---|---|
load_betting_odds |
Fetches and parses multi-page betting odds data. |
load_play_by_play |
Routes to appropriate play-by-play loader depending on sport type. |
_load_competition_data |
Loads metadata about the specific competition instance. |
_load_teams |
Populates home_team and away_team attributes from competitors JSON. |
_load_basketball_plays |
Loads all basketball plays as |
_load_drive_data |
Loads all football drives as |
to_dict |
Returns the original raw JSON for this event. |
__repr__ |
A readable string representation showing the event short name and date. |
Source code in pyespn/classes/event.py
8 9 10 11 12 13 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 319 |
|
away_team
property
Team: the away team as a Team object
drives
property
list[Drive]: a list of drives for the given event
espn_instance
property
PYESPN: the espn client instance associated with the class
event_id
property
str: the id for the event
home_team
property
Team: the home team as a Team object
odds
property
list[Betting]: a list of Odds for the given game
plays
property
list[Play]: a list of drives for the given event
__init__(event_json, espn_instance, load_game_odds=False, load_play_by_play=False)
Initializes an Event instance with the provided JSON data.
This constructor optionally loads betting odds and play-by-play data based on the supplied flags. By default, those are not loaded unless explicitly enabled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_json
|
dict
|
The JSON data containing event details. |
required |
espn_instance
|
PYESPN
|
The parent |
required |
load_game_odds
|
bool
|
If True, fetch and load the betting odds for the event. Defaults to False. |
False
|
load_play_by_play
|
bool
|
If True, fetch and load the play-by-play data (either drives or plays depending on sport). Defaults to False. |
False
|
Source code in pyespn/classes/event.py
__repr__()
Returns a string representation of the Team instance.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string with the events data. |
load_betting_odds()
method to fetch and assign betting odds for the event.
This method constructs the appropriate URL using event and league data, then retrieves
and parses odds data from each available page. The results are stored in the self.odds
list
as GameOdds
instances.
Source code in pyespn/classes/event.py
load_play_by_play()
Private method to load play-by-play data for the event.
This method routes the data fetching logic based on the sport type—calling
_load_basketball_plays()
for basketball and _load_drive_data()
for football.
Source code in pyespn/classes/event.py
to_dict()
Converts the Event instance to its original JSON dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The event's raw JSON data. |