rugbypy is a Python package that aims to make rugby data more available to aid in the development of rugby analytics.
PyPI - Downloads
Data is updated daily 5AM UTC! Currently we only have data for 2022, 2023 & 2024
Requirements
python version 3.9
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
1
599464
270557
25965
Cardiff Blues
25968
Ospreys
20230101
2
599465
270557
25966
Scarlets
25967
Dragons
20230101
3
599466
270557
25926
Ulster
25925
Munster
20230101
4
599467
270557
25924
Leinster
25923
Connacht
20230101
5
597648
270559
25917
Clermont Auvergne
25922
Stade Toulousain
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
WLWWL
WTLWL
Team Stats
You can fetch the team stats for every game with:
from rugbypy.team import*team_stats = fetch_team_stats(team_id="25901")team_stats
Fetching all team stats for team_id: 25901...
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
20220102
25901
Gloucester Rugby
25900
593902
[290946, 298485, 296815, 296184, 295534, 29512...
3.0
2.0
26.0
...
7.0
7.0
94.0
0.63
1.0
16.0
2.0
9.0
15.0
2.0
1
Harlequins
20220108
25901
Exeter Chiefs
116227
593909
[290946, 296815, 296184, 295534, 295121, 29484...
5.0
2.0
16.0
...
11.0
9.0
124.0
0.55
0.0
10.0
2.0
8.0
17.0
0.0
2
Harlequins
20220128
25901
Bath Rugby
25898
593913
[158708, 299436, 298485, 296815, 296791, 29553...
7.0
1.0
12.0
...
8.0
7.0
162.0
0.50
0.0
9.0
3.0
11.0
15.0
1.0
3
Harlequins
20220206
25901
Sale Sharks
25908
593922
[158708, 299436, 299031, 298764, 298487, 29848...
7.0
2.0
20.0
...
5.0
5.0
71.0
0.54
2.0
12.0
2.0
17.0
26.0
0.0
4
Harlequins
20220213
25901
Saracens
25909
593929
[158708, 299436, 298764, 298487, 298485, 29681...
3.0
1.0
23.0
...
4.0
2.0
98.0
0.56
1.0
15.0
1.0
11.0
17.0
0.0
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
56
Harlequins
20240421
25901
Sale Sharks
25908
597118
[290946, 257545, 301432, 299436, 299031, 29681...
8.0
3.0
36.0
...
3.0
3.0
119.0
0.45
0.0
21.0
5.0
8.0
15.0
0.0
57
Harlequins
20240427
25901
Northampton Saints
25907
597122
[290946, 257545, 301432, 300430, 299436, 29903...
10.0
4.0
22.0
...
6.0
5.0
125.0
0.45
0.0
12.0
6.0
4.0
6.0
3.0
58
Harlequins
20240505
25901
Stade Toulousain
25922
597203
[290946, 301432, 299436, 299031, 296815, 29679...
5.0
3.0
23.0
...
3.0
2.0
92.0
0.47
0.0
15.0
4.0
8.0
16.0
1.0
59
Harlequins
20240511
25901
Exeter Chiefs
116227
597126
[290946, 301432, 299436, 299031, 296815, 29679...
4.0
3.0
33.0
...
4.0
3.0
133.0
0.40
0.0
9.0
4.0
7.0
11.0
0.0
60
Harlequins
20240518
25901
Bristol Rugby
25899
597132
[290946, 301432, 299436, 299031, 299029, 29681...
6.0
4.0
24.0
...
4.0
3.0
129.0
0.45
1.0
16.0
4.0
6.0
12.0
0.0
61 rows × 42 columns
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
28
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 been 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
262799
AJ MacGinty
1
295135
Bevan Rodd
2
294815
Tom Roebuck
3
294814
Gus Warr
4
294810
Sam Dugdale
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
1345
16004
Johnny Sexton
2156
291349
Ayden Johnstone
2795
149315
Anthony Watson
Once we have their player_id we can fetch their player stats using fetch_player_stats. 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
20220205
Johnny Sexton
Ireland
3
180659
Six Nations
595080
Wales
4
...
4.0
9.0
7.0
0.0
0.0
0.0
1.0
1.0
2.0
0.0
1
16004
20220227
Johnny Sexton
Ireland
3
180659
Six Nations
595088
Italy
20
...
1.0
3.0
1.0
0.0
0.0
0.0
1.0
0.0
0.0
0.0
2
16004
20220312
Johnny Sexton
Ireland
3
180659
Six Nations
595091
England
1
...
4.0
12.0
7.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
3
16004
20220319
Johnny Sexton
Ireland
3
180659
Six Nations
595093
Scotland
2
...
3.0
3.0
10.0
0.0
0.0
0.0
0.0
0.0
1.0
0.0
4
16004
20220610
Johnny Sexton
Leinster
25924
270557
United Rugby Championship
594483
Bulls
25953
...
0.0
3.0
2.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
5
16004
20221216
Johnny Sexton
Leinster
25924
271937
European Rugby Champions Cup
597405
Gloucester Rugby
25900
...
0.0
0.0
7.0
0.0
0.0
0.0
0.0
1.0
1.0
0.0
6
16004
20230204
Johnny Sexton
Ireland
3
180659
Six Nations
596205
Wales
4
...
3.0
8.0
7.0
0.0
0.0
0.0
0.0
0.0
1.0
0.0
7
16004
20230211
Johnny Sexton
Ireland
3
180659
Six Nations
596208
France
9
...
1.0
5.0
3.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
8
16004
20230312
Johnny Sexton
Ireland
3
180659
Six Nations
596216
Scotland
2
...
2.0
5.0
9.0
0.0
0.0
0.0
0.0
0.0
2.0
0.0
9
16004
20230318
Johnny Sexton
Ireland
3
180659
Six Nations
596219
England
1
...
6.0
9.0
5.0
0.0
0.0
0.0
0.0
1.0
2.0
0.0
10
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
11
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
12
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
13
16004
20231007
Johnny Sexton
Ireland
3
164205
Rugby World Cup
596190
Scotland
2
...
0.0
5.0
7.0
0.0
0.0
0.0
1.0
0.0
0.0
0.0
14
16004
20231014
Johnny Sexton
Ireland
3
164205
Rugby World Cup
596195
New Zealand
8
...
0.0
1.0
11.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
15 rows × 41 columns
We can also fetch the player stats on a particular date using fetch_player_stats. In this example we fetch Johnny Sextons player stats on 2023-09-16:
from rugbypy.player import*player_stats = fetch_player_stats(player_id="16004", date="20230916")player_stats
Fetching player stats for player_id: 16004 on date: 20230916...