Skip to main content

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.

AI Declaration

The project was started before agentic coding, so a lot of it is handwritten. I then used GitHub Copilot for a while, mostly just for auto-complete rather than in full agentic mode, apart from some tasks such as parsing pages and enabling scraping where the agent was used.
As of version 1.0.0, I have moved to Claude instead, with a mix of manual coding and agentic development.

Installation

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

Pip

uv add pycricinfo

UV

pip install 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:

uv add pycricinfo --optional api

or

pip install 'pycricinfo[api]'

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.

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

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.

Metadata

Release files for pycricinfo 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycricinfo 1.1.0
File Size Uploaded Provenance Actions
pycricinfo-1.1.0.tar.gz 920.1 kB Without provenance Details for pycricinfo-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycricinfo 1.1.0
File Interpreter ABI Platform Actions
pycricinfo-1.1.0-py3-none-any.whl Python 3 none any Details for pycricinfo-1.1.0-py3-none-any.whl

Total release size: 980.6 kB

Release files / pycricinfo-1.1.0.tar.gz

Download URL pycricinfo-1.1.0.tar.gz
Size 920.1 kB
Tags Source
SHA-256 checksum
How to use checksums
90c4581385658f67ee6d94d0a685f05ab6634022702e931fa6a062a4d475e021
BLAKE2b-256 checksum
How to use checksums
fdca80f7a0b1fd11dc30947449ee39b1c22761d7dda18def60106a704b5f7ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Release files / pycricinfo-1.1.0-py3-none-any.whl

Download URL pycricinfo-1.1.0-py3-none-any.whl
Size 60.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91f73e58bfa9a3d75e1be69592aebdb119c5bee1d4743e07108700b7f29e34ac
BLAKE2b-256 checksum
How to use checksums
8204672be02dc7fc340d49934db76d9986d97f714c07d2421c3782851750b503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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}

Security for pycricinfo 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page