Package: py-ball
py_ballPython API wrapper for stats.nba.com with a focus on NBA and WNBA applicationsIntroductionThe motivation for this stems fromnba_pybyseemethereandnbastatsRbyabresler. The work towards a Python API wrapper innba_pyis a great start, but the documentation of thestats.nba.comAPI is lacking.nbastatsRis an extremely valuable resource for the R community, and this work hopes to extend the breadth and depth of that package. In my research, I have also come across the recent effort ofnba_apibyswar. This looks similar tonba_pyand I am hoping to collaborate.GoalsIf successful,py_ballshould accomplish the following:By working with the community, improve the quality of documentation forstats.nba.com.Further enable the dissemination of basketball statistics to increase the understanding of the sport and encourage the practice of basketball analytics.Produce introductory analyses leveraging NBA and WNBA data to reduce the barrier of entry to basketball analytics through demonstration.Focus on the WNBA in an effort to stress inclusivity and contribute to women's basketball analytics.DocumentationWhilenba_apiimproves greatly upon the documentation of thestats.nba.comAPI innba_py,py_ballstrives to take documentation further through the following:Fully documented code, including function, class, and script docstrings.Extend endpoint and parameter documentation to include feature definitions.Current DocumentationClasses:The functionality of the classes within the package are documented in both the docstrings andthis site. The endpoints, parameters, and tables are documented in the Wiki (linked below):BoxScoreDraftImageLeaderBoardLeagueLeagueDashLeagueHustlePlayByPlayPlayerSalaries(usingHoopshype)ScoreBoardShotsTeamWinProbabilityDevelopmentInitially mapstats.nba.comAPI and fully document code.Refactor code to generate a more consistent structure across classes.Document endpoints and parameters with definitions.(See Wikihere)Research other basketball-related APIs to map.Write unit tests for the package.Begin introductory basketball analytics analyses.Franchise History(here!)Draft Combine Player Sheet(here!)Live NBA/WNBA scoreboard(here!)Shot Probability Model(here!)Location Data Exploration(here!)Assist Networks(here!)Win Probability Model(here!)InstallationThe package is built for Python 3 and leverages the packages in therequirements.txtfile.py_ballcan be installed via pip (more infohere):pip install py_ballUsageThestats.nba.comAPI requires a request header for all API calls. A good discussion on this, including steps to obtain a proper request header, can be foundhere. With a request header inHEADER, the example below demonstrates usage of the package to pull franchise history for the WNBA:from py_ball import league, image

league_id = '10' #WNBA
franchises = league.League(headers=HEADERS,
                           endpoint='franchisehistory',
                           league_id=league_id)Each class, with the exception of theHeadshotandLogoclasses, has adataattribute. This is a dictionary containing table names as keys and a list of dictionaries of table data as values. TheHeadshotandLogoclasses have animageattribute that is a PNG object.ContactFollow along for updates or reach out on Twitter@py_ball_!