Extracts, transforms, and analyzes NBA statistics using the nba_api Python library. Use when working with NBA player stats, team data, game logs, shot charts, league statistics, or any NBA-related data engineering tasks. Supports both stats.nba.com endpoints and static player/team lookups.
Goal: Extract and process NBA statistical data efficiently using the nba_api library for data analysis, reporting, and application development.
IMPORTANT: The nba_api library accesses stats.nba.com endpoints. All data requests return structured datasets that can be output as JSON, dictionaries, or pandas DataFrames.
pip install nba_api if not yet installedfrom nba_api.stats.endpoints import [endpoint_name] for stats.nba.com datafrom nba_api.stats.static import players, teams for static lookupsfrom nba_api.stats.library.parameters import [parameter_classes] for valid parameter valuesFor Player/Team Lookups (No API Calls):
players.find_players_by_full_name('player_name') for player searchesteams.find_teams_by_full_name('team_name') for team searchesid, full_name, and other metadataFor Stats Endpoints (API Calls):
endpoint_class(param1=value1, param2=value2)response_object.dataset_name.get_json() for JSON string.get_dict() for dictionary.get_data_frame() for pandas DataFrameCustom Request Configuration:
endpoint_class(player_id=123, headers=custom_headers)endpoint_class(player_id=123, proxy='127.0.0.1:80')endpoint_class(player_id=123, timeout=100) (in seconds)df.to_csv('output.csv', index=False).get_json() or df.to_json().to_sql() methodnba_api must be installed before useYYYY-YY (e.g., 2019-20)00, ABA=01, WNBA=10, G-League=20Quick access to common resources:
Endpoint-specific documentation:
Refer to docs/nba_api/stats/endpoints/[endpoint_name].md for detailed parameter and dataset information for each endpoint.