Skip to content

danielwelch/xmlstats-py

Repository files navigation

xmlstats-py

Build Status

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.

Installing

pip install xmlstats-py

Tested against Python 2.7, 3.2-3.6

Usage

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 notation.

Methods

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
Events events
Roster roster
Standings standings
Teams teams
Team Schedule/Results team_results
NBA Box Score nba_box_score
NBA Draft nba_draft
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

Examples

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
]

About

Python module for interacting with the xmlstats API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages