Skip to main content

Python library for loading cricket statistics from ESPN Cricinfo into pandas DataFrames

Project description

cricinfo

Tests Documentation PyPI

Python library for loading cricket statistics from ESPN Cricinfo into pandas DataFrames.

Installation

pip install cricinfo-stats

Requires Python 3.10+.

Features

  • Career batting, bowling, fielding, and all-round statistics for international cricketers.
  • Partnership statistics for international cricket teams.
  • Aggregated team statistics in international cricket.

Usage

from cricinfo import Cricinfo, Team, MatchFormat, StatType

# Retrieve batting stats for Pakistan in T20Is
df = Cricinfo.retrieve_stats(
    team=Team.Pakistan,
    match_format=MatchFormat.T20I,
    stat_type=StatType.BATTING,
)

# Retrieve team stats across all teams in Tests
df = Cricinfo.retrieve_stats(
    team=None,
    match_format=MatchFormat.Test,
    stat_type=StatType.TEAM,
)

Sample Output

>>> df.head()
                Player  Mat  Inns    Runs     HS   Ave    SR  100  50  ...
0       Babar Azam (PK)   99   93    3485  122*  46.46  129.0  9  26  ...
1  Mohammad Rizwan (PK)   72   65    2088   88*  38.66  126.0  0  19  ...

Error Handling

retrieve_stats may raise:

  • requests.HTTPError if ESPN Cricinfo is unreachable or returns an error.
  • ValueError if the response HTML cannot be parsed.

Supported Teams

Enum Value Team
Team.England England
Team.Australia Australia
Team.SouthAfrica South Africa
Team.WestIndies West Indies
Team.NewZealand New Zealand
Team.India India
Team.Pakistan Pakistan
Team.SriLanka Sri Lanka
Team.Zimbabwe Zimbabwe
Team.Bangladesh Bangladesh
Team.Ireland Ireland
Team.Afghanistan Afghanistan

Pass team=None to retrieve stats for all teams.

Supported Formats

Enum Value Format
MatchFormat.Test Test
MatchFormat.ODI ODI
MatchFormat.T20I T20I
MatchFormat.International International (aggregated)

Stat Types

Enum Value Description
StatType.BATTING Career batting statistics
StatType.BOWLING Career bowling statistics
StatType.FIELDING Career fielding statistics
StatType.ALLROUND Career all-round statistics
StatType.PARTNERSHIP Partnership statistics
StatType.TEAM Team statistics
StatType.AGGREGATE Aggregated team statistics

Development

Testing

coverage run -m pytest -v -s
coverage report -m

Linting

ruff check .

Documentation

Documentation is hosted on Read the Docs and rebuilds automatically on every push to main (configured via .readthedocs.yaml). Sphinx pulls docstrings from source using autodoc.

To build locally:

cd docs/
make clean
make html

Packaging

Update the version in:

  1. setup.py
  2. docs/source/conf.py

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

cricinfo_stats-2.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

cricinfo_stats-2.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file cricinfo_stats-2.0.0.tar.gz.

File metadata

  • Download URL: cricinfo_stats-2.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.12

File hashes

Hashes for cricinfo_stats-2.0.0.tar.gz
Algorithm Hash digest
SHA256 66a72df44606d0ac0c769389fb43a2fab5a81eed5aae00710a5b45893234b204
MD5 90a349fa3501cb229bd644f5385a0997
BLAKE2b-256 838323e4ddf113a4ad1e81211b2c12a0031c3b1ed44e25189b42285aafa37fbb

See more details on using hashes here.

File details

Details for the file cricinfo_stats-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: cricinfo_stats-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.12

File hashes

Hashes for cricinfo_stats-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4399a6f18feea466c681fbf9a6f3164fa5b35698ef6e0f1dee9dc1cd3bc46021
MD5 d5923e658494f0c61b799fb1058402f1
BLAKE2b-256 e4bf7e4a977ebdc839b513b5ea51ec03c4905508bc78f5961d611de65675a091

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