PxWeb API Help
- lokakuu 2024 1 (10)
Statistics Finland's PxWeb API Help
Through Statistics Finland's PxWeb API interface for statistical databases you can search for
machine readable information in, for example, XLSX, CSV, JSON, JSON-stat, JSON-stat2 and PX
formats.
Before using the service, you should take a look at Statistics Sweden’s (SCB) API documentation
(pdf).
NB. SCB’s description is based on the use of a relational database where you do not have to use a
PX extension in the table name. By contrast, in Statistics Finland's databases you must always
remember to use the PX extension in the table name.
API limitations can be seen in this link https://pxdata.stat.fi/PXWeb/api/v1/en/?config
API’s structure
In the newest PxWeb version you can see the structure of the database:
https://pxdata.stat.fi/pxweb/api/v1/en/StatFin/?query=&filter=
API’s structure
PXWEB/API-NAME/API-VERSION/LANGUAGE/DATABASE-ID/LEVELS/TABLE-ID
Available
databases
https://pxdata.stat.fi/PXWeb/api/v1/en/
List of tables
https://pxdata.stat.fi/PXWeb/api/v1/fi/StatFin/vaerak
Table metadata
https://pxdata.stat.fi/PXWeb/api/v1/fi/StatFin/vaerak/statfin_vaerak_pxt_11re.px
Now a short version of both GET and POST requests can be used:
https://pxdata.stat.fi/PXWeb/api/v1/fi/StatFin/statfin_vaerak_pxt_11re.px
PxWeb API Help
- lokakuu 2024 2 (10)
PxWeb API
Example:
- First select the desired table from Statistics Finland's StatFin database.
In this example, a table describing the population by age and sex is selected from the
Population structure statistics: 11re - Population according to age (1-year) and sex by area, 1972-2023
PxWeb API Help
-
lokakuu 2024 3 (10)
-
Next, select the desired variables and click "Continue".
In this table, only the Year variable marked with a red asterisk (*) is mandatory. Only select 2023 as at this stage you only need the data form the API interface.
PxWeb API Help
-
lokakuu 2024 4 (10)
-
After the selection you see the table depicted below. Next, select the API query for this table tab which displays table information.
-
Here you find the necessary API interface data. You can use the JSON POST query to retrieve data and the GET query to retrieve the metadata of the table. These provide a machine-readable link to the database table.
PxWeb API Help
- lokakuu 2024 5 (10)
Using PxWeb API with RESTClient
The supported formats are: PX, CSV, JSON, XLXS JSON-stat and JSON-stat2.
The URL address together with the GET function gives the metadata of the selected PX table. The
metadata are also shown when the URL address is typed into the address field of the browser.
When retrieving the information with the GET function of the URL command
https://pxdata.stat.fi/PXWeb/api/v1/en/StatFin we find out that the database has on 146 root nodes.
The URL command GET https://pxdata.stat.fi/PXWeb/api/v1/fi/StatFin/altp hows that the database
has 6 table nodes.
Next page is an image of the POST query result together with the URL command and JSON query
code shown in the example
(https://pxdata.stat.fi:443/PxWeb/api/v1/en/StatFin/vaerak/statfin_vaerak_pxt_11re.px):
{ "query": [ { "code": "Vuosi", "selection": { "filter": "item", "values": [ "2023" ] } } ], "response": { "format": "json" } }
PxWeb API Help
- lokakuu 2024 6 (10)
If we want POST query result shown on CSV so there is the result:
PxWeb API Help
- lokakuu 2024 7 (10)
When you remove the time variable from the JSON query code you can see all periods and their values. The image below now shows the table describing the index point figures:
{
"query": [ ],
"response": {
“format": "csv”
}
}
PxWeb API Help
- lokakuu 2024 8 (10)
Using filters
Filters can be used to search only for defined values.
• Item. The filter lists valid variable values. There can be one or several filtered values, for
example, years “2015” and “2016”.
• All. This filter uses the wildcard feature but only one of these can be used at a time. For
example, 01* shows all values that begin with 01, * shows all values.
• Top. Shows the first values or the latest values if the variable is time-based. The number of
values to be shown is entered in the value field, for example, “5” which would show the five
first or latest values.
Examples:
Population for 2023
If the figures “1980” and “1988” are added to the time variable, the population for 1980 and 1988 are shown in addition to that for 2023.
{
"code": "Vuosi",
"selection": {
"filter": "item",
"values": [
"2023"
]
}
}
{
"code": "Vuosi",
"selection": {
"filter": "item",
“values": [
"2023", “1980”, “1988”
]
}
}
PxWeb API Help
- lokakuu 2024 9 (10)
Select all Vuosi (year) variables that end in zero, i.e. Show the populations for 1970, 1980, 1990, 2000, 2010 and 2020. Set the value of the Ikä (age) variable as “010” so only persons aged 10 are shown for the selected years.
Shows the population of the past three years: 2023, 2022 and 2021. For time-based variables, the newest values are shown first.
This example shows the number of women (sukupuoli = gender) in the last five years.
{
"code": "Vuosi",
"selection": {
"filter": "all",
"values": [
"*0"
]
}
},
{
"code": "Ikä",
"selection": {
"filter": "item",
"values": [
"010"
]
}
}
{
"code": "Vuosi",
"selection": {
"filter": "top",
"values": [
"3"
]
}
}
{
"code": "Vuosi",
"selection": {
"filter": "top",
"values": [
"5"
]
}
},
{
"code": "Sukupuoli",
"selection": {
"filter": "item",
"values": [
"2"
]
}
}
PxWeb API Help
- lokakuu 2024 10 (10)
You can also use a free text search with URL commands through the API interface. For example:
- Search “population” https://pxdata.stat.fi/PXWeb/api/v1/en/StatFin?query=population
- Searches for data related to the population in the “vaerak” topic https://pxdata.stat.fi/PXWeb/api/v1/en/StatFin/vaerak?query=population
Technical support:
Further information is available by contacting [email protected].