Python package to pull sports stats from all major sports leagues.
Project description
SPORTREFPY
Sportrefpy is package that pulls data from the Sports-Reference family of sites. Currently, only NBA is working but NHL, NFL, MLB, and College Basketball and Football will be supported as soon as possible.
Table of Contents
Installation
pip install sportrefpy
Usage
Below are some examples for ways that you can use Sports Stats.
NBA
Initialize a league, team, or player
from sportrefpy.nba.league import NBA
from sportrefpy.nba.team import NBAFranchise
from sportrefpy.nba.player import NBAPlayer
nba = NBA()
sixers = NBAFranchise('PHI')
the_answer = NBAPlayer('Allen Iverson')
Print out Franchise Codes (needed for initializing a team)
from sportrefpy.nba.league import NBA
nba = NBA()
nba.franchise_codes()
Find the career totals (regular + playoffs) of a specific player
from sportrefpy.nba.player import NBAPlayer
# For all stats
king = NBAPlayer('LeBron James')
king.career_totals()
# For a specific stats
beard = NBAPlayer('James Harden')
beard.career_totals(stats=['PTS', 'G'])
- stats is None by default. If provided, it must be a list even if only using 1.
Compare players stat totals
from sportrefpy.nba.analysis import compare_players
showtime = compare_players(["Shaquille O'Neal", "Kobe Bryant"],
stats=['PTS', 'TRB'],
total='career')
- stats must be a list, with as many stats as you'd like. Required.
- total defaults to 'career', but can also be 'post' or 'reg'.
Compare Franchise W/L records
from sportrefpy.nba.analysis import compare_franchises
compare_franchises(['NYK', 'BOS'])
- must be a list of teams, even if only using 1.
Get stats of players for a specific Franchise
from sportrefpy.nba.team import NBAFranchise
bulls = NBAFranchise('CHI')
# All players that have ever played for the team
bulls.players_all_time_stats()
# Or just the GOAT
bulls.players_all_time_stats('Michael Jordan')
Get stats of coaches for a specific Franchise
from sportrefpy.nba.team import NBAFranchise
spurs = NBAFranchise('SAS')
# All coaches that have ever coached the team
spurs.coaches_all_time_data()
# Or just Pop
spurs.coaches_all_time_data('Gregg Popovich')
Get roster for a given season
from sportrefpy.nba.team import NBAFranchise
warriors = NBAFranchise('GSW')
warriors.roster(2016)
- use integer year that season ends in. This example returns the 2015-16 Golden State Warriors.
Get current season standings
from sportrefpy.nba.league import NBA
nba = NBA()
# Both conferences
east, west = nba.current_standings()
# Just one of them
west = nba.current_standings(conf='west')
east = nba.current_standings(conf='east')
Get franchise season history
from sportrefpy.nba.team import NBAFranchise
mavs = NBAFranchise('DAL')
# Get all seasons
mavs.season_history()
# Get an individual season
mavs.season_history(year='2010-11')
- year defaults to all seasons. For an individual season, it needs to be a string like in the above example.
Find which seasons a team won the NBA Finals
from sportrefpy.nba.team import NBAFranchise
pistons = NHLFranchise('DET')
seasons = pistons.season_history()
seasons[seasons['Playoffs'] == 'Won Finals']]
NHL
Initialize a league, team, or player
from sportrefpy.nhl.league import NHL
from sportrefpy.nhl.team import NHLFranchise
from sportrefpy.nhl.player import NHLPlayer
nhl = NHL()
flyers = NHL('PHI')
the_great_one = NHL('Wayne Gretzky')
Print out Franchise Codes (needed for initializing a team)
from sportrefpy.nhl.league import NHL
nhl = NHL()
nhl.franchise_codes()
Compare Franchise W/L records
from sportrefpy.nhl.analysis import compare_franchises
compare_franchises(['TBL', 'DET'])
- must be a list of teams, even if only using 1.
Get roster for a given season
from sportrefpy.nhl.team import NHLFranchise
blues = NHLFranchise('STL')
blues.roster(2019)
- use integer year that season ends in. This example returns the 2018-19 St. Louis Blues.
Get franchise season history
from sportrefpy.nhl.team import NHLFranchise
flames = NHLFranchise('CGY')
# Get all seasons
flames.season_history()
# Get an individual season
flames.season_history(year='1988-89')
- year defaults to all seasons. For an individual season, it needs to be a string like in the above example.
Get Stanley Cup winning seasons
from sportrefpy.nhl.team import NHLFranchise
leafs = NHLFranchise('TOR')
seasons = leafs.season_history()
seasons[seasons['Playoffs'] == 'Won Stanley Cup Final']]
Saving Data
You can write the data to a CSV, JSON, or other file just like you would a Pandas DataFrame
import pandas as pd
from sportrefpy.nba.analysis import compare_franchises
compare_franchises(['IND', 'MIL']).to_csv('comparison.csv')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sportrefpy-0.2.0.tar.gz
(95.7 kB
view details)
Built Distribution
sportrefpy-0.2.0-py3-none-any.whl
(102.2 kB
view details)
File details
Details for the file sportrefpy-0.2.0.tar.gz
.
File metadata
- Download URL: sportrefpy-0.2.0.tar.gz
- Upload date:
- Size: 95.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e4fcfaca667c2addbf761ede364ef0c990d4625092ed84f74263ee8a9c6a8c |
|
MD5 | 2be7d4d5a21ad77dbcd446baf65d8ac7 |
|
BLAKE2b-256 | 52fdba2ca4c5a84bbe0172598d17b6d8c178cdcb0c6a1d2854942fafabe7205f |
File details
Details for the file sportrefpy-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: sportrefpy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 102.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99bb55c5c7a0bf99902c6c4edb9a6957e2353f54bdabf1f386ec111ba1d4c5f0 |
|
MD5 | 7e0c44021b5c42b2ff3a64be8978b7a5 |
|
BLAKE2b-256 | 9efed11969c151ff795497124a0c963016ae6ee345719c751214d324b656456d |