### Install Dependencies with Poetry Source: https://github.com/swar/nba_api/blob/master/CONTRIBUTING.md Installs all project dependencies and creates an isolated virtual environment. This command should be run after cloning the repository. ```python # Create a isolated virtual environment inclusive of all dependencies poetry install # Once the environment has been created, activate the environment for development eval $(poetry env activate) ``` -------------------------------- ### Install nba_api Source: https://github.com/swar/nba_api/blob/master/README.md Use pip to install the package in your Python environment. ```bash pip install nba_api ``` -------------------------------- ### Complete PlayerDashPtShotDefend Test Data Example Source: https://github.com/swar/nba_api/blob/master/tests/integration/scenarios/data/README.md This example demonstrates a complete test data file for the PlayerDashPtShotDefend endpoint, including multiple test cases with different parameters and expected outcomes. ```python """ Test data for PlayerDashPtShotDefend endpoint. GitHub Issues: - User reports: "team_id requirement needs to be taken off" """ TEST_CASES = [ { "name": "Basic test - LeBron 2023-24 Lakers", "params": { "player_id": "2544", "team_id": 1610612747, "season": "2023-24" }, "expected_status": "success", }, { "name": "Team ID zero - all teams", "params": { "player_id": "2544", "team_id": 0, "season": "2023-24" }, "expected_status": "has_data", # Verified: returns 6 rows }, { "name": "Known broken - old season times out", "params": { "player_id": "2544", "team_id": 1610612747, "season": "2015-16" }, "expected_status": "error", # NBA API issue }, ] ``` -------------------------------- ### Install Pre-Commit Hooks Source: https://github.com/swar/nba_api/blob/master/CONTRIBUTING.md Installs git hooks managed by pre-commit. These hooks automatically run linters and formatters like Ruff before each commit. ```bash # Install the git hooks (only needed once per clone) pre-commit install ``` -------------------------------- ### Example Output of Play-by-Play Analysis Source: https://github.com/swar/nba_api/blob/master/docs/examples/PlayByPlay.ipynb This is an example of the output generated after processing play-by-play data, showing extracted action types and their corresponding event codes. ```text ------------------ Antetokounmpo BLOCK (1 BLK) Joseph BLOCK (1 BLK) Turner BLOCK (1 BLK) Young BLOCK (1 BLK) Turner BLOCK (2 BLK) Snell BLOCK (1 BLK) Lopez BLOCK (1 BLK) ------------------ ``` -------------------------------- ### GET /SeasonWeeks Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/scheduleleaguev2.md Retrieves the schedule of weeks for a specific NBA season, including start and end dates. ```APIDOC ## GET /SeasonWeeks ### Description Retrieves the list of weeks within an NBA season, including league ID, season year, week number, week name, and date ranges. ### Method GET ### Endpoint /SeasonWeeks ### Parameters #### Query Parameters - **LeagueID** (string) - Optional - The identifier for the league. - **Season** (string) - Optional - The season year. ``` -------------------------------- ### Get Score Board Date Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/live/endpoints/scoreboard.md Retrieves the score board date as a string. No specific setup is required beyond instantiating the ScoreBoard object. ```python scoreboard.ScoreBoard().score_board_date ``` -------------------------------- ### Start Period Enum Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/library/parameters.md Defines possible starting periods. ```APIDOC ## Enum: StartPeriod ### Description Represents the starting period for a game or event. ### Values - **All**: Represents all periods (value: 0). - **First**: Represents the first period (value: 1). - **Second**: Represents the second period (value: 2). - **Third**: Represents the third period (value: 3). - **Fourth**: Represents the fourth period (value: 4). - **Quarter**: Represents a quarter (function: `quarter()`). - **Overtime**: Represents overtime (function: `overtime()`). ``` -------------------------------- ### Initialize DataSet with Data Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints_data_structure.md Assigns data to the DataSet object. This is a foundational step for creating a DataSet instance. ```python data = data_set ``` ```python data_set = {'name': name, 'headers': headers, 'data': data} ``` -------------------------------- ### Reset and Reinstall Dependencies Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Use these commands to clean the local environment when version updates are not reflecting as expected. ```bash # Reset any local changes git reset --hard HEAD # Clean install dependencies poetry install --no-ansi # Use the manual commit analysis method instead git log --oneline --grep="feat\|fix\|BREAKING" $(git describe --tags --abbrev=0)..HEAD ``` -------------------------------- ### Get NBA Team IDs Source: https://github.com/swar/nba_api/blob/master/docs/examples/Finding Games.ipynb Fetches a list of all NBA teams and selects the Celtics by their abbreviation to get their team ID. ```python from nba_api.stats.static import teams nba_teams = teams.get_teams() # Select the dictionary for the Celtics, which contains their team ID celtics = [team for team in nba_teams if team["abbreviation"] == "BOS"][0] celtics_id = celtics["id"] ``` -------------------------------- ### Run Release Script Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Execute the provided script from the project root to prepare a release. It checks the branch, determines the next version, updates relevant files, and creates a local commit. ```bash # From project root ./scripts/gen-release.sh ``` -------------------------------- ### Requesting NBA Stats Endpoints Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/examples.md Demonstrates basic endpoint initialization and advanced configuration including custom headers, proxies, and timeouts. ```python from nba_api.stats.endpoints import commonplayerinfo # Basic Request player_info = commonplayerinfo.CommonPlayerInfo(player_id=2544) custom_headers = { 'Host': 'stats.nba.com', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.9', } # Only available after v1.1.0 # Proxy Support, Custom Headers Support, Timeout Support (in seconds) player_info = commonplayerinfo.CommonPlayerInfo(player_id=2544, proxy='127.0.0.1:80', headers=custom_headers, timeout=100) ``` -------------------------------- ### Get Last Game Played Source: https://github.com/swar/nba_api/blob/master/docs/examples/Finding Games.ipynb Orders the filtered games by GAME_DATE in descending order and selects the first row to get the most recent game played. ```python # Order by date and select the last row last_game = games_1718_vs_raptors.sort_values(by="GAME_DATE", ascending=False).iloc[0] last_game ``` -------------------------------- ### Initialize Regex Mapping Imports Source: https://github.com/swar/nba_api/blob/master/docs/examples/PlayByPlay.ipynb Imports necessary modules for mapping event action types using regular expressions. ```python # Mapping out all of the EventMsgActionTypes for EventMsgType 1 import operator import re ``` -------------------------------- ### Create Endpoint Test Data File Source: https://github.com/swar/nba_api/blob/master/tests/integration/scenarios/data/README.md Use the `touch` command to create a new Python file for an endpoint's test data, following the naming convention `{endpoint_name}.py`. ```bash # Create file for the endpoint touch tests/integration/scenarios/data/leaguegamelog.py ``` -------------------------------- ### Conventional Commits Type Examples Source: https://github.com/swar/nba_api/blob/master/CONTRIBUTING.md Examples of commit types used in Conventional Commits. Each type corresponds to a specific kind of change and influences version bumping. ```text feat: add new endpoint for player statistics fix: resolve timeout issue in HTTP requests docs: update API documentation for new endpoints ``` -------------------------------- ### Simulate Semantic Release on Master Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Advanced method to test the actual semantic-release logic by merging a branch into master locally, analyzing the release version, and then cleaning up. ```bash git checkout master git pull origin master git merge --no-ff your_branch_name --no-commit poetry run semantic-release version --print git reset --hard HEAD # Clean up git checkout your_branch_name ``` -------------------------------- ### GET LeagueDashPlayerBioStats Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/leaguedashplayerbiostats.md Retrieves player biographical and statistical data. ```APIDOC ## GET LeagueDashPlayerBioStats ### Description Retrieves a dashboard of player biographical and statistical information. ### Method GET ### Endpoint LeagueDashPlayerBioStats ### Parameters #### Query Parameters - **LeagueID** (string) - Required - The league identifier. - **PerMode** (string) - Required - The mode of statistics (Totals or PerGame). - **Season** (string) - Required - The season year. - **SeasonType** (string) - Required - The type of season (Regular Season, Pre Season, Playoffs, All Star). - **College** (string) - Optional - Filter by college. - **Conference** (string) - Optional - Filter by conference. - **Country** (string) - Optional - Filter by country. - **DateFrom** (string) - Optional - Start date filter. - **DateTo** (string) - Optional - End date filter. - **Division** (string) - Optional - Filter by division. - **DraftPick** (string) - Optional - Filter by draft pick. - **DraftYear** (string) - Optional - Filter by draft year. - **GameScope** (string) - Optional - Filter by game scope. - **GameSegment** (string) - Optional - Filter by game segment. - **Height** (string) - Optional - Filter by height. - **LastNGames** (string) - Optional - Filter by last N games. - **Location** (string) - Optional - Filter by location (Home/Road). - **Month** (string) - Optional - Filter by month. - **OpponentTeamID** (string) - Optional - Filter by opponent team ID. - **Outcome** (string) - Optional - Filter by game outcome (W/L). - **PORound** (string) - Optional - Filter by playoff round. - **Period** (string) - Optional - Filter by period. - **PlayerExperience** (string) - Optional - Filter by experience level. - **PlayerPosition** (string) - Optional - Filter by position. - **SeasonSegment** (string) - Optional - Filter by season segment. - **ShotClockRange** (string) - Optional - Filter by shot clock range. - **StarterBench** (string) - Optional - Filter by starter or bench status. - **TeamID** (string) - Optional - Filter by team ID. - **VsConference** (string) - Optional - Filter by opponent conference. - **VsDivision** (string) - Optional - Filter by opponent division. - **Weight** (string) - Optional - Filter by weight. ### Response #### Success Response (200) - **PLAYER_ID** (integer) - Unique player identifier - **PLAYER_NAME** (string) - Name of the player - **TEAM_ID** (integer) - Team identifier - **TEAM_ABBREVIATION** (string) - Team abbreviation - **AGE** (integer) - Player age - **PLAYER_HEIGHT** (string) - Height in feet and inches - **PLAYER_HEIGHT_INCHES** (integer) - Height in inches - **PLAYER_WEIGHT** (integer) - Weight in pounds - **COLLEGE** (string) - College attended - **COUNTRY** (string) - Country of origin - **DRAFT_YEAR** (string) - Year drafted - **DRAFT_ROUND** (string) - Round drafted - **DRAFT_NUMBER** (string) - Draft pick number - **GP** (integer) - Games played - **PTS** (float) - Points per game - **REB** (float) - Rebounds per game - **AST** (float) - Assists per game - **NET_RATING** (float) - Net rating - **OREB_PCT** (float) - Offensive rebound percentage - **DREB_PCT** (float) - Defensive rebound percentage - **USG_PCT** (float) - Usage percentage - **TS_PCT** (float) - True shooting percentage - **AST_PCT** (float) - Assist percentage ``` -------------------------------- ### Clone Fork and Create Branch Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Steps to clone your forked repository and create a new branch for testing. This follows the standard fork workflow. ```bash # 2. Clone YOUR fork locally git clone https://github.com/yourusername/nba_api.git cd nba_api # 3. Create test branch from your fork's master git checkout -b your_branch_name ``` -------------------------------- ### GET TeamVsPlayer Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/teamvsplayer.md Retrieves statistical data for a team against a specific player. ```APIDOC ## GET TeamVsPlayer ### Description Retrieves performance statistics for a team against a specific player, with support for various filters and modes. ### Method GET ### Endpoint TeamVsPlayer ### Parameters #### Query Parameters - **DateFrom** (string) - Optional - Start date for filtering. - **DateTo** (string) - Optional - End date for filtering. - **GameSegment** (string) - Optional - Filter by game segment (First Half, Second Half, Overtime). - **LastNGames** (integer) - Required - Number of recent games to include. - **LeagueID** (string) - Optional - League identifier. - **Location** (string) - Optional - Filter by location (Home, Road). - **MeasureType** (string) - Required - Type of statistics (Base, Advanced, Misc, Four Factors, Scoring, Opponent, Usage, Defense). - **Month** (integer) - Required - Month filter. - **OpponentTeamID** (integer) - Required - ID of the opponent team. - **Outcome** (string) - Optional - Filter by game outcome (W, L). - **PaceAdjust** (string) - Required - Whether to pace adjust (Y, N). - **PerMode** (string) - Required - Statistical mode (Totals, PerGame, Per48, etc.). - **Period** (integer) - Required - Specific game period. - **PlayerID** (integer) - Optional - ID of the player. - **PlusMinus** (string) - Required - Include plus-minus (Y, N). - **Rank** (string) - Required - Include rankings (Y, N). - **Season** (string) - Required - Season identifier. - **SeasonSegment** (string) - Optional - Filter by season segment (Pre All-Star, Post All-Star). - **SeasonType** (string) - Required - Type of season (Regular Season, Pre Season, Playoffs). - **TeamID** (integer) - Required - ID of the team. - **VsConference** (string) - Optional - Filter by conference (East, West). - **VsDivision** (string) - Optional - Filter by division. - **VsPlayerID** (integer) - Required - ID of the player being compared against. ``` -------------------------------- ### Execute Release Workflow Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Commands for testing release scripts, verifying version bumps, and cleaning up test commits. ```bash # 1. Use the release script (easiest) ./scripts/gen-release.sh # Follow the prompts to prepare release # 2. Or test manually: git commit -m "feat: add new testing feature" --allow-empty git commit -m "fix: resolve testing issue" --allow-empty # 3. Check what would be released poetry run semantic-release version --print # Should show: 1.11.0 (minor bump for feat) # 4. Test version bump without publishing poetry run semantic-release version --no-push --no-vcs-release --no-tag # Updates local files to show what would happen # 5. Reset changes and clean up git reset --hard HEAD~2 # Removes test commits # 6. For full workflow testing, use your fork: # Fork repo → push changes → observe complete automation ``` -------------------------------- ### GET /stats/teamdashptpass Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/teamdashptpass.md Retrieves passing statistics for a specific NBA team. ```APIDOC ## GET /stats/teamdashptpass ### Description Retrieves passing statistics for a specific NBA team based on various filters like season, date range, and game type. ### Method GET ### Endpoint https://stats.nba.com/stats/teamdashptpass ### Parameters #### Query Parameters - **DateFrom** (string) - Optional - Start date for filtering - **DateTo** (string) - Optional - End date for filtering - **LastNGames** (integer) - Optional - Number of last games to include - **LeagueID** (string) - Optional - League identifier - **Location** (string) - Optional - Home or Away - **Month** (integer) - Optional - Month filter - **OpponentTeamID** (integer) - Optional - Filter by opponent team - **Outcome** (string) - Optional - Win or Loss - **PerMode** (string) - Optional - Per mode (e.g., Totals) - **Season** (string) - Optional - Season year (e.g., 2019-20) - **SeasonSegment** (string) - Optional - Season segment - **SeasonType** (string) - Optional - Season type (e.g., Regular Season) - **TeamID** (integer) - Required - The ID of the team - **VsConference** (string) - Optional - Filter by conference - **VsDivision** (string) - Optional - Filter by division ``` -------------------------------- ### GET /stats/playerdashptreb Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/playerdashptreb.md Retrieves rebounding dashboard statistics for a specific player. ```APIDOC ## GET /stats/playerdashptreb ### Description Retrieves detailed rebounding statistics for a specific NBA player based on provided filters. ### Method GET ### Endpoint https://stats.nba.com/stats/playerdashptreb ### Parameters #### Query Parameters - **DateFrom** (string) - Optional - Start date for filtering - **DateTo** (string) - Optional - End date for filtering - **GameSegment** (string) - Optional - Filter by game segment - **LastNGames** (integer) - Optional - Number of last games to include - **LeagueID** (string) - Optional - League identifier - **Location** (string) - Optional - Home or Away - **Month** (integer) - Optional - Month filter - **OpponentTeamID** (integer) - Optional - Filter by opponent team - **Outcome** (string) - Optional - Win or Loss - **PerMode** (string) - Optional - Totals or PerGame - **Period** (integer) - Optional - Game period - **PlayerID** (integer) - Required - Unique identifier for the player - **Season** (string) - Optional - Season year (e.g., 2019-20) - **SeasonSegment** (string) - Optional - Season segment - **SeasonType** (string) - Optional - Regular Season or Playoffs - **TeamID** (integer) - Optional - Team identifier - **VsConference** (string) - Optional - Filter by conference - **VsDivision** (string) - Optional - Filter by division ``` -------------------------------- ### NBA API Parameters Documentation Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/videodetailsasset.md This section details the available parameters for the NBA API, including their names, nullability, and any associated regular expressions or constraints. ```APIDOC ## NBA API Parameters This document outlines the parameters available for querying the NBA API. ### Parameters - **Outcome** (string) - Nullable - Represents the outcome of a game, accepting 'W' (Win) or 'L' (Loss). Regex: `^((W)\|(L))?$` - **Location** (string) - Nullable - Represents the location of a game, accepting 'Home' or 'Road'. Regex: `^((Home)\|(Road))?$` - **LeagueID** (string) - Nullable - Represents the League ID. No specific format provided. - **GameSegment** (string) - Nullable - Represents a segment of the game. No specific format provided. ``` -------------------------------- ### GET /stats/playercareerbycollege Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/playercareerbycollege.md Retrieves career statistics for players from a specific college. ```APIDOC ## GET /stats/playercareerbycollege ### Description Retrieves career statistics for NBA players filtered by the college they attended. ### Method GET ### Endpoint https://stats.nba.com/stats/playercareerbycollege ### Parameters #### Query Parameters - **College** (string) - Required - The name of the college. - **LeagueID** (string) - Required - The league identifier. - **PerMode** (string) - Required - The mode for statistics (e.g., Totals). - **SeasonType** (string) - Required - The type of season (Regular Season, Pre Season, Playoffs, All Star). - **Season** (string) - Optional - The specific season (nullable). ### Response #### Success Response (200) - **PlayerCareerByCollege** (array) - List of player career statistics including PLAYER_ID, PLAYER_NAME, COLLEGE, GP, MIN, FGM, FGA, FG_PCT, FG3M, FG3A, FG3_PCT, FTM, FTA, FT_PCT, OREB, DREB, REB, AST, STL, BLK, TOV, PF, PTS. ``` -------------------------------- ### Make and Push Test Commits Source: https://github.com/swar/nba_api/blob/master/RELEASE_TESTING.md Create test commits using the conventional format and push the test branch to your fork. These commits are used to trigger the release automation. ```bash # 4. Make test commits using conventional format git commit -m "feat: add test automation feature" --allow-empty git commit -m "fix: resolve test issue" --allow-empty # 5. Push test branch to your fork git push origin your_branch_name ``` -------------------------------- ### GET /stats/leaguedashlineups Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/leaguedashlineups.md Retrieves lineup statistics from the NBA stats API. ```APIDOC ## GET /stats/leaguedashlineups ### Description Retrieves lineup performance statistics for the NBA. ### Method GET ### Endpoint https://stats.nba.com/stats/leaguedashlineups ### Query Parameters - **Conference** (string) - Optional - Filter by conference - **DateFrom** (string) - Optional - Start date for filtering - **DateTo** (string) - Optional - End date for filtering - **Division** (string) - Optional - Filter by division - **GameSegment** (string) - Optional - Filter by game segment - **GroupQuantity** (integer) - Optional - Number of players in the lineup (default 5) - **LastNGames** (integer) - Optional - Filter by last N games - **LeagueID** (string) - Optional - League identifier - **Location** (string) - Optional - Home or Away - **MeasureType** (string) - Optional - Type of measurement (e.g., Base) - **Month** (integer) - Optional - Filter by month - **OpponentTeamID** (integer) - Optional - Filter by opponent team ID - **Outcome** (string) - Optional - Filter by win/loss outcome - **PORound** (integer) - Optional - Playoff round - **PaceAdjust** (string) - Optional - Pace adjustment flag (Y/N) - **PerMode** (string) - Optional - Per mode (e.g., Totals) - **Period** (integer) - Optional - Filter by period - **PlusMinus** (string) - Optional - Plus/Minus flag (Y/N) - **Rank** (string) - Optional - Rank flag (Y/N) - **Season** (string) - Optional - Season (e.g., 2019-20) - **SeasonSegment** (string) - Optional - Season segment - **SeasonType** (string) - Optional - Season type (e.g., Regular Season) - **ShotClockRange** (string) - Optional - Shot clock range - **TeamID** (integer) - Optional - Filter by team ID - **VsConference** (string) - Optional - Filter by opponent conference - **VsDivision** (string) - Optional - Filter by opponent division ``` -------------------------------- ### generate_all_endpoint_documentation Source: https://github.com/swar/nba_api/blob/master/docs/nba_api/tools/stats/endpoint_documentation_generator/generator.md Batch generates documentation for all endpoints defined in the endpoint_list. ```APIDOC ## generate_all_endpoint_documentation ### Description Generates all documentation text based on the endpoints found in the endpoint_list. ### Parameters - **directory** (string) - Optional - The target directory for the generated documentation files (default: 'endpoint_documentation'). ```