Revenue per pupil for every district in Delaware

List the measure keys in a record, select Delaware’s exact revenue-per-pupil key, and preserve missing values.

List the measure keys in a record, select Delaware’s exact revenue-per-pupil key, and preserve missing values.

What you will produce: One JSON row per district with a published DDOE revenue-per-pupil figure, period, unit, source, and locator.

1. Confirm that Delaware is published

Start with the API index. Delaware’s committed artifacts have an exact revenue-per-pupil series, but no exact spending-per-pupil series, so this guide does not relabel revenue as spending.

curl

curl --fail --silent --show-error \
  https://www.districtfacts.com/data/v1/index.json

curl

const response = await fetch("https://www.districtfacts.com/data/v1/index.json");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
interface ApiIndex {
  api_version: string;
  states: Array<{ state: string; name: string; api_url: string }>;
}

const index = (await response.json()) as ApiIndex;
console.log(index.states.length, "published states");

JavaScript

const response = await fetch("https://www.districtfacts.com/data/v1/index.json");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
console.log(data);

Python

import json
from urllib.request import Request, urlopen

request = Request("https://www.districtfacts.com/data/v1/index.json")
with urlopen(request, timeout=30) as response:
    data = json.load(response)
print(json.dumps(data, indent=2))

Sample output

Relevant response
{ "state": "de", "districts": 43, "api_url": "/data/v1/de/districts.json" }

2. List the keys available in a record

Measure keys follow the official files available in each jurisdiction. List keys and labels before choosing a series in another state.

curl

curl -sS https://www.districtfacts.com/data/v1/de/districts/capital-school-district.json | jq '[.measures[] | {key, label}] | unique_by(.key)'

JavaScript

const district = await fetch("https://www.districtfacts.com/data/v1/de/districts/capital-school-district.json").then(response => response.json());
const available = [...new Map(district.measures.map(measure => [measure.key, measure.label])).entries()];
console.log(available);

Python

import json
from urllib.request import urlopen
with urlopen("https://www.districtfacts.com/data/v1/de/districts/capital-school-district.json") as response: district = json.load(response)
available = {measure["key"]: measure["label"] for measure in district["measures"]}
print(json.dumps(available, indent=2))

Sample output

Excerpt
{ "edstats_revenue_per_pupil": "Revenue per pupil (DDOE)" }

3. Select the exact published key

Fetch each directory record, match `edstats_revenue_per_pupil` exactly, and choose its newest published period.

curl

base=https://www.districtfacts.com
curl -sS "$base/data/v1/de/districts.json" | jq -r '.[].api_url' | while read -r path; do curl -sS "$base$path"; echo; done | jq -s '[.[] | . as $d | [.measures[] | select(.status == "published" and .key == "edstats_revenue_per_pupil")] | sort_by(.period) | last | select(. != null) | {district: $d.name, period, value, unit, source_id, locator}]'

JavaScript

const base = "https://www.districtfacts.com";
const directory = await fetch(base + "/data/v1/de/districts.json").then(response => response.json());
const rows = [];
for (const item of directory) {
  const record = await fetch(base + item.api_url).then(response => response.json());
  const matches = record.measures.filter(measure => measure.status === "published" && measure.key === "edstats_revenue_per_pupil").sort((a, b) => a.period.localeCompare(b.period));
  const measure = matches.at(-1);
  if (measure) rows.push({ district: record.name, period: measure.period, value: measure.value, unit: measure.unit, source_id: measure.source_id, locator: measure.locator });
}
console.log(rows);

Python

import json
from urllib.request import urlopen
base = "https://www.districtfacts.com"
with urlopen(base + "/data/v1/de/districts.json") as response: directory = json.load(response)
rows = []
for item in directory:
    with urlopen(base + item["api_url"]) as response: record = json.load(response)
    matches = sorted((m for m in record["measures"] if m["status"] == "published" and m["key"] == "edstats_revenue_per_pupil"), key=lambda m: m["period"])
    if matches:
        m = matches[-1]
        rows.append({"district": record["name"], **{key: m[key] for key in ("period", "value", "unit", "source_id", "locator")}})
print(json.dumps(rows, indent=2))

Sample output

Committed Capital artifact excerpt
{ "district": "Capital School District", "period": "2024-2025", "value": 2592280, "unit": "cents per pupil", "source_id": "de-edstats-fy25" }

4. Report unavailable records

Do not turn an absent or withheld measure into zero. Compare the number of produced rows with the directory length.

curl

printf 'Directory records: '; curl -sS https://www.districtfacts.com/data/v1/de/districts.json | jq 'length'
# Compare that number with the output row count from step 3.

JavaScript

console.log({ directoryCount: directory.length, publishedCount: rows.length, unavailable: directory.length - rows.length });

Python

print({"directory_count": len(directory), "published_count": len(rows), "unavailable": len(directory) - len(rows)})

Sample output

Example output shape
{ "directoryCount": 43, "publishedCount": 43, "unavailable": 0 }

Counts can change in a later release. A withheld or absent measure is not zero.

Developer documentation