Marketplace engineering-nba-data
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.
git clone https://github.com/aiskillstore/marketplace
T=$(mktemp -d) && git clone --depth=1 https://github.com/aiskillstore/marketplace "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/emz1998/engineering-nba-data" ~/.claude/skills/aiskillstore-marketplace-engineering-nba-data && rm -rf "$T"
skills/emz1998/engineering-nba-data/SKILL.mdGoal: 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.
Workflow
Phase 1: Setup and Installation
- Install nba_api:
if not yet installedpip install nba_api - Import required modules based on task:
for stats.nba.com datafrom nba_api.stats.endpoints import [endpoint_name]
for static lookupsfrom nba_api.stats.static import players, teams
for valid parameter valuesfrom nba_api.stats.library.parameters import [parameter_classes]
Phase 2: Data Retrieval
For Player/Team Lookups (No API Calls):
- Use
for player searchesplayers.find_players_by_full_name('player_name') - Use
for team searchesteams.find_teams_by_full_name('team_name') - Both return dictionaries with
,id
, and other metadatafull_name - No HTTP requests are sent; data is embedded in the package
For Stats Endpoints (API Calls):
- Identify the correct endpoint from table of contents
- Initialize endpoint with required parameters:
endpoint_class(param1=value1, param2=value2) - Access datasets using dot notation:
response_object.dataset_name - Retrieve data in desired format:
for JSON string.get_json()
for dictionary.get_dict()
for pandas DataFrame.get_data_frame()
Custom Request Configuration:
- Set custom headers:
endpoint_class(player_id=123, headers=custom_headers) - Set proxy:
endpoint_class(player_id=123, proxy='127.0.0.1:80') - Set timeout:
(in seconds)endpoint_class(player_id=123, timeout=100)
Phase 3: Data Processing
- Extract specific datasets from endpoint responses
- Transform data using pandas for aggregations, filtering, joins
- Normalize nested data structures as needed
- Handle multiple datasets returned by single endpoint
Phase 4: Output and Storage
- Export to CSV:
df.to_csv('output.csv', index=False) - Export to JSON: Use
or.get_json()df.to_json() - Store in database using pandas
method.to_sql() - Cache responses to minimize API calls
Rules
- Required packages:
must be installed before usenba_api - Static first: Always use static lookups (players/teams) for ID retrieval before making API calls
- Parameter validation: Reference parameters.md for valid parameter values
- Endpoint selection: Check table of contents to find the correct endpoint
- Rate limiting: Be mindful of API rate limits; cache data when possible
- Error handling: Wrap API calls in try-except blocks to handle network failures
- Data formats: Know when to use JSON, dict, or DataFrame based on downstream requirements
- Season format: Seasons use format
(e.g.,YYYY-YY
)2019-20 - League IDs: NBA=
, ABA=00
, WNBA=01
, G-League=1020
Acceptance Criteria
- Data retrieved successfully from appropriate endpoint or static source
- Correct parameters used based on documentation
- Data formatted appropriately for intended use case
- Error handling implemented for API failures
- Code follows Python best practices
- Results validated against expected structure
- Documentation references included where relevant
Reference Documentation
Quick access to common resources:
- Table of Contents - Full documentation index
- Examples - Usage examples for endpoints and static data
- Parameters - Valid parameter values and patterns
- Endpoints Data Structure - Response format and methods
- Players - Static player lookup functions
- Teams - Static team lookup functions
- HTTP Library - HTTP request details
Endpoint-specific documentation:
Refer to
docs/nba_api/stats/endpoints/[endpoint_name].md for detailed parameter and dataset information for each endpoint.