PxWebApi 1.0 for the Statistical Database

In the fall of 2025, PxWebApi 1.0 will be replaced by PxWebApi 2.0.

Redan idag finns det en betaversion av PxWebApi 2.0. 

Via PxWebAPI 1.0 får du tillgång till valfri tabell eller del av tabell från Statistikdatabasen. Du hittar också exempel på användning samt vanliga frågor om API (Application Programming Interface).

Statistikdatabasens gränssnitt ligger i PxWeb där PxAPI 1.0 är en del. Du kan använda API:et utan att du registrerar dig. 

Source code

 https://github.com/statisticssweden/PxWeb 

API ikon

Please note! On October 26, 2022, we introduced mandatory https for the API. If you get metadata instead of data in the table, it is because http is rerouting the call to GET. You can fix this by redirecting your calls to https instead of http.

Guide

How to use the API (pdf)

Examples

Show all subject area in English in the Statistical Database:

Show all sub-levels for the subject area Population:

Show the metadata for the table:

Download Sweden's population for the years 2011 and 2012. Make an http POST request to:

and as data, the JSON request is used below

{  
"query": [
 {       
 "code": "ContentsCode",
  "selection": {        
    "filter": "item",         
    "values": [          
      "BE0101N1"         
    ]      
   }    
},    
{      
  "code": "Tid",
   "selection": {        
   "filter": "item",         
   "values": [           
   "2010",          
   "2011"         
   ]      
  }    
 }   
],  
"response": {    
  "format": "json"   
 }
}

You can now get help to formulate questions to the Statistical Database API. Make your data retrieval in the Statistical Database user interface. On the page that shows the table, click on the API link for this table. This will give you information about the URL and the query that you need to send to retrieve the same data with the API.

JSON-bild

For Python developers

One of the users of the Statistical Database has developed a module with an example code for Python Developers. The code is available on GitHub.

How to use Python for data from the Statistical Database (Github)

For R developers

One of the users of the Statistical Database has developed a module with an example code for Python Developers. The code is available on GitHub.
How to fetch data from the Statistical Database in R 

Contact

Statistics Service

Telephone
+46 10 479 50 00
Opening hours
Weekdays
9:00–12:00, 13:00–16:00