Skip to content
Christian Wendt edited this page Jul 31, 2022 · 20 revisions

Welcome to the espn-api wiki!

I am going to use this wiki as the main source for package documentation and a better explanation of package fields and functions.

If you can't find something or have a question please feel free to open a issue!

Getting Started

You will need your league id and year. For private leagues you will also need two more parameters; your swid and espn_s2. To find your swid and espn_s2 check out this discussion! I would suggest to still login with your credentials even if your league is public so that you will be able to use the recent activity feature.
This API currently supports Football and Basketball.

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

Check out Football or Basketball page to find out all the information you can get on your League!
You should only need to access the League Object to get all of the data you need.