Skip to main content

Python library for SofaScore data extraction. Built on scrapling/curl_cffi stealth engine.

Project description

pysofascore

Disclaimer / Отказ от ответственности

This project and library is created and used exclusively for educational and research purposes. It is not intended for commercial use, automated data collection at scale, or any activity that violates SofaScore's Terms of Service. The project is not actively maintained — use at your own risk.

Данный проект и библиотека созданы и используются исключительно в познавательных (educational) целях. Проект не предназначен для коммерческого использования или массового автоматизированного сбора данных. Проект не поддерживается на постоянной основе.


Python library for SofaScore data extraction — matches, live scores, statistics, xG, lineups and more.

Built on top of scrapling — uses curl_cffi with Chrome TLS fingerprint impersonation to bypass SofaScore anti-bot protection. No browser binary required.

Installation

pip install pysofascore

That's it. No browser downloads needed.

Quick Start

from sofascore_api import SofaScoreClient

client = SofaScoreClient()

# Get all football categories (countries)
categories = client.get_categories("football")
for cat in categories[:5]:
    print(f"{cat['id']}: {cat['name']}")

# Get today's matches
events = client.get_events_today("football")
print(f"\nToday: {len(events)} matches")

# Get live matches
live = client.get_live_events("football")
for ev in live[:5]:
    home = ev["homeTeam"]["name"]
    away = ev["awayTeam"]["name"]
    hs = ev.get("homeScore", {}).get("current", "?")
    as_ = ev.get("awayScore", {}).get("current", "?")
    print(f"  LIVE: {home} {hs} - {as_} {away}")

client.close()

Or use as a context manager:

with SofaScoreClient() as client:
    events = client.get_events_today()

Features

Categories & Sports

# All categories for a sport
categories = client.get_categories("football")
categories = client.get_all_categories("basketball")

# Tournaments within a category (country)
tournaments = client.get_category_tournaments(category_id=1)  # England

Matches by Date

# Specific date
events = client.get_events_by_date("football", "2026-04-07")

# Today
events = client.get_events_today("football")

# Next 7 days (returns {date: [events]})
week = client.get_events_week("football")

# Next 30 days
month = client.get_events_month("football")

# Custom range
events = client.get_events_range("football", start="2026-04-01", end="2026-04-15")

Live Matches

live = client.get_live_events("football")
tournaments = client.get_live_tournaments("football")

Match Statistics & xG

event_id = 13981725

# Full statistics (possession, shots, corners, xG, etc.)
stats = client.get_event_statistics(event_id)

# Shot map with per-shot xG and xGOT
shotmap = client.get_event_shotmap(event_id)
for shot in shotmap:
    print(f"{shot['player']['name']}: xG={shot['xg']:.3f}, type={shot['shotType']}")

# Match incidents (goals, cards, substitutions)
incidents = client.get_event_incidents(event_id)

# Lineups
lineups = client.get_event_lineups(event_id)

# Momentum graph
graph = client.get_event_graph(event_id)

# Head-to-head
h2h = client.get_event_h2h(event_id)

# Best players
best = client.get_event_best_players(event_id)

Search

results = client.search("Barcelona")

Tournaments

seasons = client.get_tournament_seasons(17)  # Premier League
standings = client.get_tournament_standings(17, season_id=76986)
top_scorers = client.get_tournament_top_players(17, season_id=76986, kind="goals")

Teams & Players

team = client.get_team(2817)               # Barcelona
players = client.get_team_players(2817)
recent = client.get_team_events(2817, direction="last")

player = client.get_player(284363)
transfers = client.get_player_transfer_history(284363)
heatmap = client.get_player_heatmap(284363, event_id=13981725)

Proxy Support

# HTTP proxy
client = SofaScoreClient(proxy="http://user:pass@proxy.example.com:8080")

# SOCKS5 proxy
client = SofaScoreClient(proxy="socks5://proxy.example.com:1080")

Configuration

client = SofaScoreClient(
    proxy=None,        # Proxy URL
    timeout=15,        # Request timeout in seconds
    retries=3,         # Retry attempts on 403/network errors
    retry_delay=2.0,   # Initial delay between retries (doubles each attempt)
)

How It Works

SofaScore protects their API with anti-bot measures (Cloudflare, TLS fingerprinting). Regular HTTP libraries like requests or httpx get blocked with 403.

This library uses curl_cffi (the same engine that powers scrapling's Fetcher) to:

  1. Impersonate Chrome's TLS fingerprint (JA3/JA4, cipher suites, ALPN)
  2. Send browser-like headers (Referer, Origin, Accept)
  3. Automatically retry on 403 with exponential backoff
  4. Return parsed JSON responses

No browser binary, no Selenium, no Playwright — just HTTP with the right fingerprint.

Supported Sports

football, basketball, tennis, ice-hockey, table-tennis, baseball, handball, american-football, volleyball, darts, esports, mma, motorsport, cricket, rugby, futsal, waterpolo, snooker, cycling, badminton

License

MIT

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

pysofascore-0.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

pysofascore-0.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file pysofascore-0.2.0.tar.gz.

File metadata

  • Download URL: pysofascore-0.2.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pysofascore-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0c95952901a738917992d4f5eb78a04631a70c7a6c9c8544ce75ee26cd04fbb9
MD5 f77f9caffca9594dfa987cdc9bbd0c97
BLAKE2b-256 b3dc2d23d5ebbf46de968fd79953f24f99347dce9314e6cb47452f68b0cc435a

See more details on using hashes here.

File details

Details for the file pysofascore-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pysofascore-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pysofascore-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0102a0adbd3bde7e34f0ed7a894bda7eac81200bc3a87fd37177add500f70d98
MD5 60e238dcf41c142a9ebe859fe45cc3e0
BLAKE2b-256 312b67ab19e443379c9578c04984b219d25a0f40a747503003849e72fa3a3ba0

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