Skip to main content

A Python API for scraping football data from understat.com

Project description

CI PyPI PyPI - License PyPI - Python Version

jeke-understat-scrapper

A Python API for scraping football data from understat.com. Understat is a website with football data for 6 european leagues for every season since 2014/15 season. The leagues available are the Premier League, La Liga, Ligue 1, Serie A, Bundesliga and the Russian Premier League.

This is a maintained fork of understatapi with fixes for Understat's new AJAX-based data loading.


NOTE

This project is not affiliated with understat.com in any way


Installation

pip install jeke-understat-scrapper

Getting started

The API contains endpoints which reflect the structure of the understat website. Below is a table showing the different endpoints and the pages on understat.com to which they correspond

Endpoint Webpage
UnderstatClient.league https://understat.com/league/<league_name>
UnderstatClient.team https://understat.com/team/<team_name>/<season>
UnderstatClient.player https://understat.com/player/<player_id>
UnderstatClient.match https://understat.com/match/<match_id>

Every method in the public API corresponds to one of the tables visible on the understat page for the relevant endpoint. Each method returns JSON with the relevant data. Below are some examples of how to use the API. Note how the league() and team() methods can accept the names of leagues and teams respectively, but player() and match() must receive an id number.

from understatapi import UnderstatClient

understat = UnderstatClient()
# get data for every player playing in the Premier League in 2019/20
league_player_data = understat.league(league="EPL").get_player_data(season="2019")
# Get the name and id of one of the player
player_id, player_name = league_player_data[0]["id"], league_player_data[0]["player_name"]
# Get data for every shot this player has taken in a league match (for all seasons)
player_shot_data = understat.player(player=player_id).get_shot_data()
from understatapi import UnderstatClient

understat = UnderstatClient()
# get data for every league match involving Manchester United in 2019/20
team_match_data = understat.team(team="Manchester_United").get_match_data(season="2019")
# get the id for the first match of the season
match_id = team_match_data[0]["id"]
# get the rosters for the both teams in that match
roster_data = understat.match(match=match_id).get_roster_data()

You can also use the UnderstatClient class as a context manager which closes the session after it has been used, and also has some improved error handling. This is the recommended way to interact with the API.

from understatapi import UnderstatClient

with UnderstatClient() as understat:
    team_match_data = understat.team(team="Manchester_United").get_match_data(season="2019")

Contributing

If you find any bugs in the code or have any feature requests, please make an issue and I'll try to address it as soon as possible.

Versioning

The versioning for this project follows the semantic versioning conventions.

Credits

This package is based on the original understatapi by collinb9.

Project details


Download files

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

Source Distribution

jeke_understat_scrapper-1.0.0.tar.gz (537.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jeke_understat_scrapper-1.0.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file jeke_understat_scrapper-1.0.0.tar.gz.

File metadata

  • Download URL: jeke_understat_scrapper-1.0.0.tar.gz
  • Upload date:
  • Size: 537.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for jeke_understat_scrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0778225a58aa3d157d846ebd2b9aceb7f6608aabad55248d8be9efedc7151eda
MD5 7e2598e736f600c2b590d01ae3e8bd98
BLAKE2b-256 e0dc8031cf595efe4a0efc2642f25fc8b9ea90352e3f9875f7345cba3f314ee3

See more details on using hashes here.

File details

Details for the file jeke_understat_scrapper-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jeke_understat_scrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06887ca0873d7621abf4847759ba4407edf8f5df3023541279bf8c4339e37b08
MD5 fcd6e5b3763a8e24f27bc77bb5233eec
BLAKE2b-256 bac2602afca8a06953237b6c4dab32c7be37aef989fa07b5b646c1c6276bb4cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page