A package to collect data from ESPN Cricinfo
Project description
pycricinfo
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
Release history Release notifications | RSS feed
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 pycricinfo-0.0.32.tar.gz.
File metadata
- Download URL: pycricinfo-0.0.32.tar.gz
- Upload date:
- Size: 735.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27ef2335c0ab9d0bab4cd56eeceefacc17ef63fc0991ee3bc87075efe7229969
|
|
| MD5 |
ed739f24a1336c0bf538f5e7335f11b2
|
|
| BLAKE2b-256 |
71a0e13e83037b19e45344e692e7450a7e488fb5a43d769ca19ff3574ac10e5c
|
File details
Details for the file pycricinfo-0.0.32-py3-none-any.whl.
File metadata
- Download URL: pycricinfo-0.0.32-py3-none-any.whl
- Upload date:
- Size: 46.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1c4af0e6530600279ea5b9be7f6302bfe26d7baa99a69e13e5ec2308c826106
|
|
| MD5 |
2a1e50296f07516a3dde9854e66f82cc
|
|
| BLAKE2b-256 |
02f80b2b4bddbdf4cc95a7fb1aecb793121baa43ae73ffe9f0e8a1ac9726dd6c
|