Home

Awesome

StatsBomb JSON parser

PyPI version PyPI - Python Version Build Status codecov HitCount

Convert competitions/matches/lineups/events JSON data released by StatsBomb into easy-to-use CSV format.

A simple web interface for this package can be found here.

Installation

$ pip install statsbomb

Example usage

import statsbomb as sb

comps = sb.Competitions()
print(len(comps))  # 3
json_data = comps.data  # underlying json data

df = comps.get_dataframe()
print(df)
competition_idcompetition_namecountry_namematch_availablematch_updatedseason_idseason_name
37FA Women's Super LeagueEngland2018-09-08T07:33:39.3563402018-09-08T07:33:39.35634012017/2018
43FIFA World CupInternational2018-09-08T07:33:39.3563402018-09-08T14:30:04.35651432018
49NWSLUnited States of America2018-09-08T07:33:39.3563402018-09-08T07:33:39.35634032018
import statsbomb as sb

matches = sb.Matches(event_id='11', season_id='37')
df = matches.get_dataframe()
print(len(df))  # 7
import statsbomb as sb

events = sb.Events(event_id='8658')
df = events.get_dataframe(event_type='shot')
print(len(df))  # 23

print(df)
event_typeidindexperiodtimestampminutesecondpossessionpossession_teamplay_patternoff_camerateamplayerpositiondurationunder_pressurestatsbomb_xgkey_pass_idbody_parttypeoutcometechniquefirst_timefollows_dribbleredirectone_on_oneopen_goaldeflectedstart_location_xstart_location_yend_location_xend_location_yend_location_z
shotc3ffbb5f-d836-4d33-a02a-3a994990d253577100:20:51.227205139CroatiaFrom Free KickFalseCroatiaDomagoj VidaLeft Center Back1.0130.05478843baafd0a9-1031-46df-82a2-16538d6e94cfHeadOpen PlayOff TNormal112.049.0119.036.74.7
shotd7a727de-1b60-47c7-b9fa-10948bb730ed634100:23:34.907233445CroatiaFrom Free KickFalseCroatiaIvan RakitićLeft Center Midfield2.0530.043759829cc48e31-5a52-4074-97b1-5c3eafdd753dLeft FootOpen PlayOff TVolley108.029.0120.046.96.1
shot20bcdb94-9507-4bed-8315-edddcbb84081736100:27:53.880275353CroatiaFrom Free KickFalseCroatiaIvan PerišićLeft Wing0.5870.1217227890fdf286-3e32-4646-bcb1-a83a7d51593fLeft FootOpen PlayGoalHalf VolleyTrueTrue105.032.0120.043.30.7
...................................................................................................
import statsbomb as sb

events = sb.Events(event_id='8658')
events.save_data(event_type='shot')  # outputs a file named events_8658_shot.csv

Contributing

Clone the repo:

git clone https://github.com/imrankhan17/statsbomb-parser.git
cd statsbomb-parser

Create a virtual environment:

python -m venv env
source env/bin/activate
pip install -r requirements.txt

Or use Docker:

docker build -t statsbomb-parser .

To run the CI pipeline locally, execute the commands in the script part of the .travis.yml files. Or using Docker:

docker run -it --rm -v $(pwd):/home -w /home statsbomb-parser python -m pycodestyle --max-line-length=119 statsbomb tests *.py
docker run -it --rm -v $(pwd):/home -w /home statsbomb-parser python -m pylint statsbomb tests *.py
docker run -it --rm -v $(pwd):/home -w /home statsbomb-parser python -m pytest --disable-pytest-warnings --cov=statsbomb --cov-report=html --durations=5 tests/