A python module for interacting with the xmlstats API
This module aims to closely mirror the methods provided by the xmlstats API in terms of parameters and output structure.
pip install xmlstats-py
Tested against Python 2.7, 3.2-3.6
Instantiate an XmlStats object using a valid access token and user agent, obtained from the xmlstats API.
stats = Xmlstats(access_token=MY_ACCESS_TOKEN, user_agent=MY_USER_AGENT)
This object exposes a number of methods (one for each API endpoint) that
return a NamedTuple representation of the data provided by the API. The
JSON response is processed with
json.loads, and a custom
object_hook is used to convert JSON objects into NamedTuples when
they are encountered. This means fields can be accessed using dot
Each method exposed by the Xmlstats class aims to mirror an the endpoint provided by the API. See the API documentation for a complete explanation of parameters and results.
|API Endpoint||Class Method|
|NBA Box Score||nba_box_score|
|NBA Daily Leaders||nba_daily_leaders|
|NBA Team Stats||nba_team_stats|
|MLB Box Score||mlb_box_score|
|MLB Wild Card Standings||mlb_wild_card_standings|
Get Boxscores for a given date - yyyymmdd
stats = Xmlstats(access_token=MY_ACCESS_TOKEN, user_agent=MY_USER_AGENT) events = stats.events(date="20141028", sport="nba") # returns NamedTuple "Events" which mirrors data structure explained in API documentation, containing all NBA events on given date event_ids = [event.event_id for event in events.event] boxscores = [ stats.nba_box_score(eid) for eid in event_ids ]