Currently Empty: $0.00
Football Analytics
Win a Fantasy Football Championship with Free Analytics Data
How to Easily Access Fantasy Football Data for Analytics Projects
Fantasy football has grown into a data-driven competition, with millions of players worldwide relying on analytics to gain an edge over their opponents. In this guide, we’ll show you how to retrieve fantasy football data using R and Python packages like ffverse to build your own models, create projections, and dominate your fantasy league. We’ll also explain how to connect to private leagues using tokens like SWID and ESPN_S2 for ESPN leagues.
Step 1: How to Connect to Private ESPN Leagues
To connect to a private ESPN league, you need two specific tokens: SWID and ESPN_S2. Here’s how you can find these tokens:
Finding ESPN SWID and ESPN_S2 Tokens
- Log in to ESPN: Open a browser and log in to your ESPN Fantasy account.
- Inspect the Website: Right-click anywhere on the page and select Inspect or press
Ctrl+Shift+I
(Windows) orCmd+Option+I
(Mac) to open the browser’s developer tools. - Find the Cookies: Go to the Application tab in the developer tools. On the left side, expand Cookies under the Storage section. Look for
SWID
andESPN_S2
under thehttps://www.espn.com
domain. - Copy the Values: The
SWID
value will look something like{8A2E7F7D-1E53-4A21-A4CD-EF37CE5AECB1}
. TheESPN_S2
value will be a long string of characters. - Save These Tokens: You will need these tokens to connect to your ESPN league.
Example: Connecting to ESPN Private League with ffscrapr
library(ffscrapr)
library(tidyverse)
library(ffsimulator)
library(ggridges)
# Connect to ESPN private league
league_connection <- ffscrapr::espn_connect(
season = 2024,
league_id = 1044897, # Replace with your league ID
espn_s2 = "YOUR_ESPN_S2", # Replace with your ESPN_S2 token
swid = "YOUR_SWID" # Replace with your SWID token
)
# Run simulations of the league schedule
league_sim <- ff_simulate(conn = league_connection, n_seasons = 5000)
# Plot the simulation results
plot(league_sim)
Step 2: How to Connect to Private Sleeper Leagues
For Sleeper leagues, the connection process is simpler since you only need the League ID.
Finding Your Sleeper League ID
- Log in to Sleeper: Open a browser and log in to your Sleeper account.
- Go to Your League: Navigate to your fantasy football league.
- Locate the League ID: Look at the URL of your league’s homepage. It will look something like
https://sleeper.app/leagues/71234567890
. The number at the end is your League ID.
Example: Connecting to Sleeper League with ffscrapr
library(ffscrapr)
# Connect to Sleeper league
sleeper_connection <- sleeper_connect(
season = 2024,
league_id = 71234567890 # Replace with your Sleeper League ID
)
# Get league standings
league_standings <- sleeper_standings(conn = sleeper_connection)
print(league_standings)
Step 3: How to Connect to Private MyFantasyLeague (MFL) Leagues
To connect to private MFL leagues, you’ll need your League ID and sometimes your MFL login token.
Finding Your MFL League ID
- Log in to MFL: Open a browser and log in to your MyFantasyLeague account.
- Locate the League ID: Navigate to your league’s homepage. The League ID is usually a 5- to 6-digit number found in the URL, such as
https://www57.myfantasyleague.com/2023/home/12345
. The League ID in this case is12345
.
Finding Your MFL Login Token
In some cases, you may need an MFL login token to access private league data. This token can be found by inspecting your browser’s cookies. Look for a cookie named MFL_USER_ID
under the myfantasyleague.com
domain.
Example: Connecting to MFL Private League with ffscrapr
library(ffscrapr)
# Connect to MFL private league
mfl_connection <- mfl_connect(
season = 2024,
league_id = 12345, # Replace with your MFL League ID
user_token = "MFL_USER_ID" # Optional: Replace with your MFL login token
)
# Get MFL league data
league_data <- mfl_league(mfl_connection)
print(league_data)
Step 4: Projecting Fantasy Football Stats with ffanalytics
The ffanalytics package, part of the ffverse ecosystem, allows you to create detailed player projections using multiple data sources.
- ffanalytics: ffanalytics aggregates fantasy football projections from various experts and combines them into a single consensus projection for each player. You can use this to forecast weekly or seasonal performance for every player on your roster. You can find the full documentation here.
Example: Projecting Weekly Player Stats with ffanalytics
library(ffanalytics)
# Create a data frame of projected stats for the 2023 season
projections <- ffanalytics::run_projections(
seasons = 2023,
sources = c("ESPN", "FantasyPros", "NFL")
)
head(projections)
Example: Customizing Fantasy Football Projections
# Modify weightings for different projection sources
custom_projections <- ffanalytics::run_projections(
seasons = 2023,
sources = c("ESPN", "FantasyPros"),
weights = c(0.6, 0.4)
)
head(custom_projections)
Step 5: Simulating League Outcomes with ffsimulator
The ffsimulator package lets you run advanced simulations of fantasy football leagues, projecting the probability of different outcomes.
Example: Running League Simulations
library(ffsimulator)
# Simulate 5000 seasons for a connected league
simulation_results <- ff_simulate(conn = league_connection, n_seasons = 5000)
# Plot the simulation results
plot(simulation_results)
Step 6: Analyze Fantasy Football Draft Data with ffpros
The ffpros package allows you to retrieve ADP (Average Draft Position) and rankings from FantasyPros, making it easy to understand expert consensus and draft trends.
Example: Retrieving ADP Data with ffpros
library(ffpros)
# Get FantasyPros ADP data for 2023 season
adp_data <- ffpros_adp()
head(adp_data)
Step 7: Explore Public Fantasy Football Data Sources
In addition to using R packages, several public sources offer valuable fantasy football data:
- FantasyPros: Provides expert rankings, projections, and ADP data for multiple fantasy football platforms.
- Sleeper: One of the most popular fantasy football platforms, providing league settings, player stats, and projections.
- MyFantasyLeague: MFL offers detailed league settings, player stats, ADP, and historical data.
- ESPN Fantasy: Offers player stats, projections, and league data for ESPN fantasy football leagues.
- NFL Fantasy: Provides player projections, rankings, and stats for NFL-managed leagues.
Step 8: Apply Your Data Skills to Fantasy Football Analytics Projects
Now that you know how to connect to your private fantasy football leagues and retrieve data, it’s time to apply your skills to real-world analytics projects. Whether you’re analyzing player projections, simulating league schedules, or building a draft strategy, tools like ffverse will help you gain a competitive edge.
To take your skills further, explore our Football Analytics Courses, where you’ll learn how to build custom models, use data scraping techniques, and apply statistical analysis to dominate your fantasy league.
Final Thoughts
Fantasy football analytics is a rapidly growing field, and with access to data from platforms like Sleeper, MFL, and ESPN, you’re ready to dive into impactful projects. Whether you use R, Python, or public sources like FantasyPros and NFL.com, gathering the right data is essential to winning your league.
Ready to master fantasy football analytics? Enroll in our Football Analytics Certifications today and start building data-driven models that will impress your league mates and help you win more games.
Call to Action
Start mastering fantasy football analytics by enrolling in our Football Analytics Courses.