Skip to main content

A package to collect data from ESPN Cricinfo

Project description

pycricinfo

PyPI version Upload to PyPi Upload to ghcr.io

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.

Project status

:warning: This project is still in pre-release and, whilst it still has a 0.0.X version number, is liable to change in a breaking way with any release :warning:

Installation

Use your package manager of choice to install pycricinfo. For example:

Pip

pip install pycricinfo

UV

uv add pycricinfo

Optional installation: API

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

Sample usage: CLI

Installing the project adds 2 scripts:

print_scorecard

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

print_ballbyball

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:

run_api

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

Sample usage: In code

Import one of the get_ function from the root of the library.

For scorecards as above, use:

from pycricinfo 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 import get_player


async def fetch_player_from_cricinfo(player_id: int):
    cricinfo_player = await get_player(player_id)
    print(cricinfo_player.display_name)

Reusing a session

By default, each call creates and closes its own HTTP session. For better reliability when making multiple requests — particularly when fetching data across several seasons or matches — you can create a shared session using create_session() and pass it to each call.

A persistent session retains cookies set by the server across requests, which makes subsequent calls appear more like a real browser session and reduces the likelihood of being rejected with transient 5xx errors.

from pycricinfo import create_session, get_match_types_in_season


async def fetch_multiple_seasons():
    async with create_session() as session:
        season_2023 = await get_match_types_in_season("2023", session=session)
        season_2024 = await get_match_types_in_season("2024", session=session)
        season_2024_25 = await get_match_types_in_season("2024/25", session=session)

The session is used as an async context manager, which ensures it is properly closed when done.

Docker

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.

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

pycricinfo-0.0.34.tar.gz (753.3 kB view details)

Uploaded Source

Built Distribution

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

pycricinfo-0.0.34-py3-none-any.whl (47.2 kB view details)

Uploaded Python 3

File details

Details for the file pycricinfo-0.0.34.tar.gz.

File metadata

  • Download URL: pycricinfo-0.0.34.tar.gz
  • Upload date:
  • Size: 753.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pycricinfo-0.0.34.tar.gz
Algorithm Hash digest
SHA256 a0a1e120dd02e07c48fdc14b2cad0b2a8b668cb003c108bdc2f3bd29071f067b
MD5 5fc2aeeedf6ed44215a1d983fdaf7af0
BLAKE2b-256 a913d7f60823e872f369fdcb52aa6150c3fd42896f65bfccb636519ab8bc5597

See more details on using hashes here.

File details

Details for the file pycricinfo-0.0.34-py3-none-any.whl.

File metadata

  • Download URL: pycricinfo-0.0.34-py3-none-any.whl
  • Upload date:
  • Size: 47.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pycricinfo-0.0.34-py3-none-any.whl
Algorithm Hash digest
SHA256 d0044c092d969cad6c208fbdce9776f9a1c38e06c53cc1a8ba7389a097969ac1
MD5 8e5834131e6827a10df7f7fe607c900d
BLAKE2b-256 1a581c6c8b37fdad2bd80e2e39014e43b15a8dde48e8cabd8a84d68a1c15b1b9

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