Skip to main content

NHL Scrapr API for Python

Project description

Purpose

Provide a Python API for accessing NHL game data including play by play, game summaries, player stats et c. The library hides the guts of the NHL website scraping process and encapsulates not only the data gathering, but data output. This project is inspired by the R package nhlscrapr, an all around must for NHL analytics geeks and R power users.

nhlscrapi is in the early/initial stages, but will be updated regularly. Currently, the package support most of the game summary reports, but all of the important and essential ones.

Related projects:

Installation

Getting started is as easy as:

pip install nhlscrapi

For more information on the setup, see the PyPi: nhlscrapi. The documentation for the package can be found at nhlscrapi: NHL Scraper API.

Usage Example

Scrape data for game 1226 of 2014, Ottawa vs Pittsburgh.

from nhlscrapi.games.game import Game, GameKey, GameType
from nhlscrapi.games.cumstats import Score, ShotCt, Corsi, Fenwick

season = 2014                                    # 2013-2014 season
game_num = 1226                                  #
game_type = GameType.Regular                     # regular season game
game_key = GameKey(season, game_type, game_num)

# define stat types that will be counted as the plays are parsed
cum_stats = {
  'Score': Score(),
  'Shots': ShotCt(),
  'Corsi': Corsi(),
  'Fenwick': Fenwick()
}
game = Game(game_key, cum_stats=cum_stats)

# also http requests and processing are lazy
# accumulators require play by play info so they parse the RTSS PBP
print('Final         : {}'.format(game.cum_stats['Score'].total))
print('Shootout      : {}'.format(game.cum_stats['Score'].shootout.total))
print('Shots         : {}'.format(game.cum_stats['Shots'].total))
print('EV Shot Atts  : {}'.format(game.cum_stats['Corsi'].total))
print('Corsi         : {}'.format(game.cum_stats['Corsi'].share()))
print('FW Shot Atts  : {}'.format(game.cum_stats['Fenwick'].total))
print('Fenwick       : {}'.format(game.cum_stats['Fenwick'].share()))

# http req for roster report
# only parses the sections related to officials and coaches
print('\nRefs          : {}'.format(game.refs))
print('Linesman      : {}'.format(game.linesman))
print('Coaches')
print('  Home        : {}'.format(game.home_coach))
print('  Away        : {}'.format(game.away_coach))

# scrape all remaining reports
game.load_all()

Current Release: v0.4.4

This is a pre-release and is not stable and fully fit for production. The first full stable release (v1.0.0) will be made available once the framework for all NHL game reports are completed. Currently, Play-by-Play, Home/Away TOI, Roster, Face-off Comparison and Event Summary reports are functional.

License

The NHL Scraper API is a free Python library provided under Apache License version 2.0.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

nhlscrapi-0.4.4-py2-none-any.whl (46.2 kB view details)

Uploaded Python 2

File details

Details for the file nhlscrapi-0.4.4-py2-none-any.whl.

File metadata

  • Download URL: nhlscrapi-0.4.4-py2-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.16

File hashes

Hashes for nhlscrapi-0.4.4-py2-none-any.whl
Algorithm Hash digest
SHA256 acbad9ecf44055bf7076063599d49dd2aebac8f34d6ae80282c338f66da86160
MD5 8af3c663254391a160f1f3dfaf214a41
BLAKE2b-256 6c3e1cfdcfe905bd213b59bf4964396c8f906cfb3661e7a8bf5db18cb0936fc2

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