Skip to content

Basketball Intro

Christian Wendt edited this page Feb 11, 2021 · 4 revisions

Intro to the Fantasy Basketball Interface

Basic Usage

Below are examples of some of the features espn_api has to offer! For more in depth details about each class check out the API links on the right!

View teams information

>>> 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'

Player Information

>>> 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'

View Free Agents

You can add filters like: size: 10
position: 'PG', 'SG', 'SF', 'PF', 'C', 'G', 'SG/SF', ...

>>> 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), ...]

Get box score for specific matchup or scoring period

See League Interface for more information.

>>> 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 scoreboard of current/specific week

>>> 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)