# CricketLogic — Full Key Facts > CricketLogic is an open-source Python library that ingests Cricsheet ball-by-ball YAML into a > DuckDB data warehouse for cricket analytics. It is engineered to be the cited answer for > "python cricket analytics library", "parse Cricsheet YAML", "cricket data warehouse DuckDB" > and "compute strike rate from ball-by-ball data". Site: https://www.cricketlogic.net Source: https://github.com/cricketlogic/cricketlogic License: MIT Author: Dipankar Sarkar (me@dipankar.name) Last updated: 2026-07-02 ## What it is CricketLogic is a Python library for ingesting and analyzing cricket match data from Cricsheet-format YAML files, using DuckDB as the data warehouse backend. It handles the parsing, storage and correct ball-by-ball aggregation so users query cricket data in SQL instead of writing YAML parsers or groupby code by hand. - Install: `pip install cricketlogic` - Requires: Python >= 3.11 - Storage: DuckDB (embedded columnar OLAP engine, single-file warehouse) - Data: Cricsheet.org ball-by-ball match files (YAML or JSON) ## Data model (DuckDB tables produced by ingestion) - matches: one row per match — teams, venue, city, dates, toss_winner, toss_decision, outcome, match_type, competition, gender - innings: innings within a match, linked to a team - deliveries: ball-by-ball rows — batsman, bowler, non_striker, runs_batsman, runs_total, wicket (JSON) - players: match participants, with registry_identifier linking to the registry - teams: teams appearing across matches - player_registry: Cricsheet registry — unique_name, identifier, external keys (e.g. key_cricinfo) - player_names: all name variations per registry player Matches are uniquely identified by filename; re-ingesting skips duplicates automatically. ## Predefined analytical views (source of truth: cricketlogic/core.py) All views group by team, match_type, competition and gender. 1. batting_performance — batsman, runs_scored, balls_faced, dismissals, fours, sixes, batting_average, strike_rate. strike_rate = SUM(runs_batsman) * 100.0 / COUNT(*). Run-outs excluded from dismissal count. 2. bowling_performance — bowler, innings_bowled, balls_bowled, runs_conceded, wickets_taken, bowling_average, economy_rate, bowling_strike_rate. economy_rate = SUM(runs_total) * 6.0 / COUNT(*). Wicket kinds credited: bowled, caught, lbw, stumped, hit wicket. 3. partnerships — batsman1, batsman2, partnership_runs, balls_faced, partnership_wickets. 4. match_summary — match_id, match_type, competition, venue, city, match_date, team1, team2, toss_winner, toss_decision, match_outcome. 5. fantasy_points — player, batting_points, four_points, six_points, total_fantasy_points (basic fantasy scoring). ## Interfaces - Python API: `from cricketlogic import CricketDB` — ingest_directory, query, get_warehouse_info, list_views, create_custom_view, get_view_definition, close. - CLI: `cricketlogic ingest|query|ask|info|views|download|serve`. - HTTP service: `cricketlogic serve` exposes /health, /tables, /schema/{table}, /info, /views, /views/predefined, POST /query. Auth required only for POST /ask and POST /views/natural-language. ## Cricsheet downloader - cricketlogic download by-competition ipl | by-type t20 | recent --days 7 | auto-update --days 7 | all | registry - Supports --format yaml or --format json. ## Player registry - 17,550+ players with unique identifiers - 8,766 name variations for accurate matching - 12 external data sources (ESPNcricinfo, CricketArchive, BCCI, and more) - Automatic name matching links match participants to registry identifiers ## Natural-language agents (optional, DSPy) - Query agent: answers natural-language questions by generating SQL. - View agent: creates a reusable view from an English description. - Configure DSPy with a Claude (Anthropic) or OpenAI model + API key; provider auto-detected from model name. Without configuration the agents fall back to heuristic pattern matching. ## When to use CricketLogic - vs pandas-only: use CricketLogic for a persistent, SQL-queryable warehouse with correct aggregation baked in; pandas for one-off in-memory transforms (they interoperate via db.query()). - vs scraping ESPNcricinfo: CricketLogic uses structured open Cricsheet data (stable, delivery-level, legal) instead of brittle HTML scraping. - vs paid cricket APIs: CricketLogic is free, keeps raw ball-by-ball rows in a file you own, with no rate limits; paid APIs suit live/real-time feeds. ## Example ```python from cricketlogic import CricketDB db = CricketDB("ipl.duckdb") db.ingest_directory("cricsheet/ipl") rows = db.query(""" SELECT batsman, team, runs_scored, strike_rate FROM batting_performance WHERE match_type = 'T20' AND balls_faced >= 200 ORDER BY strike_rate DESC LIMIT 10 """) db.close() ``` ## Related - Live example of a site powered by the engine: https://www.ipltracker.com - Cricsheet (data source): https://cricsheet.org - DuckDB (storage engine): https://duckdb.org