Skip to contents

pixieweb is an R client for PX-Web statistical APIs. It provides a pipe-friendly, tibble-based interface for discovering, inspecting and downloading data from national statistics agencies — including SCB (Sweden), SSB (Norway), Statistics Finland, and more.

To learn more about using pixieweb, it is recommended you use the following resources in order:

Getting started with pixieweb

  1. To get up and running quickly with pixieweb, please see the vignette A quick start guide to pixieweb.
  2. For an introduction to pixieweb and the design principles of functions included, please see Introduction to pixieweb.
  3. For cross-country comparisons and multi-API workflows, see Working with multiple APIs.
  4. See the Reference section of the package homepage to learn about the full set of functionality included with the package.

pixieweb is open source licensed under the Affero Gnu Public License version 3. This means you are free to download the source, modify and redistribute it as you please, but any copies or modifications must retain the original license. Please see the file LICENSE.md for further information.

Note on pxweb: The excellent pxweb package by rOpenGov already provides comprehensive R access to PX-Web APIs. pixieweb is not a replacement — it offers an alternative paradigm built around search-then-fetch discovery and progressive disclosure. If you already use pxweb and it works for you, there is no need to switch. Choose the workflow that fits your needs.

Installation

pixieweb is on CRAN. To install it, run the following code in R:

install.packages("pixieweb")

To install the latest development version from GitHub, use the remotes package:

library("remotes")
remotes::install_github("LCHansson/pixieweb")

Quick start

library(pixieweb)

# Connect to Statistics Sweden
scb <- px_api("scb", lang = "en")

# Search for tables about population
tables <- get_tables(scb, query = "population")

# Inspect variables in a table
vars <- get_variables(scb, tables$id[1])

# Download data
data <- get_data(scb, tables$id[1])

Features

  • Search-then-fetch workflow: Discover tables, inspect variables, then download data
  • Multiple APIs: Built-in catalogue of Nordic and European statistical agencies
  • Selection helpers: px_all(), px_top(), px_bottom(), px_from(), px_to(), px_range() for concise variable selections
  • Automatic chunking: Large queries are split and rate-limited automatically
  • Persistent caching: Cache responses to disk with pixieweb_cache_dir()
  • v1 and v2 support: Works with both PX-Web API versions

Enhanced caching with nordstatExtras

For multi-user web applications or workflows that benefit from a shared, persistent cache, pixieweb integrates with the nordstatExtras package. When installed, get_data(), get_tables(), table_enrich(), and other functions can write to a shared SQLite file instead of per-session .rds files:

# install.packages("devtools")
devtools::install_github("LCHansson/nordstatExtras")

library(nordstatExtras)
handle <- nxt_open("cache.sqlite")

scb <- px_api("scb")

# Metadata and data cached in the same SQLite file
tables <- get_tables(scb, cache = TRUE, cache_location = handle)
data <- get_data(scb, "TAB638",
  Region = c("0180", "1480"),
  cache = TRUE, cache_location = handle
)

# table_enrich with per-table caching + async support
enriched <- table_enrich(tables, cache = TRUE,
                         cache_location = handle)

nxt_close(handle)

Features include cell-level deduplication across overlapping queries, per-table incremental enrichment with resume-on-crash, async background fetching via mirai, and FTS5-powered typeahead search via nxt_search(). See the nordstatExtras README for details.

Contributing

You are welcome to contribute to the further development of the pixieweb package in any of the following ways:

  • Open an issue
  • Clone this repo, make modifications and create a pull request
  • Spread the word!

pixieweb is part of a family of R packages for Swedish and Nordic open statistics that share the same design philosophy — tibble-based, pipe-friendly, and offline-safe:

  • rKolada — R client for the Kolada database of Swedish municipal and regional Key Performance Indicators
  • rTrafa — R client for the Trafa API of Swedish transport statistics

See also pxweb — the original and established PX-Web client for R, by rOpenGov.

Code of Conduct

Please note that the pixieweb project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

AGPL (>= 3)