Python library for loading cricket statistics from ESPN Cricinfo into pandas DataFrames
Project description
cricinfo
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.HTTPErrorif ESPN Cricinfo is unreachable or returns an error.ValueErrorif 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:
setup.pydocs/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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66a72df44606d0ac0c769389fb43a2fab5a81eed5aae00710a5b45893234b204
|
|
| MD5 |
90a349fa3501cb229bd644f5385a0997
|
|
| BLAKE2b-256 |
838323e4ddf113a4ad1e81211b2c12a0031c3b1ed44e25189b42285aafa37fbb
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4399a6f18feea466c681fbf9a6f3164fa5b35698ef6e0f1dee9dc1cd3bc46021
|
|
| MD5 |
d5923e658494f0c61b799fb1058402f1
|
|
| BLAKE2b-256 |
e4bf7e4a977ebdc839b513b5ea51ec03c4905508bc78f5961d611de65675a091
|