Skip to main content

Module path

Data.fetch_games

fetch_games_teamwins()

Fetches Regular Season team-level game logs from the NBA API and stores them in the local SQLite database. Each game produces two rows — one for each team.

Signature

def fetch_games_teamwins(season="2025-2026"):

Parameters

season
string
default:"2025-2026"
NBA season string passed to nba_api. The source default is "2025-2026" (full-year format). The abbreviated form (e.g., "2025-26") is also accepted by nba_api.
Returns: None Side effects:
  • Creates the games table in Data/nba_stats.db if it does not already exist.
  • Inserts or replaces rows for every team-game in the specified season.
  • Prints progress and a row count to stdout.
Data source: nba_api.stats.endpoints.leaguegamelog, Regular Season, team ("T") level.

Usage example

from Data.fetch_games import fetch_games_teamwins

# Fetch the current season (default)
fetch_games_teamwins()

# Fetch a specific past season
fetch_games_teamwins(season="2024-2025")

games table columns

The function creates or updates the games table with the following columns:
ColumnTypeDescription
game_idTEXTUnique NBA game identifier. Part of primary key.
game_dateTEXTDate of the game as returned by the NBA API.
team_idINTEGERNBA team identifier. Part of primary key.
teamTEXTTeam abbreviation (e.g., "LAL").
opponentTEXTOpponent team abbreviation (e.g., "BOS").
team_pointsINTEGERPoints scored by the team.
opponent_pointsINTEGERPoints scored by the opponent.
team_rebINTEGERTotal rebounds for the team.
opponent_rebINTEGERTotal rebounds for the opponent.
team_astINTEGERTotal assists for the team.
opponent_astINTEGERTotal assists for the opponent.
homeINTEGER1 if the team played at home, 0 if away.
winINTEGER1 if the team won, 0 if the team lost.
Primary key: (game_id, team_id)
The home indicator is derived from the MATCHUP field: "vs." in the matchup string means home; "@" means away.

Build docs developers (and LLMs) love