rugbypy

Repository for rugby data analytics.

rugbypy is a Python package that aims to make rugby data more available to aid in the development of rugby analytics.

Data is updated daily 5AM UTC! Currently we only have 2023 data available with previous years coming soon.

Requirements

python version 3.8

Install

pip install rugbypy

How to use

Match Stats

You can fetch all the matches that occured on a particular date with:

from rugbypy.match import *
matches = fetch_matches(date="20230101")
matches
Fetching matches on date:20230101...
match_id competition_id home_team_id home_team away_team_id away_team date
0 595735 267979 25907 Northampton Saints 25901 Harlequins 20230101

Then using that match id you can feed it into the match details function:

from rugbypy.match import *
match_details = fetch_match_details(match_id="595735")
match_details
Fetching match details for match_id:595735...
match_id date season competition_id competition venue_id venue city_played home_team away_team home_team_id away_team_id completed is_tournament played_on_grass attendance home_team_form away_team_form
0 595735 20230101 2023 267979 Premiership Rugby 26070 cinch Stadium at Franklin's Gardens Northampton Northampton Saints Harlequins 25907 25901 True True True None LLWWL WLWLL

Team Stats

You can then fetch the team stats for a particular team on a particular date with:

from rugbypy.team import *
team_stats = fetch_team_stats(team_id="25901", date="20230108")
team_stats
Fetching team stats for team_id:25901 on date:20230108...
team game_date team_id team_vs team_vs_id match_id players clean_breaks conversion_goals defenders_beaten ... scrums_total scrums_won tackles territory total_free_kicks_conceded total_lineouts tries turnover_knock_on turnovers_conceded yellow_cards
0 Harlequins 20230108 25901 Sale Sharks 25908 595741 [158708, 299436, 299031, 298485, 295117, 29477... 3.0 0.0 24.0 ... 7.0 5.0 125.0 0.41 0.0 11.0 2.0 8.0 17.0 0.0

1 rows × 42 columns

Player Stats

We have the ability to fetch player stats for all the games they have bene involved in. We firstly identify the `player_id`` of a player by searching our player manifest file.

from rugbypy.player import *
player_manifest = fetch_all_players()
player_manifest.head()
player_id player_name
0 246815 Will Edwards
1 158708 Tommaso Allan
2 299436 Oscar Beard
3 299031 Fin Baxter
4 298485 Jordan Els

Or we can search for a certain player through our similarity tool:

from rugbypy.player import *
individual_player = fetch_player(name="johnny sexton")
individual_player
player_id player_name
267 149315 Anthony Watson
294 16004 Johnny Sexton
796 291349 Ayden Johnstone

We can also fetch the player stats for any player using their player_ids. In this example we fetch Johnny Sextons player stats:

from rugbypy.player import *
player_stats = fetch_player_stats(player_id="16004")
player_stats
Fetching all player stats for player_id:16004...
player_id game_date name team team_id competition_id competition match_id team_vs team_vs_id ... rucks_won runs tackles total_free_kicks_conceded total_lineouts tries try_assists turnover_knock_on turnovers_conceded yellow_cards
0 16004 20230204 Johnny Sexton Ireland 3 180659 Six Nations Championship 596205 Wales 4 ... 3.0 8.0 7.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
0 16004 20230211 Johnny Sexton Ireland 3 180659 Six Nations Championship 596208 France 9 ... 1.0 5.0 3.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0 16004 20230312 Johnny Sexton Ireland 3 180659 Six Nations Championship 596216 Scotland 2 ... 2.0 5.0 9.0 0.0 0.0 0.0 0.0 0.0 2.0 0.0
0 16004 20230318 Johnny Sexton Ireland 3 180659 Six Nations Championship 596219 England 1 ... 6.0 9.0 5.0 0.0 0.0 0.0 0.0 1.0 2.0 0.0
0 16004 20230909 Johnny Sexton Ireland 3 164205 Rugby World Cup 596156 Romania 12 ... 0.0 5.0 4.0 0.0 0.0 2.0 0.0 0.0 0.0 0.0
0 16004 20230916 Johnny Sexton Ireland 3 164205 Rugby World Cup 596166 Tonga 16 ... 1.0 1.0 2.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0
0 16004 20230923 Johnny Sexton Ireland 3 164205 Rugby World Cup 596175 South Africa 5 ... 1.0 3.0 11.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

7 rows × 41 columns