Unofficial StatFin (Tilastokeskus) SDK for querying the Statistics Finland PxWeb API.
ESM only. Requires Node 18+ (built-in fetch).
- Developer friendly API for StatFin PxWeb data
- Simple, typed query building for JSON-stat2
- Return a flat row array with labels so developers can programmatically work with the data more easily
npm install statfin-sdk
# or
pnpm add statfin-sdk
# or
yarn add statfin-sdkimport { buildJsonQuery, queryStatFin } from "statfin-sdk";
const url =
"https://pxdata.stat.fi:443/PxWeb/api/v1/fi/StatFin/vaerak/statfin_vaerak_pxt_11re.px";
const jsonQuery = buildJsonQuery([
{ code: "Vuosi", selection: { filter: "item", values: ["2023"] } },
{ code: "Alue", selection: { filter: "item", values: ["SSS"] } },
{ code: "Tiedot", selection: { filter: "item", values: ["vaesto"] } },
]);
const rows = await queryStatFin(url, jsonQuery);
console.log(rows[0]);queryStatFin returns an array of rows. Each row contains:
- One key per dimension (e.g.
Vuosi,Tiedot) - A label field for each dimension (e.g.
Vuosi_label) valuefor the numeric value
If you copied the JSON query from the PxWeb UI, pass it directly:
const rows = await queryStatFin(url, jsonQueryStringFromUi);When the Cache API is available (browsers, service workers), queryStatFin
caches successful responses in a cache named statfin-sdk. The cache key is
derived from the request URL and JSON body so repeated queries return the cached
data.
To clear the cache:
await caches.delete("statfin-sdk");Node.js does not expose the Cache API, so caching is skipped in Node runtimes.
Use the StatFin PxWeb UI and copy the URL + JSON query from "Make this table available in your application".