PitchAPI Source Research
Status: implemented in pkg/source/pitchapi, with supported-source docs at docs/supported-sources/pitchapi.md. The REST tables and the Data plan's bulk export tables live in the same package.
Primary docs:
- Documentation: https://pitchapi.dev/docs
- OpenAPI 3.1 document: https://pitchapi.dev/openapi.json
- Pricing and limits: https://pitchapi.dev/pricing
Connection
| Item | Value |
|---|---|
| Base URL | https://api.pitchapi.dev/v1 |
| Auth | X-API-KEY: pk_live_... request header (not Authorization) |
| Response envelope | {"data": ...} on success, {"error":{"code","message"}} on failure |
| Pagination | None server-side: the cursor is a date, a league-season, or a match id |
| IDs | Opaque strings with prefixes m_, t_, p_, l_, s_ (ex_ for export jobs); never cast to integers |
Every response is the same envelope, so unwrapping is uniform — but the member inside data is not: data.leagues for the catalogue, data.matches for a date or a league-season, and objects or arrays for the per-match endpoints.
Tier Map
| Plan | Price | Requests | Notes |
|---|---|---|---|
| Free | €0 | 15,000/day, 600/min, 60/min on /live | Every league and every endpoint. |
| Pro | €4.99/mo | No daily cap, 1,200/min, 600/min on /live | Outbound webhooks. |
| Data | €9.99/mo | Same as Pro | Bulk exports: NDJSON or Parquet, 25 jobs a day. |
The free plan is complete, which matters for how this source is described: nothing here is behind a plan except the _bulk tables, and those exist for volume, not access.
Main Table Coverage
| Main table | Coverage | Primary endpoint | Required tier | Paging |
|---|---|---|---|---|
| Leagues | Yes | GET /leagues | Free | One call, all 77. |
| Teams | Yes | GET /leagues/{id}/matches (team refs), or GET /teams/{id} | Free | Derived from the match lists: one request per league instead of one per team. |
| Players | Yes | GET /matches/{id}/players, then GET /players/{id} | Free | Per match, deduplicated across the run. |
| Matches | Yes | GET /date/{date} or GET /leagues/{id}/matches?season= | Free | Iterate dates, or one league-season. |
| Shots | Yes | GET /matches/{id}/shots | Free | Per match; nested under data.periods[].shots. |
| Events | Yes | GET /matches/{id}/events | Free | Per match; data.events. |
| Lineups | Yes | GET /matches/{id}/lineups | Free | Per match; one object per team, starters and subs as arrays. |
| Player stats | Yes | GET /matches/{id}/players | Free | Per match; data is the array itself. |
| Match stats | Yes | GET /matches/{id}/stats | Free | Per match; periods, groups and items. |
| Bulk exports | Yes | POST /v1/exports | Data | One job per read, then a Parquet file. |
Endpoint Map
Discovery
GET /leagues → data.leagues[] with id, name, country_code, image_url, seasons and is_free.
GET /date/{YYYY-MM-DD}?status=played|upcoming|all → data.matches[] with id, league, home_team, away_team, time_utc, status, score_home, score_away. This is the cheapest discovery call and the one the date-range mode uses.
GET /leagues/{id}/matches?season=2025/2026&status=all → data.matches[], a summary list that also carries date. Seasonless calls default to the latest season the league has data for; a league with no data answers 400 INVALID_PARAMETER.
Per-match endpoints
All of these take an m_ id and take no query parameters.
GET /matches/{id}/shots → data.periods[].shots[]
GET /matches/{id}/events → data.events[]
GET /matches/{id}/lineups → data.home / data.away
GET /matches/{id}/players → data[] (an array, not an object)
GET /matches/{id}/stats → data.periods[].groups[].items[]A match that was never rated, or simply has nothing stored for that table, answers 404 RESOURCE_NOT_FOUND; 404 ANALYTICS_UNAVAILABLE is specific to the advanced endpoints. Both are permanent and must not be retried.
Bulk exports
POST /v1/exports with {"dataset","format","league?","season?","from?","to?"} → 202 and data.job. Poll GET /v1/exports/{id} until status is ready, then take data.download_url (a signed URL valid for 15 minutes). DELETE /v1/exports/{id} frees the object.
Datasets: matches, shots, events, lineups, player_stats, match_stats, teams, players. The last two are not match-scoped and refuse a filter with 400 INVALID_PARAMETER.
Backfill Strategy
REST for incremental reads — a date range, or one league-season. For a full history, the export API is the only realistic path: 77 leagues of shots is roughly 150k matches, one request each on REST, which is ten days of the entire free allowance before the match lists are counted. One export job replaces all of it with a single file.
# Data plan: queue an export, then read the Parquet straight into DuckDB
curl -X POST https://api.pitchapi.dev/v1/exports \
-H "X-API-KEY: $PITCHAPI_KEY" -H 'Content-Type: application/json' \
-d '{"dataset":"shots","format":"parquet","season":"2025/2026"}'
duckdb pitch.duckdb -c "CREATE TABLE shots AS SELECT * FROM read_parquet('signed-url.parquet')"Response Notes
- Nested objects (
league,home_team,away_team,player) stay objects; the connector liftsidto its own column and keeps the object as JSON, which is what the other football sources in this repo do. 429 DAILY_QUOTA_EXCEEDEDand429 RATE_LIMIT_EXCEEDEDcarryRetry-Afterin seconds.403 PLAN_UPGRADE_REQUIREDmeans the resource needs a paid plan;403 SUBSCRIPTION_SUSPENDEDmeans the account's payment failed beyond the grace window.429 EXPORT_QUOTA_EXCEEDEDis the 25-job daily allowance, resetting at 00:00 UTC.503 EXPORTS_UNAVAILABLEmeans the deployment does not sell exports at all, which is a permanent answer, not a transient one.GET /date/{date}is edge-cached for settled dates, so a backfill by date is cheaper than it looks on the rate-limit arithmetic.
Implementation Notes
- Strategies:
replacefor the whole-table reads (leagues,teams, the_bulktables);delete+insertondateforshots,eventsandmatch_stats, so a corrected or removed row does not linger;mergeformatches,players,lineupsandplayer_stats. Use one destination table perleague/season. match_statskeys ongroup_nameas well: the "Top stats" group repeats keys from the other groups.playersismergerather thanreplacebecause its rows are derived from the matches in the window: replacing would keep only those players and drop the rest of the catalogue.- The rate limiter paces at 8 requests a second (Free allows 600/min, about 10/s), and a
429is retried twice with theRetry-Afterthe API sends. - Bulk reads download the Parquet to a temporary file and stream it through
pqarrow, so a 2 GiB export never sits in memory.