A Python package extracting match, player & statistical data from ESPNCricinfo, either using their (otherwise undocumented) API, or by scraping pages.
Defines Pydantic models to represent data from the API, allowing easier interaction with the data in your code.
0.0.X version number, is liable to change in a breaking way with any release
Use your package manager of choice to install pycricinfo. For example:
pip install pycricinfo
uv add pycricinfo
This project also comes with an optional dependency to run an API wrapper around Cricinfo, providing an OpenAPI specification through FastAPI. Install this optional dependency with:
pip install 'pycricinfo[api]'
or
uv add pycricinfo --optional api
Installing the project adds 2 scripts:
Produces a match scorecard in the CLI, output using PrettyTable.
Can either be from an already downloaded JSON file on disk, or fetched on demand from the API, by changing parameter options:
--file: A path to a JSON file from the Cricinfo match summary API
or
--match_id: The Cricinfo ID of a match while will be fetched from the summary API--series_id: The Cricinfo ID of the series this match was in
Produces a summary of each ball in a page of data in the CLI.
Can either be output from an already fetched JSON file on disk, or fetched on demand from the API, by changing parameter options:
--file: A path to a JSON file from the Cricinfo 'play-by-play' API to the
or
--match_id: The Cricinfo ID of a match while will be fetched from the summary API--innings: The innings of the game to get data from--page: The page of commentary to return from that innings
Installing the optional API dependency adds a further script:
Runs uvicorn to launch a FastAPI wrapper around the Cricinfo API, which will launch on port 8000, with the Swagger documentation available at http://localhost:8000/docs
Import one of the get_ function from pycricinfo.search.
For scorecards as above, use:
from pycricinfo.search import get_scorecard
async def show_scorecard(series_id: int, match_id: int):
scorecard = await get_scorecard(series_id, match_id)
scorecard.show()Other data is available, always returning strongly typed and documented Pydantic models, such as:
from pycricinfo.search import get_player
async def fetch_player_from_cricinfo(player_id: int):
cricinfo_player = await get_player(player_id)
print(cricinfo_player.display_name)A docker image is also produced which runs the project's API on port 8000.
Run the included docker-compose.yml and browse to http://localhost:8000/docs for the Swagger interface.