### Install ESPN API with Pip Source: https://github.com/cwendt94/espn-api/blob/master/README.md The simplest way to install the package if you don't need to modify the source code. ```bash pip install espn_api ``` -------------------------------- ### Install ESPN API with Git and Setup.py Source: https://github.com/cwendt94/espn-api/blob/master/README.md Use this method for older Python versions. Clone the repository and install using setup.py. ```bash git clone https://github.com/cwendt94/espn-api cd espn-api python3 setup.py install ``` -------------------------------- ### Install ESPN API with Git and Requirements.txt Source: https://github.com/cwendt94/espn-api/blob/master/README.md Recommended for Python 3.9+. Clone the repository, set up a virtual environment, and install dependencies. ```bash git clone https://github.com/cwendt94/espn-api cd espn-api python -m venv myenv myenv\Scripts\activate.bat pip install -r requirementsV2.txt ``` -------------------------------- ### Player Class Variables Documentation (Python) Source: https://github.com/cwendt94/espn-api/wiki/Player-Class Lists and describes the variables available in the Player Class. Includes data types and example values for context. ```python name: str playerId: int posRank: int # players positional rank eligibleSlots: List[str] # example ['WR', 'WR/TE/RB'] lineupSlot: str # the players lineup position acquisitionType: str proTeam: str # 'PIT' or 'LAR' schedule: dict # key is scoring period, example: {'1': {'team': 'LAR', 'date': datetime.datetime(2018, 10, 17, 23, 0)}} onTeamId: int # id of fantasy team position: str # main position like 'TE' or 'QB' injuryStatus: str injured: boolean total_points: int # players total points during the season avg_points: int # players average points during the season projected_total_points: int # projected player points for the season projected_avg_points: int # projected players average points for the season percent_owned: int # percentage player is rostered percent_started: int # percentage player is started stats: dict # holds each week stats, actual and projected points. # week 1 example {1: {'breakdown': {'receivingReceptions': 1.7, 'rushingYards': 7.9}, 'points': 14.57, 'projected_points': 24.64, 'projected_breakdown': {'receivingReceptions': 6.354896833, 'rushingYards': 7.890957077}}} ``` -------------------------------- ### Get Standings Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Helper function to retrieve the current standings for the league. ```python3 def standings() -> List[Team]: ``` -------------------------------- ### Get Scoreboard Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve the scoreboard for the current or a specific week, showing all matchups. ```APIDOC ## Get Scoreboard ### Description Fetch the scoreboard for a given week, displaying all the matchups scheduled for that period. You can also retrieve the current week's scoreboard by default. ### Parameters - `week` (int, optional): The specific week number for which to retrieve the scoreboard. If not provided, the current week is used. ### Usage ```python >>> league.scoreboard() [Matchup(Team(Team 8), Team(THE KING)), Matchup(Team(Team 7), Team(Team 1)), Matchup(Team(Team 2), Team(Team Viking Queen)), Matchup(Team(Team Mizrachi), Team(FANTASY GOD)), Matchup(Team(Team 10), Team(Team 5))] >>> week = 3 >>> matchups = league.scoreboard(week) >>> matchups[0].home_score 89.2 >>> matchups[0].away_score 88.62 >>> matchups [Matchup(Team(Team 1), Team(Team 10)), Matchup(Team(FANTASY GOD), Team(THE KING)), Matchup(Team(Team 7), Team(Team Viking Queen)), Matchup(Team(Team 5), Team(Team 2)), Matchup(Team(Team Mizrachi), Team(Team 8))] >>> matchups[0].home_team Team(Team 1) >>> matchups[0].away_team Team(Team 10) ``` ``` -------------------------------- ### Get Free Agents Source: https://github.com/cwendt94/espn-api/wiki/League-Class Retrieves a list of free agents. You can filter by week, size, and specific positions like 'QB', 'RB', 'WR', 'TE', 'D/ST', 'K', or 'FLEX'. ```python3 # position inputs: 'QB', 'RB', 'WR', 'TE', 'D/ST', 'K', 'FLEX' def free_agents(week: int = None, size: int = 50, position: str = None, position_id: int=None) -> List[BoxPlayer]: ``` -------------------------------- ### Get Scoreboard Data Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Retrieves basic information about matchups for a specified week. Can be used for current or past years. ```python3 def scoreboard(week: int = None) -> List[Matchup]: ``` -------------------------------- ### refresh Source: https://github.com/cwendt94/espn-api/wiki/League-Class Gets the latest league data. This can be used instead of creating a new League class each week. ```APIDOC ## refresh ### Description Gets latest league data. This can be used instead of creating a new League class each week. ### Method ```python def refresh() -> None: ``` ``` -------------------------------- ### View Team Information and Roster Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Access a league's teams and retrieve detailed information about a specific team, including its roster, wins, losses, and final standing. Use this to get an overview of your league's teams. ```python >>> league.teams [Team(Team 1), Team(Team 2), Team(FANTASY GOD), Team(THE KING), Team(Team 5), Team(Team Viking Queen), Team(Team 7), Team(Team 8), Team(Team Mizrachi), Team(Team 10)] >>> team = league.teams[0] >>> team.roster [Player(Damian Lillard), Player(Russell Westbrook), Player(Jimmy Butler), Player(Bam Adebayo), Player(T.J. Warren), Player(Mitchell Robinson), Player(John Wall), Player(LaMarcus Aldridge), Player(Tyrese Haliburton), Player(Mason Plumlee), Player(Ivica Zubac), Player(Otto Porter Jr.), Player(Killian Hayes)] >>> team.wins 10 >>> team.losses 3 >>> team.final_standing 4 >>> team.team_name 'Team 1' ``` -------------------------------- ### Get Most Points Against Source: https://github.com/cwendt94/espn-api/wiki/League-Class Identifies and returns the team that has had the most points scored against them. ```python3 def most_points_against() -> Team: ``` -------------------------------- ### Get Recent Activity Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves a list of recent activities in the league, such as trades, drops, and adds. ```APIDOC ## Leagues Recent Activity ### Description This can be used to view league trades and waiver wire drops/adds. ### Method league.recent_activity(size: int = 25, msg_type: str = None) ### Parameters #### Query Parameters - **size** (int) - Optional - Defaults to 25. The number of recent activities to retrieve. - **msg_type** (str) - Optional - Filters activities by type (e.g., 'TRADED', 'DROPPED', 'ADDED'). ### Response #### Success Response - List[Activity] - A list of Activity objects representing recent league events. ### Activity Object Details - **actions** (List[Tuple[Team, str, str]]) - A list of tuples, where each tuple contains a Team object, an action string (e.g., 'DROPPED', 'ADDED', 'TRADED'), and a player name (string). ``` -------------------------------- ### Get Power Rankings Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves the power rankings for a specific week in the fantasy league. The output is a list of tuples, each containing a score and a Team object. ```python >>> league.power_rankings(week=13) [('70.85', Team(Team 7)), ('65.20', Team(Team 1)), ('62.45', Team(Team 8)), ('57.70', Team(THE KING)), ('45.10', Team(Team Mizrachi)), ('42.80', Team(Team 10)), ('40.65', Team(Team Viking Queen)), ('37.30', Team(Team 2)), ('27.85', Team(Team 5)), ('20.40', Team(FANTASY GOD))] ``` -------------------------------- ### Get Player Information Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Retrieves detailed information for a player by name or ID. If a list of player IDs is provided, it returns a list of players. Returns None if the player is not found. ```python3 def player_info(name: str = None, playerId: Union[int, list] = None) -> Union[Player, List[Player]]: ``` -------------------------------- ### Get Player Details Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieve comprehensive details for a specific player, including their name, player ID, rank, position, pro team, eligible slots, and acquisition type. ```python >>> team = league.teams[0] >>> player = team.roster[0] >>> player Player(Travis Kelce) >>> player.name 'Travis Kelce' >>> player.playerId 15847 >>> player.posRank 10 >>> player.position 'TE' >>> player.proTeam 'KC' >>> player.eligibleSlots ['WR/TE', 'TE', 'OP', 'BE', 'IR', 'RB/WR/TE'] >>> player.acquisitionType 'DRAFT' ``` -------------------------------- ### Get Team Data Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves the data for a specific team using its ID. ```APIDOC ## Get Team Data ### Description Retrieves the data for a specific team using its ID. ### Method league.get_team_data(team_id: int) ### Parameters #### Path Parameters - **team_id** (int) - Required - The unique identifier for the team. ### Response #### Success Response - Team - The Team object corresponding to the provided team ID. ``` -------------------------------- ### Get Top Scorer Source: https://github.com/cwendt94/espn-api/wiki/League-Class Identifies and returns the team with the highest total score. ```python3 def top_scorer() -> Team: ``` -------------------------------- ### Get Box Scores Source: https://github.com/cwendt94/espn-api/wiki/League-Class Returns more specific information on week matchups. This function is only applicable to the current season. ```python3 def box_scores(week: int = None) -> List[BoxScore]: ``` -------------------------------- ### Get Scoreboard for a Specific Week Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve the scoreboard for the current or a specified week, showing all matchups and their scores. This is useful for tracking game results and league progress. ```python >>> league.scoreboard() [Matchup(Team(Team 8), Team(THE KING)), Matchup(Team(Team 7), Team(Team 1)), Matchup(Team(Team 2), Team(Team Viking Queen)), Matchup(Team(Team Mizrachi), Team(FANTASY GOD)), Matchup(Team(Team 10), Team(Team 5))] >>> week = 3 >>> matchups = league.scoreboard(week) >>> matchups[0].home_score 89.2 >>> matchups[0].away_score 88.62 >>> matchups [Matchup(Team(Team 1), Team(Team 10)), Matchup(Team(FANTASY GOD), Team(THE KING)), Matchup(Team(Team 7), Team(Team Viking Queen)), Matchup(Team(Team 5), Team(Team 2)), Matchup(Team(Team Mizrachi), Team(Team 8))] >>> matchups[0].home_team Team(Team 1) >>> matchups[0].away_team Team(Team 10) ``` -------------------------------- ### Player Information Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Get detailed information about individual players, including their ID, position, pro team, eligible slots, and acquisition type. ```APIDOC ## Player Information ### Description Retrieve comprehensive details for a specific player, such as their unique ID, playing position, associated professional team, eligible fantasy slots, and how they were acquired. ### Usage ```python >>> team = league.teams[0] >>> player = team.roster[0] >>> player Player(Damian Lillard) >>> player.name 'Damian Lillard' >>> player.playerId 6606 >>> player.position 'PG' >>> player.proTeam 'POR' >>> player.eligibleSlots ['PG', 'G', 'G/F', 'UT', 'BE', 'IR'] >>> player.acquisitionType 'DRAFT' ``` ``` -------------------------------- ### Get Recent Activity Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Fetches a list of recent activities such as free agent acquisitions, waiver claims, or trades. Requires authentication. Filter by message type. ```python3 # msg_type inputs: 'FA', 'WAVIER', 'TRADED' def recent_activity(size: int = 25, msg_type: str = None) -> List[Activity]: ``` -------------------------------- ### Get Specific Team Data Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Helper function to retrieve all data for a specific team using its ID. ```python3 def get_team_data(team_id: int) -> Team: ``` -------------------------------- ### Get Least Scorer Source: https://github.com/cwendt94/espn-api/wiki/League-Class Identifies and returns the team with the lowest total score. ```python3 def least_scorer() -> Team: ``` -------------------------------- ### Get Box Scores Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Fetches box score data. Can specify matchup period, scoring period, or both. If neither is provided, it defaults to the current matchup and scoring period. `matchup_total` determines if total matchup points or current scoring period points are shown. Category scoring leagues require both `scoring_period` and `matchup_period`. ```python3 def box_scores(matchup_period: int = None, scoring_period: int = None, matchup_total: bool = True) -> List[BoxScore]: ``` -------------------------------- ### Get Box Score Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve the box score for a specific matchup or scoring period, including team scores and player performance details. ```APIDOC ## Get Box Score ### Description Obtain the box score data for a given matchup or scoring period. This includes scores for both the home and away teams, as well as detailed statistics for each player in the lineups. ### Usage ```python >>> box = league.box_scores() >>> box[0].home_team Team(Team fedejko) >>> box[0].away_team Team(Free Cash ) >>> box[0].home_score 280.0 >>> box[0].away_score 450.0 >>> box[0].home_lineup [Player(Delon Wright, points:42), Player(Zach LaVine, points:45), Player(Andrew Wiggins, points:53), Player(Kelly Oubre Jr., points:61), Player(Nikola Vucevic, points:61), Player(Kemba Walker, points:18)] >>> box[0].away_lineup [Player(Nikola Jokic, points:62), Player(Khris Middleton, points:69), Player(Harrison Barnes, points:26), Player(Collin Sexton, points:38), Player(Jerami Grant, points:51), Player(Bradley Beal, points:54), Player(Chris Boucher, points:31), Player(Darius Garland, points:30), Player(Jaylen Brown, points:40), Player(Julius Randle, points:18), Player(Terry Rozier, points:31)] >>> box[0].home_lineup[0].points 42.0 >>> box[0].home_lineup[0].points_breakdown {'FTA': -12.0, 'PTS': 22.0, '3PTM': 0.0, 'BLK': 0.0, 'STL': 8.0, 'AST': 18.0, 'REB': 4.0, 'TO': -4.0, 'FGM': 14.0, 'FGA': -16.0, 'FTM': 8.0} >>> box[0].home_lineup[0].slot_position 'PG' >>> box[0].home_lineup[0].name 'Delon Wright' ``` ``` -------------------------------- ### Get Top Scored Week Source: https://github.com/cwendt94/espn-api/wiki/League-Class Returns a tuple containing the team and the week number in which they scored the most points. ```python3 def top_scored_week() -> Tuple(Team, int): ``` -------------------------------- ### Get Player Details Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve comprehensive details for a specific player, including their ID, position, pro team affiliation, eligible fantasy slots, and acquisition type. Useful for scouting or analyzing player attributes. ```python >>> team = league.teams[0] >>> player = team.roster[0] >>> player Player(Damian Lillard) >>> player.name 'Damian Lillard' >>> player.playerId 6606 >>> player.position 'PG' >>> player.proTeam 'POR' >>> player.eligibleSlots ['PG', 'G', 'G/F', 'UT', 'BE', 'IR'] >>> player.acquisitionType 'DRAFT' ``` -------------------------------- ### Get Recent Activity Source: https://github.com/cwendt94/espn-api/wiki/League-Class Returns a list of activities, such as free agent acquisitions, waiver claims, or trades. This function requires authentication and can be filtered by message type and size. ```python3 # msg_type inputs: 'FA', 'WAIVER', 'TRADED' def recent_activity(size: int = 25, msg_type: str = None, offset: int = 0) -> List[Activity]: ``` -------------------------------- ### Get Player Information Source: https://github.com/cwendt94/espn-api/wiki/League-Class Retrieves a Player object with season stats based on name or player ID. If a list of IDs is provided, it returns a list of players. Returns None if the name or ID is invalid. ```python3 def player_info(name: str = None, playerId: Union[int, list] = None) -> -> Union[Player, List[Player]]: ``` -------------------------------- ### Get Box Score for Matchups Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve box score data for matchups, including home and away teams, scores, and player lineups with their points. You can also access detailed point breakdowns and player information within the lineup. ```python >>> box = league.box_scores() >>> box[0].home_team Team(Team fedejko) >>> box[0].away_team Team(Free Cash ) >>> box[0].home_score 280.0 >>> box[0].away_score 450.0 >>> box[0].home_lineup [Player(Delon Wright, points:42), Player(Zach LaVine, points:45), Player(Andrew Wiggins, points:53), Player(Kelly Oubre Jr., points:61), Player(Nikola Vucevic, points:61), Player(Kemba Walker, points:18)] >>> box[0].away_lineup [Player(Nikola Jokic, points:62), Player(Khris Middleton, points:69), Player(Harrison Barnes, points:26), Player(Collin Sexton, points:38), Player(Jerami Grant, points:51), Player(Bradley Beal, points:54), Player(Chris Boucher, points:31), Player(Darius Garland, points:30), Player(Jaylen Brown, points:40), Player(Julius Randle, points:18), Player(Terry Rozier, points:31)] >>> box[0].home_lineup[0].points 42.0 >>> box[0].home_lineup[0].points_breakdown {'FTA': -12.0, 'PTS': 22.0, '3PTM': 0.0, 'BLK': 0.0, 'STL': 8.0, 'AST': 18.0, 'REB': 4.0, 'TO': -4.0, 'FGM': 14.0, 'FGA': -16.0, 'FTM': 8.0} >>> box[0].home_lineup[0].slot_position 'PG' >>> box[0].home_lineup[0].name 'Delon Wright' ``` -------------------------------- ### Get Power Rankings Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves the power rankings for a given week in the league. Returns a list of tuples, where each tuple contains a score and a Team object. ```APIDOC ## Get power rankings ### Description Retrieves the power rankings for a specified week. ### Method league.power_rankings(week: int) ### Parameters #### Path Parameters - **week** (int) - Required - The week number for which to retrieve power rankings. ### Response #### Success Response - List[Tuple[str, Team]] - A list of tuples, where each tuple contains the power ranking score (string) and the corresponding Team object. ``` -------------------------------- ### Get Box Score for a Specific Week Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Fetches the box scores for a given week, providing detailed information about each team's performance, including scores, lineups, and player statistics. Access individual player data like points, projected points, and position. ```python >>> box_scores = league.box_scores(12) >>> box_scores[0].home_team Team(Team 1) >>> box_scores[0].away_team Team(Team Viking Queen) >>> box_scores[0].home_score 69.24 >>> box_scores[0].away_score 87.62 >>> box_scores[0].home_lineup [Player(Kareem Hunt, points:0, projected:0), Player(Travis Kelce, points:0, projected:0), Player(Zach Ertz, points:15, projected:9), Player(Josh Gordon, points:7, projected:8), Player(Kenyan Drake, points:21, projected:8), Player(Devin Funchess, points:0, projected:0), Player(Tarik Cohen, points:11, projected:8), Player(Wil Lutz, points:10, projected:7), Player(Dion Lewis, points:4, projected:9), Player(Matthew Stafford, points:5, projected:15), Player(Ezekiel Elliott, points:20, projected:17), Player(Brandin Cooks, points:0, projected:0), Player(Kerryon Johnson, points:0, projected:0), Player(Mitchell Trubisky, points:0, projected:0), Player(Bengals D/ST, points:6, projected:-3), Player(Courtland Sutton, points:7, projected:1)] >>> box_scores[0].home_lineup[2].points 15.1 >>> box_scores[0].home_lineup[2].projected_points 9.97 >>> box_scores[0].home_lineup[2].slot_position 'TE' >>> box_scores[0].home_lineup[2].position 'TE' >>> box_scores[0].home_lineup[2].name 'Zach Ertz' >>> box_scores[0].home_lineup[2].pro_opponent 'GB' >>> box_scores[0].home_lineup[2].pro_pos_rank 3 ``` -------------------------------- ### Get Recent League Activity Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves recent league activity, such as trades and player drops/adds. The 'actions' field within each activity item lists the specific transactions, including the team, action type, and player involved. Can filter by message type, e.g., 'TRADED'. ```python # inputs: # - size: int defaults to 25 >>> activity = league.recent_activity() # returns List[Activity] >>> len(activity) 25 # Activity object has a field called actions which is a list of tuples (Team Object, action, player) # this list holds all the actions that happend with this activity >>> activity[0].actions [(Team(Sleepy Joe ), 'DROPPED', "Ka'imi Fairbairn"), (Team(Sleepy Joe ), 'ADDED', 'Ty Long')] >>> for action in activity[0].actions: ... action ... (Team(Sleepy Joe ), 'DROPPED', "Ka'imi Fairbairn") (Team(Sleepy Joe ), 'ADDED', 'Ty Long') >>> for action in activity[24].actions: ... action ... (Team(Mack Sauce), 'DROPPED', 'Terrell Suggs') >>> activitys = league.recent_activity(msg_type='TRADED') >>> for activity in activitys: ... for action in activity.actions: ... action ... print('\n') ... (Team(Team 2), 'TRADED', 'Aaron Rodgers') (Team(Team 1), 'TRADED', 'Adrian Peterson') (Team(Team 2), 'TRADED', 'Leighton Vander Esch') (Team(Team 1), 'TRADED', 'Tom Brady') ``` -------------------------------- ### Initialize League Class Source: https://github.com/cwendt94/espn-api/wiki/League-Class Instantiate the League class with your league ID, year, and optional ESPN authentication tokens. Set debug to True to view API requests and responses. ```python3 from espn_api.football import League league = League(league_id: int, year: int, espn_s2: str = None, swid: str = None, debug=False) ``` -------------------------------- ### View League Settings Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieve league settings such as the number of regular season games, total team count, and the number of veto votes required. ```python >>> settings = league.settings >>> settings.reg_season_count 13 >>> settings.team_count 10 >>> settings.veto_votes_required 4 ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/cwendt94/espn-api/blob/master/README.md Recommended for Python 3.9+ to run the test suite. ```bash pytest ``` -------------------------------- ### Initialize League Object Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Instantiate the League object with your league ID, year, and optional authentication tokens. Set debug to True to see API request/response details. ```python3 from espn_api.basketball import League league = League(league_id: int, year: int, espn_s2: str = None, swid: str = None, debug=False) ``` -------------------------------- ### Import and Initialize ESPN API Leagues Source: https://github.com/cwendt94/espn-api/blob/master/README.md Import the League class for different sports (Football, Basketball, Hockey, Baseball) and initialize a league instance with your league ID and year. ```python # Football API from espn_api.football import League # Basketball API from espn_api.basketball import League # Hockey API from espn_api.hockey import League # Baseball API from espn_api.baseball import League # Init league = League(league_id=222, year=2019) ``` -------------------------------- ### View Free Agents with Filters Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Fetch a list of free agent players, with options to filter by the number of results (size) and player position (e.g., 'QB', 'RB', 'WR', 'TE', 'FLEX', 'D/ST', 'K'). ```python >>> league.free_agents(size=5) [Player(James White), Player(Phillip Lindsay), Player(Jaylen Samuels), Player(LeSean McCoy), Player(David Njoku)] >>> league.free_agents(size=5,position='QB') [Player(Jameis Winston), Player(Baker Mayfield), Player(Dak Prescott), Player(Josh Allen), Player(Nick Foles)] >>> league.free_agents(size=5,position='WR') [Player(Chris Godwin), Player(Mike Williams), Player(Devin Funchess), Player(Emmanuel Sanders), Player(Josh Reynolds)] >>> league.free_agents() [Player(James White), Player(Phillip Lindsay), Player(Jaylen Samuels), Player(LeSean McCoy), Player(David Njoku), Player(Ravens D/ST), Player(Gus Edwards), Player(Kareem Hunt), Player(Jameis Winston), Player(Matt Breida), Player(Chris Godwin), Player(Baker Mayfield), Player(Dak Prescott), Player(Josh Adams), Player(Titans D/ST), Player(Mike Williams), Player(Patriots D/ST), Player(Devin Funchess), Player(Royce Freeman), Player(Emmanuel Sanders), Player(Doug Martin), Player(Josh Reynolds), Player(Cooper Kupp), Player(Josh Allen), Player(T.J. Yeldon), Player(Cameron Brate), Player(Broncos D/ST), Player(DeSean Jackson), Player(DaeSean Hamilton), Player(Duke Johnson Jr.), Player(Derrius Guice), Player(Jeff Wilson Jr.), Player(Dante Pettis), Player(Ian Thomas), Player(Eagles D/ST), Player(Rashaad Penny), Player(Matt Prater), Player(Bills D/ST), Player(Dede Westbrook), Player(O.J. Howard), Player(Nick Foles), Player(Curtis Samuel), Player(Robert Foster), Player(Chiefs D/ST), Player(Hunter Henry), Player(Justin Jackson), Player(Anthony Miller), Player(Jalen Richard), Player(Kalen Ballage), Player(Marquez Valdes-Scantling)] ``` -------------------------------- ### Import and Initialize ESPN API League Objects Source: https://github.com/cwendt94/espn-api/wiki/Home Import the League class for various sports (NFL, NBA, WNBA, MLB, NHL). Initialize a League object with league ID and year. Supports private leagues with espn_s2 and swid cookies, debug mode, and delayed data fetching. ```python3 # NFL Import from espn_api.football import League # NBA Import from espn_api.basketball import League # WNBA Import from espn_api.wbasketball import League # MLB Import from espn_api.baseball import League # NHL Import from espn_api.hockey import League # public league league = League(league_id=1245, year=2018) # private league with cookies league = League(league_id=1245, year=2018, espn_s2='ASCWDWheghjwwqfwjqhgjkjgegkje', swid='{03JFJHW-FWFWF-044G}') # debug mode league = League(league_id=1245, year=2018, debug=True) # won't get any league data when initialized. Make sure to call league.fetch_league() when ready to use. league = League(league_id=1245, year=2018, fetch_league=False) ``` -------------------------------- ### Enable Debug Mode for ESPN API Source: https://github.com/cwendt94/espn-api/blob/master/README.md Initialize the League with `debug=True` to view all ESPN API requests and responses in the console. This is useful for debugging issues. ```python # ... import statement above league = League(league_id=1245, year=2019, debug=True) ``` -------------------------------- ### League Initialization Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Initializes the League object with league ID, year, and optional authentication details. Set debug to True to see API request/response logs. ```APIDOC ## League Initialization ### Description Initializes the League object with league ID, year, and optional authentication details. Set debug to True to see API request/response logs. ### Method ```python League(league_id: int, year: int, espn_s2: str = None, swid: str = None, debug=False) ``` ``` -------------------------------- ### Get Least Scored Week Source: https://github.com/cwendt94/espn-api/wiki/League-Class Returns a tuple containing the team and the week number in which they scored the fewest points. ```python3 def least_scored_week() -> Tuple(Team, int): ``` -------------------------------- ### View and Filter Free Agents Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Fetch a list of free agents from the league. You can filter the results by the number of players to return (size) and by player position. This is helpful for identifying available talent. ```python >>> league.free_agents(size=5) [Player(Jonas Valanciunas), Player(Thaddeus Young), Player(Joe Harris), Player(P.J. Washington), Player(Lauri Markkanen)] >>> league.free_agents(size=5,position='PF') [Player(Thaddeus Young), Player(P.J. Washington), Player(Lauri Markkanen), Player(Robert Covington), Player(Jaren Jackson Jr.)] >>> league.free_agents() [Player(Jonas Valanciunas), Player(Thaddeus Young), Player(Joe Harris), Player(P.J. Washington), Player(Lauri Markkanen), Player(Tim Hardaway Jr.), Player(Robert Covington), Player(OG Anunoby), ...] ``` -------------------------------- ### Settings Class Variables Documentation Source: https://github.com/cwendt94/espn-api/wiki/Settings-Class This snippet lists the variables available in the Settings Class, along with their types and a brief description. It includes settings for regular season games, playoff teams, trade deadlines, and scoring formats. ```python reg_season_count: int veto_votes_required: int team_count: int playoff_team_count: int keeper_count: int trade_deadline: int epoch name: str tie_rule: int playoff_tie_rule: int playoff_seed_tie_rule: int playoff_matchup_period_length: int # Weeks Per Playoff Matchup faab: bool # Is the league using a free agent acquisition budget acquisition_budget: int scoring_format: List[dict] # example [{'abbr': 'RETD', 'label': 'TD Reception', 'id': 43, 'points': 6.0}] ``` -------------------------------- ### View Team Information and Roster Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Access a league's teams and retrieve detailed information for a specific team, including its roster, wins, losses, final standing, and team name. ```python >>> league.teams [Team(Team 1), Team(Team 2), Team(FANTASY GOD), Team(THE KING), Team(Team 5), Team(Team Viking Queen), Team(Team 7), Team(Team 8), Team(Team Mizrachi), Team(Team 10)] >>> team = league.teams[0] >>> team.roster [Player(Travis Kelce), Player(Zach Ertz), Player(Josh Gordon), Player(Kenyan Drake), Player(Tarik Cohen), Player(Wil Lutz), Player(Dion Lewis), Player(Matthew Stafford), Player(Ezekiel Elliott), PLayer(Brandin Cooks), Player(Kerryon Johnson), Player(Mitchell Trubisky), Player(Bengals D/ST), Player(Courtland Sutton), Player(Spencer Ware), Player(Austin Ekeler)] >>> team.wins 10 >>> team.losses 3 >>> team.final_standing 4 >>> team.team_name 'Team 1' ``` -------------------------------- ### Player Class Variables Documentation Source: https://github.com/cwendt94/espn-api/wiki/Player-Class-Basketball Defines the variables and their types for the Player Class. Use this to understand the data structure for player information. ```python3 name: str playerId: int eligibleSlots = List[str] posRank: int # players positional rank acquisitionType: str proTeam: str position: str injuryStatus: str injured: boolean stats: dict # example {'2': {'team': 'NYK', 'date': datetime.datetime(2019, 4, 11, 0, 0), 'total': {'PTS': 20.0, 'BLK': 0.0, 'AST': 3.0}}} schedule: dict # key is scoring period, example: {'2': {'team': 'BKN', 'date': datetime.datetime(2018, 10, 17, 23, 0)}} lineupSlot: str # SG, C, PG, SF, IR total_points: int # players total points during the season avg_points: int # players average points during the season projected_total_points: int # projected player points for the season projected_avg_points: int # projected players average points for the season ``` -------------------------------- ### scoreboard Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Returns basic information on a match up for a current week. This can be used for previous years. Requires a week number. ```APIDOC ## scoreboard ### Description Returns basic information on a match up for a current week. This can be used for previous years. Requires a week number. ### Method ```python scoreboard(week: int = None) -> List[Matchup] ``` ``` -------------------------------- ### Find Free Agents Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Returns a list of available free agents. You can filter by week, size, and position. See Player Class documentation for position inputs. ```python3 # position inputs: 'PG', 'SG', 'SF', 'PF', 'C', 'G', 'F' def free_agents(week: int = None, size: int = 50, position: str = None, position_id: int=None) -> List[Player]: ``` -------------------------------- ### Helper Functions for League Data Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Provides essential helper functions for interacting with league data. This includes initializing a League object, loading specific weeks, retrieving standings, identifying top/least scorers, and accessing team-specific data. ```python >>> from ff_espn_api import League >>> league_id = 1234 >>> year = 2018 >>> league = League(league_id, year) >>> league.load_roster_week(3) >>> league.standings() [Team(Team 8), Team(THE KING), Team(Team 7), Team(Team 1), Team(Team Viking Queen), Team(Team 2), Team(FANTASY GOD), Team(Team Mizrachi), Team(Team 10), Team(Team 5)] >>> league.top_scorer() Team(Team 8) >>> league.least_scorer() Team(FANTASY GOD) >>> league.most_points_against() Team(Team Mizrachi) >>> league.top_scored_week() (Team(Team Viking Queen), 219.74) >>> league.least_scored_week() (Team(Team 5), 41.48) >>> league.get_team_data(1) Team(Team 1) ``` -------------------------------- ### standings Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Retrieves the current standings for the league. ```APIDOC ## standings ### Description Retrieves the current standings for the league. ### Method ```python standings() -> List[Team] ``` ``` -------------------------------- ### League Standings Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Retrieves the current standings of the league. ```APIDOC ## League Standings ### Description Retrieves the current standings of the league. ### Method league.standings() ### Response #### Success Response - List[Team] - A list of Team objects representing the league standings, ordered from best to worst. ``` -------------------------------- ### View Team Information Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro Retrieve details about teams in a league, including their roster, wins, losses, final standing, and team name. ```APIDOC ## View Team Information ### Description Access information about teams within a fantasy league, including their roster, win-loss record, and final standings. ### Usage ```python >>> league.teams [Team(Team 1), Team(Team 2), Team(FANTASY GOD), Team(THE KING), Team(Team 5), Team(Team Viking Queen), Team(Team 7), Team(Team 8), Team(Team Mizrachi), Team(Team 10)] >>> team = league.teams[0] >>> team.roster [Player(Damian Lillard), Player(Russell Westbrook), Player(Jimmy Butler), Player(Bam Adebayo), Player(T.J. Warren), Player(Mitchell Robinson), Player(John Wall), Player(LaMarcus Aldridge), Player(Tyrese Haliburton), Player(Mason Plumlee), Player(Ivica Zubac), Player(Otto Porter Jr.), Player(Killian Hayes)] >>> team.wins 10 >>> team.losses 3 >>> team.final_standing 4 >>> team.team_name 'Team 1' ``` ``` -------------------------------- ### View Free Agents Source: https://github.com/cwendt94/espn-api/wiki/Basketball-Intro List available free agents in the league, with options to filter by size and position. ```APIDOC ## View Free Agents ### Description Fetch a list of players available in free agency. You can specify the number of results and filter by player position. ### Parameters - `size` (int, optional): The maximum number of free agents to return. - `position` (str, optional): Filters free agents by the specified position (e.g., 'PG', 'PF'). ### Usage ```python >>> league.free_agents(size=5) [Player(Jonas Valanciunas), Player(Thaddeus Young), Player(Joe Harris), Player(P.J. Washington), Player(Lauri Markkanen)] >>> league.free_agents(size=5,position='PF') [Player(Thaddeus Young), Player(P.J. Washington), Player(Lauri Markkanen), Player(Robert Covington), Player(Jaren Jackson Jr.)] >>> league.free_agents() [Player(Jonas Valanciunas), Player(Thaddeus Young), Player(Joe Harris), Player(P.J. Washington), Player(Lauri Markkanen), Player(Tim Hardaway Jr.), Player(Robert Covington), Player(OG Anunoby), ...] ``` ``` -------------------------------- ### View League Draft Picks Source: https://github.com/cwendt94/espn-api/wiki/Football-Intro Access the league's draft results, including player names, pick numbers, round information, and the team that made the pick. ```python >>> league.draft [Pick(LeVeon Bell, Team(FANTASY GOD)), Pick(Todd Gurley II, Team(Team Mizrachi)), Pick(David Johnson, Team(Team 8)), Pick(Antonio Brown, Team(THE KING)), Pick(Ezekiel Elliott, Team(Team 7)), Pick(DeAndre Hopkins, Team(Team 2)), Pick(Julio Jones, Team(Team Viking Queen)), Pick(Alvin Kamara, Team(Team 10)), Pick(Odell Beckham Jr., Team(Team 5)), Pick(Kareem Hunt, Team(Team 1)), Pick(Michael Thomas, Team(Team 1))...] >>> first_pick = league.draft[0] >>> first_pick.playerName "Le'Veon Bell" >>> first_pick.round_num 1 >>> first_pick.round_pick 1 >>> first_pick.team Team(FANTASY GOD) ``` -------------------------------- ### Activity Class Variables Source: https://github.com/cwendt94/espn-api/wiki/Activity-Class Defines the data types for 'date' and 'actions' within the Activity Class. 'date' is an epoch time in milliseconds, and 'actions' is a list of tuples containing team, action type, player, and bid amount. ```python date: int # Epoch time milliseconds actions: List[Tuple] # Tuple includes (team: Team Class, action: str, player: Player Class, bid_amount: int) ``` -------------------------------- ### recent_activity Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Returns a list of Activities (e.g., 'FA', 'WAVIER', 'TRADED'). Requires authentication. Allows specifying the number of activities and message type. ```APIDOC ## recent_activity ### Description Returns a list of Activities (e.g., 'FA', 'WAVIER', 'TRADED'). Requires authentication. Allows specifying the number of activities and message type. ### Method ```python recent_activity(size: int = 25, msg_type: str = None) -> List[Activity] ``` ``` -------------------------------- ### Team Class Variables Documentation Source: https://github.com/cwendt94/espn-api/wiki/Team-Class Lists and describes the variables associated with a team object. Includes identifiers, performance stats, roster, and scheduling information. Note that owner name attributes are only available for private leagues. ```python3 team_id: int team_abbrev: str team_name: str division_id: str division_name: str wins: int losses: int ties: int points_for: int # total points for through out the season points_against: int # total points against through out the season waiver_rank: int # waiver position acquisitions: int # number of acquisitions made by the team acquisition_budget_spent: int # budget spent on acquisitions drops: int # number of drops made by the team trades: int # number of trades made by the team move_to_ir: int # number of players move to ir owners: List[dict] # array of owner dict example: { id: '1234', displayName: 'team', firstName: 'Bob', lastName: 'Joe'} # Note for owners name attributes will only be available for private leagues. Public leagues will not show name data. stats: dict # holds teams season long stats streak_type: str # string of either WIN or LOSS streak_length: int # how long the streak is for streak type standing: int # standing before playoffs final_standing: int # final standing at end of season draft_projected_rank: int # projected rank after draft playoff_pct: int # teams projected chance to make playoffs logo_url: str roster: List[Player] # These 3 variables will have the same index and match on those indexes schedule: List[Team] scores: List[int] outcomes: List[str] ``` -------------------------------- ### free_agents Source: https://github.com/cwendt94/espn-api/wiki/League-Class-Basketball Returns a list of free agent players. Allows filtering by week, number of results, and position (e.g., 'PG', 'C'). ```APIDOC ## free_agents ### Description Returns a list of free agent players. Allows filtering by week, number of results, and position (e.g., 'PG', 'C'). ### Method ```python free_agents(week: int = None, size: int = 50, position: str = None, position_id: int=None) -> List[Player] ``` ``` -------------------------------- ### free_agents Source: https://github.com/cwendt94/espn-api/wiki/League-Class Returns a list of free agents. You can filter by week, size, position, and position ID. ```APIDOC ## free_agents ### Description Returns a list of free agents. ### Method ```python # position inputs: 'QB', 'RB', 'WR', 'TE', 'D/ST', 'K', 'FLEX' def free_agents(week: int = None, size: int = 50, position: str = None, position_id: int=None) -> List[BoxPlayer]: ``` ### Parameters #### Query Parameters - **week** (int) - Optional - The week number to retrieve free agents for. - **size** (int) - Optional - The number of free agents to return (default is 50). - **position** (str) - Optional - The position to filter free agents by (e.g., 'QB', 'RB'). - **position_id** (int) - Optional - The ID of the position to filter free agents by. ``` -------------------------------- ### Calculate Power Rankings Source: https://github.com/cwendt94/espn-api/wiki/League-Class Calculates week power rankings using a two-step dominance method. Returns a list of tuples, where each tuple contains a score and a Team object. ```python3 def power_rankings(week: int=None) -> List[Tuples(str, Team)]: ``` -------------------------------- ### power_rankings Source: https://github.com/cwendt94/espn-api/wiki/League-Class Calculates week power rankings using a two-step dominance method. Returns a list of tuples with the first element being the score and the second the Team object. ```APIDOC ## power_rankings ### Description Calculates week power rankings using two step dominance. Returns a list of tuples with first position being score and second the [Team Class](https://github.com/cwendt94/ff-espn-api/wiki/Team-Class). ### Method ```python def power_rankings(week: int=None) -> List[Tuples(str, Team)]: ``` ### Parameters #### Query Parameters - **week** (int) - Optional - The week number to calculate power rankings for. ```