Skip to main content

A free sports API written for python

Project description

https://github.com/roclark/sportsreference/workflows/Sportsreference%20push%20tests/badge.svg Documentation Status https://img.shields.io/pypi/v/sportsreference.svg

Sportsreference is a free python API that pulls the stats from www.sports-reference.com and allows them to be easily be used in python-based applications, especially ones involving data analytics and machine learning.

Sportsreference exposes a plethora of sports information from major sports leagues in North America, such as the MLB, NBA, College Football and Basketball, NFL, and NHL. Every sport has its own set of valid API queries ranging from the list of teams in a league, to the date and time of a game, to the total number of wins a team has secured during the season, and many, many more metrics that paint a more detailed picture of how a team has performed during a game or throughout a season.

Installation

The easiest way to install sportsreference is by downloading the latest released binary from PyPI using PIP. For instructions on installing PIP, visit PyPA.io for detailed steps on installing the package manager for your local environment.

Next, run:

pip install sportsreference

to download and install the latest official release of sportsreference on your machine. You now have the latest stable version of sportsreference installed and can begin using it following the examples below!

If the bleeding-edge version of sportsreference is desired, clone this repository using git and install all of the package requirements with PIP:

git clone https://github.com/roclark/sportsreference
cd sportsreference
pip install -r requirements.txt

Once complete, create a Python wheel for your default version of Python by running the following command:

python setup.py sdist bdist_wheel

This will create a .whl file in the dist directory which can be installed with the following command:

pip install dist/*.whl

Examples

The following are a few examples showcasing how easy it can be to collect an abundance of metrics and information from all of the tracked leagues. The examples below are only a miniscule subset of the total number of statistics that can be pulled using sportsreference. Visit the documentation on Read The Docs for a complete list of all information exposed by the API.

Get instances of all NHL teams for the 2018 season

from sportsreference.nhl.teams import Teams

teams = Teams(2018)

Get a specific NFL team’s season information

from sportsreference.nfl.teams import Teams

teams = Teams()
lions = teams('DET')

Get a Pandas DataFrame of all stats for a MLB game

from sportsreference.mlb.boxscore import Boxscore

game = Boxscore('BOS201806070')
df = game.dataframe

Documentation

Two blog posts detailing the creation and basic usage of sportsreference can be found on The Medium at the following links:

The second post in particular is a great guide for getting started with sportsreference and is highly recommended for anyone who is new to the package.

Complete documentation is hosted on readthedocs.org. Refer to the documentation for a full list of all metrics and information exposed by sportsreference. The documentation is auto-generated using Sphinx based on the docstrings in the sportsreference package.

Testing

Sportsreference contains a testing suite which aims to test all major portions of code for proper functionality. To run the test suite against your environment, ensure all of the requirements are installed by running:

pip install -r requirements.txt

Next, start the tests by running py.test while optionally including coverage flags which identify the amount of production code covered by the testing framework:

py.test --cov=sportsreference --cov-report term-missing tests/

If the tests were successful, it will return a green line will show a message at the end of the output similar to the following:

======================= 380 passed in 245.56 seconds =======================

If a test failed, it will show the number of failed and what went wrong within the test output. If that’s the case, ensure you have the latest version of code and are in a supported environment. Otherwise, create an issue on GitHub to attempt to get the issue resolved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sportsreference-sio-0.4.6.tar.gz (287.9 kB view details)

Uploaded Source

Built Distribution

sportsreference_sio-0.4.6-py3-none-any.whl (374.3 kB view details)

Uploaded Python 3

File details

Details for the file sportsreference-sio-0.4.6.tar.gz.

File metadata

  • Download URL: sportsreference-sio-0.4.6.tar.gz
  • Upload date:
  • Size: 287.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for sportsreference-sio-0.4.6.tar.gz
Algorithm Hash digest
SHA256 f511ef1e6131b9113ce3fcd83640e42467074b40841481d816770ead844463da
MD5 a88214823a354c24503c8d68a22665cc
BLAKE2b-256 3b1e0f3116e11f87b497715c494b02ec465c724cd200a3aaeea313e5ddaa4e9e

See more details on using hashes here.

File details

Details for the file sportsreference_sio-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: sportsreference_sio-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 374.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for sportsreference_sio-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1ca290f4b0e75895fb40e2a4b3f0ab0380838d22305f75994c47bfac2bce200d
MD5 56f305d7e3b691f798f014df9b41b49a
BLAKE2b-256 307242b10b34dab82e9bbd32cc2ca54fe7299fbc701c3e685cdd121e046fe014

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page