README
¶
cfbd-go is a lightweight Go client for the collegefootballdata.com API suite
Table of Contents
- Installation
- Quick Start
- Authentication
- API Methods
- Error Handling
- Context Support
- Patreon Subscriptions
- Examples
- License
- Contributing
Installation
go get github.com/clintrovert/cfbd-go
Quick Start
package main
import (
"context"
"fmt"
"os"
"github.com/clintrovert/cfbd-go/cfbd"
)
func main() {
// Initialize the client with your API key
client, err := cfbd.New(os.Getenv("CFBD_API_KEY"))
if err != nil {
panic(err)
}
ctx := context.Background()
// Get games for a specific year
games, err := client.GetGames(ctx, cfbd.GetGamesRequest{
Year: 2024,
Week: 1,
})
if err != nil {
panic(err)
}
for _, game := range games {
fmt.Printf("%s vs %s\n", game.AwayTeam, game.HomeTeam)
}
}
Authentication
The CFBD API requires an API key for authentication. You can obtain an API key by:
- Signing up at collegefootballdata.com
- Getting a free API key or subscribing to Patreon for additional features
The API key is passed as a Bearer token in the Authorization header. Some endpoints require a Patreon subscription.
API Methods
Games
GetGames
Retrieve game information with filtering options.
games, err := client.GetGames(ctx, cfbd.GetGamesRequest{
Year: 2024,
Week: 1,
Team: "Texas",
Conference: "Big 12",
SeasonType: "regular",
})
GetGameTeams
Get team box score statistics for games.
teamStats, err := client.GetGameTeams(ctx, cfbd.GetGameTeamsRequest{
Year: 2024,
Week: 1,
})
GetGamePlayers
Retrieve player box score statistics for games.
playerStats, err := client.GetGamePlayers(ctx, cfbd.GetGamePlayersRequest{
Year: 2024,
Week: 1,
Team: "Alabama",
})
GetGameMedia
Get media information for games.
media, err := client.GetGameMedia(ctx, cfbd.GetGameMediaRequest{
Year: 2024,
Week: 1,
})
GetGameWeather
Get weather information for games (Patreon required).
weather, err := client.GetGameWeather(ctx, cfbd.GetGameWeatherRequest{
Year: 2024,
Week: 1,
})
GetAdvancedBoxScore
Get advanced box score statistics for a specific game.
boxScore, err := client.GetAdvancedBoxScore(ctx, cfbd.GetAdvancedBoxScoreRequest{
GameID: 401752677,
})
GetCalendar
Retrieve calendar weeks for a year.
weeks, err := client.GetCalendar(ctx, cfbd.GetCalendarRequest{
Year: 2024,
})
GetScoreboard
Get live scoreboard data.
scoreboard, err := client.GetScoreboard(ctx, cfbd.GetScoreboardRequest{
Conference: "SEC",
})
Teams
GetTeams
Retrieve team information.
teams, err := client.GetTeams(ctx, cfbd.GetTeamsRequest{
Conference: "SEC",
Year: 2024,
})
GetFBSTeams
Get FBS (Football Bowl Subdivision) teams.
fbsTeams, err := client.GetFBSTeams(ctx, cfbd.GetFBSTeamsRequest{
Year: 2024,
})
GetTeamRecords
Get team records.
records, err := client.GetTeamRecords(ctx, cfbd.GetTeamRecordsRequest{
Team: "Texas",
Year: 2024,
})
GetTeamMatchup
Get historical matchup data between two teams.
matchup, err := client.GetTeamMatchup(ctx, cfbd.GetTeamMatchupRequest{
Team1: "Texas",
Team2: "Oklahoma",
MinYear: 2020,
MaxYear: 2024,
})
GetTeamATS
Get team against-the-spread records.
ats, err := client.GetTeamATS(ctx, cfbd.GetTeamATSRequest{
Year: 2024,
Conference: "SEC",
})
GetRoster
Get team roster information.
roster, err := client.GetRoster(ctx, cfbd.GetRosterRequest{
Team: "Alabama",
Year: 2024,
})
GetTeamTalentComposite
Get 247 team talent composite ratings.
talent, err := client.GetTeamTalentComposite(ctx, cfbd.GetTalentCompositeRequest{
Year: 2024,
})
Players
SearchPlayers
Search for players by name or other criteria.
players, err := client.SearchPlayers(ctx, cfbd.SearchPlayersRequest{
SearchTerm: "Smith",
Year: 2024,
Team: "Alabama",
})
GetPlayerUsage
Get player usage statistics.
usage, err := client.GetPlayerUsage(ctx, cfbd.GetPlayerUsageRequest{
Year: 2024,
Team: "Texas",
Position: "QB",
})
GetReturningProduction
Get returning production statistics for players.
production, err := client.GetReturningProduction(ctx, cfbd.GetReturningProductionRequest{
Year: 2024,
Team: "Alabama",
})
GetTransferPortalPlayers
Get transfer portal player information.
transfers, err := client.GetTransferPortalPlayers(ctx, cfbd.GetTransferPortalPlayersRequest{
Year: 2024,
})
Plays and Drives
GetPlays
Get play-by-play data for games.
plays, err := client.GetPlays(ctx, cfbd.GetPlaysRequest{
Year: 2024,
Week: 1,
Team: "Texas",
})
GetPlayTypes
Get all available play types.
playTypes, err := client.GetPlayTypes(ctx)
GetPlayStats
Get play statistics.
stats, err := client.GetPlayStats(ctx, cfbd.GetPlayStatsRequest{
Year: 2024,
Week: 1,
GameID: 401767768,
})
GetPlayStatTypes
Get all available play statistic types.
statTypes, err := client.GetPlayStatTypes(ctx)
GetLivePlays
Get live play-by-play data for a game (requires live game ID).
liveGame, err := client.GetLivePlays(ctx, cfbd.GetLivePlaysRequest{
GameID: 401778330,
})
GetDrives
Get drive information for games.
drives, err := client.GetDrives(ctx, cfbd.GetDrivesRequest{
Year: 2024,
Week: 1,
Team: "Alabama",
})
Statistics
GetPlayerSeasonStats
Get player season statistics.
stats, err := client.GetPlayerSeasonStats(ctx, cfbd.GetPlayerSeasonStatsRequest{
Year: 2024,
Team: "Texas",
Category: "passing",
})
GetTeamSeasonStats
Get team season statistics.
stats, err := client.GetTeamSeasonStats(ctx, cfbd.GetTeamSeasonStatsRequest{
Year: 2024,
Team: "Alabama",
})
GetAdvancedSeasonStats
Get advanced season statistics.
stats, err := client.GetAdvancedSeasonStats(ctx, cfbd.GetAdvancedSeasonStatsRequest{
Year: 2024,
Team: "Texas",
ExcludeGarbageTime: &excludeGarbage,
})
GetAdvancedGameStats
Get advanced game statistics.
stats, err := client.GetAdvancedGameStats(ctx, cfbd.GetAdvancedGameStatsRequest{
Year: 2024,
Week: 1,
Team: "Alabama",
})
GetHavocGameStats
Get havoc game statistics.
stats, err := client.GetHavocGameStats(ctx, cfbd.GetHavocGameStatsRequest{
Year: 2024,
Week: 1,
Team: "Texas",
})
GetStatCategories
Get all available statistics categories.
categories, err := client.GetStatCategories(ctx)
Ratings
GetTeamSPPlusRatings
Get SP+ (S&P+) ratings for teams.
ratings, err := client.GetTeamSPPlusRatings(ctx, cfbd.GetSPPlusRatingsRequest{
Year: 2024,
Team: "Alabama",
})
GetConferenceSPPlusRatings
Get SP+ ratings for conferences.
ratings, err := client.GetConferenceSPPlusRatings(ctx, cfbd.GetConferenceSPPlusRatingsRequest{
Year: 2024,
Conference: "SEC",
})
GetSRSRatings
Get SRS (Simple Rating System) ratings.
ratings, err := client.GetSRSRatings(ctx, cfbd.GetSRSRatingsRequest{
Year: 2024,
Team: "Texas",
})
GetEloRatings
Get Elo ratings for teams.
ratings, err := client.GetEloRatings(ctx, cfbd.GetEloRatingsRequest{
Year: 2024,
Week: 1,
Team: "Alabama",
})
GetFPIRatings
Get FPI (Football Power Index) ratings.
ratings, err := client.GetFPIRatings(ctx, cfbd.GetFPIRatingsRequest{
Year: 2024,
Team: "Texas",
})
Rankings
GetRankings
Get college football rankings (polls).
rankings, err := client.GetRankings(ctx, cfbd.GetRankingsRequest{
Year: 2024,
Week: 1,
SeasonType: "regular",
})
Betting
GetBettingLines
Get betting lines for games.
lines, err := client.GetBettingLines(ctx, cfbd.GetBettingLinesRequest{
Year: 2024,
Week: 1,
Provider: "fanduel",
})
Recruiting
GetPlayerRecruitingRankings
Get player recruiting rankings.
recruits, err := client.GetPlayerRecruitingRankings(ctx, cfbd.GetPlayersRecruitingRankingsRequest{
Year: 2024,
Team: "Alabama",
Position: "QB",
})
GetTeamRecruitingRankings
Get team recruiting rankings.
rankings, err := client.GetTeamRecruitingRankings(ctx, cfbd.GetTeamRecruitingRankingsRequest{
Year: 2024,
Team: "Texas",
})
GetTeamPositionGroupRecruitingRankings
Get aggregated team recruiting information by position group.
groups, err := client.GetTeamPositionGroupRecruitingRankings(ctx, cfbd.GetTeamPositionGroupRecruitingRankingsRequest{
Team: "Alabama",
StartYear: 2020,
EndYear: 2024,
})
Metrics
GetPredictedPoints
Get predicted points values by down and distance.
points, err := client.GetPredictedPoints(ctx, cfbd.GetPredictedPointsRequest{
Down: 2,
Distance: 10,
})
GetTeamsPPA
Get team season PPA (Predicted Points Added) statistics.
ppa, err := client.GetTeamsPPA(ctx, cfbd.GetTeamsPPARequest{
Year: 2024,
Team: "Texas",
})
GetGamesPPA
Get team game PPA statistics.
ppa, err := client.GetGamesPPA(ctx, cfbd.GetPpaGamesRequest{
Year: 2024,
Week: 1,
Team: "Alabama",
})
GetPlayersPPA
Get player game PPA statistics.
ppa, err := client.GetPlayersPPA(ctx, cfbd.GetPlayerPpaGamesRequest{
Year: 2024,
Week: 1,
Team: "Texas",
Position: "QB",
})
GetPlayerSeasonPPA
Get player season PPA statistics.
ppa, err := client.GetPlayerSeasonPPA(ctx, cfbd.GetPlayerSeasonPPARequest{
Year: 2024,
Team: "Alabama",
Position: "RB",
})
GetWinProbability
Get win probability data for each play in a game.
probabilities, err := client.GetWinProbability(ctx, cfbd.GetWinProbabilityRequest{
GameID: 401778330,
})
GetPregameWinProbability
Get pregame win probability data.
probabilities, err := client.GetPregameWinProbability(ctx, cfbd.GetPregameWpRequest{
Year: 2024,
Week: 1,
Team: "Texas",
})
GetFieldGoalExpectedPoints
Get field goal expected points values.
ep, err := client.GetFieldGoalExpectedPoints(ctx)
Adjusted Metrics (Patreon Required)
GetTeamSeasonWEPA
Get team season WEPA (Weighted Expected Points Added) metrics.
wepa, err := client.GetTeamSeasonWEPA(ctx, cfbd.GetTeamSeasonWEPARequest{
Year: 2024,
Team: "Alabama",
})
GetPlayerPassingWEPA
Get player passing WEPA metrics.
wepa, err := client.GetPlayerPassingWEPA(ctx, cfbd.GetPlayerWEPARequest{
Year: 2024,
Team: "Texas",
Position: "QB",
})
GetPlayerRushingWEPA
Get player rushing WEPA metrics.
wepa, err := client.GetPlayerRushingWEPA(ctx, cfbd.GetPlayerWEPARequest{
Year: 2024,
Team: "Alabama",
Position: "RB",
})
GetPlayerKickingWEPA
Get kicker PAAR (Points Above Average Replacement) metrics.
paar, err := client.GetPlayerKickingWEPA(ctx, cfbd.GetWepaPlayersKickingRequest{
Year: 2024,
Team: "Texas",
})
Draft
GetDraftTeams
Get all NFL draft teams.
teams, err := client.GetDraftTeams(ctx)
GetDraftPositions
Get all NFL draft positions.
positions, err := client.GetDraftPositions(ctx)
GetDraftPicks
Get NFL draft picks.
picks, err := client.GetDraftPicks(ctx, cfbd.GetDraftPicksRequest{
Year: 2024,
Team: "Dallas Cowboys",
School: "Alabama",
})
Reference Data
GetConferences
Get all available conferences.
conferences, err := client.GetConferences(ctx)
GetVenues
Get all available venues.
venues, err := client.GetVenues(ctx)
GetCoaches
Get coach information.
coaches, err := client.GetCoaches(ctx, cfbd.GetCoachesRequest{
Team: "Alabama",
Year: 2024,
})
User Information
GetInfo
Get information about the authenticated user's API key.
info, err := client.GetInfo(ctx)
if info != nil {
fmt.Printf("User: %s\n", info.Email)
}
Error Handling
The client returns errors for various conditions:
ErrMissingAPIKey: Returned when the API key is emptyErrMissingRequiredParams: Returned when required parameters are missing- Network and API errors are wrapped with context
client, err := cfbd.New("")
if err == cfbd.ErrMissingAPIKey {
// Handle missing API key
}
games, err := client.GetGames(ctx, cfbd.GetGamesRequest{})
if err != nil {
// Handle API error
}
Context Support
All methods accept a context.Context for cancellation and timeouts:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
games, err := client.GetGames(ctx, cfbd.GetGamesRequest{Year: 2024})
Patreon Subscriptions
Some endpoints require a Patreon subscription:
- Weather data (
GetGameWeather) - Adjusted metrics (WEPA endpoints)
- Some advanced statistics
Check the CFBD API documentation for the latest list of Patreon-only features.
Examples
See the examples directory for comprehensive usage examples covering all API endpoints.
License
See LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Branch Naming and Versioning
This project uses semantic versioning (semver) with automated version calculation based on branch names. When creating a pull request, prefix your branch name with one of the following to indicate the type of change:
-
major/- For breaking changes that require a major version bump- Example:
major/breaking-api-changes - Result:
v2.0.0(if previous wasv1.x.x)
- Example:
-
minor/- For new features that are backward compatible- Example:
minor/add-new-endpoint - Result:
v1.2.0(if previous wasv1.1.x)
- Example:
-
patch/- For bug fixes and other backward-compatible changes- Example:
patch/fix-bug - Result:
v1.1.1(if previous wasv1.1.0)
- Example:
Note: If no prefix is provided, the default is a patch version bump.
Workflow
- Create a branch with the appropriate prefix (
major/,minor/, orpatch/) - Make your changes
- Ensure tests pass (
go test ./...) - Submit a pull request
- The CI workflow will:
- Run all tests
- Calculate and comment the suggested next release version on your PR
- When your PR is merged, a new release will be automatically created with the calculated version
For more details, see the GitHub workflows for test and release automation.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cfbd provides a minimal, type-safe Golang client for the College Football Data API.
|
Package cfbd provides a minimal, type-safe Golang client for the College Football Data API. |
|
internal/httpget
Package httpget provides an HTTP client wrapper for dependency injection and testing.
|
Package httpget provides an HTTP client wrapper for dependency injection and testing. |