Skip to main content

A Python API for scraping football data from understat.com

Project description

CI PyPI License: MIT Python 3.10+

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.2.tar.gz (538.0 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.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jeke_understat_scrapper-1.0.2.tar.gz
  • Upload date:
  • Size: 538.0 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.2.tar.gz
Algorithm Hash digest
SHA256 2ebf1ee91c73682ef6e56a68417ea60a869615ffeb5f6e888b55fd1306273e0c
MD5 873b8b74719f5f1e8ce130647e0b48d0
BLAKE2b-256 f08cacb84e449faca9cd96c16e0d2ed86115c8a0c81cc311f9a58420ff8810e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jeke_understat_scrapper-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c40c0f0cd03bd3751cc2ea86c89a896535d973de4a043963a40aa0a34d08cb5e
MD5 ff2ea284185caafb97180448292ff161
BLAKE2b-256 ceb78dc86dd18c727ea74204ef3544114ee695056190f8d9779c9a954943ae8f

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