Norsk - for English see below
Statistisk sentralbyrå (SSB) tilbyr to API-er for å hente ut og integrere SSBs data med egne systemer. API-ene er åpne og krever ikke registrering:
API for å poste spørringer i JSON mot alle Statistikkbankens 7000 tabeller (PxWebApi): Dette API-et lar deg sende spørringer i JSON-format mot alle tabeller i Statistikkbanken.
SSB kom i oktober 2025 med en versjon 2 av PxWebApi. Dette tilbyr http GET, som gjør det lettere å integrere i egne systemer Se egen README for hva som er nytt og eksempler som benytter versjon 2.
- REST API for statistiske klassifikasjoner og kodelister: Dette API-et gir deg tilgang til statistiske klassifikasjoner og kodelister (Klass).
Det kommer fortsatt mer metadata i JSON-stat2. Det gjelder både versjon 1 og 2 av APIet. Noen av eksemplene under er oppdatert, bl.a. for å vise dette. Flere oppdateringer vil komme.
Forøvrig er R-pakken PxWebApiData oppdatert til versjon 1.1 i oktober 2025. Den håndterer også v2 GET URL-er.
Eksemplene under bruker Python Pandas.
JSON-stat eksempler for å poste spørringer mot PxWebApi v1
-
apidata - dapla-statbank-client er en python pakke laget av SSB og gjør det enkelt å hente JSON-stat2 datasett via PxWebApi.
-
Laks - Post spørring og få Pandas dataframe i retur
-
JsonStatToPandas - To funksjoner for å poste JSON spørring og få Pandas dataframe i retur
-
komm-nr-id - Hvordan vise både kommunenummer/-kode og kommunenavn i en dataframe, dvs. vise kode og tekst i JSON-stat
-
Kombiner to tabeller - Spørre mot to ulike Statstikkbank-tabeller og vise resultatet i en figur med Pandas pivot og Matplotlib.
-
Konkurs-datokonv - Funksjon for å konvertere Tid fra kategori til datoformat. Viser forskjellen i to figurer med ukentlige konkurser.
-
Nasjonalregnskap-datokonvertering - Viser samme spørring mot tabeller med ulik frakvense, her BNP-endring i månedlig, kvartalsvis og årlig nasjonalregnskap. Viser dateconv() som konverterer fra kategori til dataoformat og setter Pandas Period.
-
text-code - Få Kode og Tekst i JSON-stat - eksempel med HS-varekoder i månedlig Utenrikshandel
- Klasskommune - Standard for kommuneinndeling til Pandas.
- KOSTRA-koder - KOSTRA koder for regnskapsarter og -funksjoner. Hvordan hente og filtrere KOSTRA arter og funksjoner med definisjoner via Klass API (KOSTRA - Municipality-State-Reporting)
R-bruker?
Bruk SSBs R-pakke PxWebApiData og se denne Introduksjonen.
Tips: Har du problem med æøå når du henter data fra API, prøv setlocale i R til no_NO.UTF8
Statistics Norway offers three APIs that allow you to retrieve and integrate SSB's data with your own systems. These APIs are open and do not require registration. Here is a brief overview of the three APIs:
- API for posting queries in JSON to all of Statbank Norway's 7000 tables (PxWebApi): This API allows you to send queries in JSON format to all of Statistikkbanken's tables.
- API for ready-made datasets: This API provides access to 200 datasets with fixed URLs. This API will be discontinued.
- REST API for statistical classifications and code lists: This API provides access to statistical classifications and code lists.
In October 2025 Statistics Norway released a version 2 of the PxWebApi. This API supports http GET URLs. See README
Examples using CSV from the API for Readymade datasets
- Economic trends Import a readymade CSV dataset, Main Economic Forecasts, to Pandas. Shows basic plots using Pandas plot and Plotly Express.
Examples using http POST to query PxWebApi
All examples are using JSON-stat output and the library pyjstat
-
apidata - dapla-statbank-client is a package made by Statistics Norway and makes it easier to get JSON-stat2 datasets.
-
basic - a basic example on using http POST to query PxWebApi.
-
jsonstatToPandas_function - General function to read JSON-stat to Pandas dataframes
-
two-tables-one-chart - http POST example, combines two datasets from two Statbank tables using Pandas pivot, and plot them using Matplotlib.
-
bankrupties - shows the use of a general function for converting the time variable from category to date, and the difference of the two in two plots. The table used is on weekly bankruptcies.
-
gdp-dateconv - shows posting of the same query for GDP changes to tables with different frequency, and the use of the function dateconv() which converts from Categories to dateformat and set a Pandas PeriodIndex.
-
text-code - shows how to get both text and code from JSON-stat. Example using HS-code from monthly Foreign trade by country.
Example on Statistics Norway's Statistical Classifications and Codelists API
- Klasskommune get municipality names and codes.
Using R ? Try Statistics Norway's R-package PxWebApiData and see Introduction which is now in version 1.1.