Football data in DuckDB
DuckDB is the shortest path from a football API to a table you can query: one file, no server, and it reads Parquet over HTTPS without downloading it first. Which of the three routes below fits depends only on how much history you need.
Why DuckDB at all
A CSV in pandas and a table in Postgres both work, and both make you think about types, memory and a server before you have asked a single question. DuckDB is an in-process columnar engine: a `.duckdb` file is the whole database, `read_parquet` and `read_json_auto` read files and URLs directly, and a match archive that would not fit in a dataframe aggregates in a second.
It also reads the same Parquet our bulk exports are written in, which is why the third route below is a single statement rather than an ingestion script.
One date, right now
The cheapest discovery call is `GET /v1/date/{date}`: every match on that day, already carrying league and team ids. One request returns a `data.matches` array, and DuckDB can read the envelope without a parser — the `unnest` lifts the array into rows, and the struct fields follow.
Format the date as `YYYY-MM-DD`, pass `status=played` to skip fixtures, and keep the ids as strings. `m_`, `t_` and `l_` are opaque and are the keys everything else joins on; casting them to integers loses them.
curl -s "https://api.pitchapi.dev/v1/date/2026-11-29?status=played" \
-H "X-API-KEY: $PITCHAPI_KEY" > matches.json
duckdb pitch.duckdb -c "
CREATE OR REPLACE TABLE matches AS
WITH raw AS (
SELECT unnest(data.matches) AS m FROM read_json_auto('matches.json')
)
SELECT m.id AS match_id,
m.league.id AS league_id,
m.home_team.id AS home_team_id,
m.away_team.id AS away_team_id,
m.time_utc, m.status, m.score_home, m.score_away
FROM raw;"A season, one date at a time
There is no server-side pagination, so the cursor is the date. A season of one competition is a few hundred days of one request each; `GET /v1/leagues/{id}/matches?season=2025/2026` gets the whole competition in a single call when you want the fixture list with ids and scores rather than a day at a time.
Either way the requests are ordinary API calls and the plan's rate limit applies: 600 a minute and 15,000 a day on Free. A season is comfortable. Seventy-seven leagues across five seasons is not — the numbers run to hundreds of thousands of calls, which is weeks of the daily allowance. That is the point at which the export API exists.
# one competition, one season: the whole fixture list, with ids
curl -s "https://api.pitchapi.dev/v1/leagues/l_B8x2K9/matches?season=2025/2026" \
-H "X-API-KEY: $PITCHAPI_KEY" > league.json
# then per-match detail, one call per endpoint you need
for m in $(jq -r '.data.matches[].id' league.json); do
curl -s "https://api.pitchapi.dev/v1/matches/$m/shots" \
-H "X-API-KEY: $PITCHAPI_KEY" > "shots-$m.json"
doneThe whole archive: one export, one read_parquet
Bulk exports are part of the Data plan, €9.99/month. A job is a dataset plus optional filters, and it is built in the background: queue it, poll until the status is `ready`, and download the file from a signed URL valid for fifteen minutes. Twenty-five jobs a day, files kept for seven days.
Parquet is the format to ask for here. `read_parquet` reads the signed URL directly — no staging file, no copy — and the columns are typed, with NULLs preserved rather than flattened to zero.
# 1. queue an export (Data plan: €9.99/month)
curl -s -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"}'
# 2. poll until ready, then take data.download_url (valid 15 minutes)
curl -s https://api.pitchapi.dev/v1/exports/$JOB_ID \
-H "X-API-KEY: $PITCHAPI_KEY"
# 3. land it in DuckDB in one statement
duckdb pitch.duckdb -c "CREATE TABLE shots AS
SELECT * FROM read_parquet('https://…');"Joining the pieces
Inside an export, ids are integers, because that is what joins one dataset to another without a lookup: `shots.match_id` is `matches.id`. Each id-bearing dataset also carries the opaque token the API understands — `id_token` on `matches`, `teams` and `players` — so a row you found in a file can be turned back into a request.
One thing to keep straight: a rates column is NULL when it is undefined (a team that attempted no pass has no pass accuracy), not zero. `sum()` skips NULLs, `count(*)` does not, so pick the aggregate that matches the question.
-- xG per match, from the shot file alone
SELECT match_id, round(sum(expected_goals), 2) AS xg, count(*) AS shots
FROM shots
GROUP BY match_id ORDER BY xg DESC LIMIT 10;
-- the top matches, with the token to fetch them from the API
SELECT m.id_token, m.home_team_id, m.away_team_id,
sum(s.expected_goals) AS xg
FROM matches m JOIN shots s ON s.match_id = m.id
GROUP BY ALL ORDER BY xg DESC LIMIT 10;Which route to use
REST is right for today's matches, a live dashboard, or one competition-season: a handful of calls, fresh data, and no plan above Free. A full backfill is thousands of requests and hits the daily allowance long before it finishes; the export API replaces all of them with one queued file per dataset. Use the first for what changed, the second for what exists.
Keep reading
Read the number from the API
One key covers every competition and every endpoint, with 15,000 requests a day, no card, and the current season plus the one before it.