Get started

pxwebpy is a Python client for the PxWeb API. The goal is to make it easier to get data from the API and into a dataframe. It is BYODF* so that you can use what DataFrame library you prefer, be it polars, pandas or a pyarrow table.

* = Bring your own dataframe

Installation

The package is on PyPI and the easiest way to install it into your environment is:

pip install pxwebpy

Or by using uv:

uv add pxwebpy

Usage

from pxweb import PxApi
import polars as pl

api = PxApi("scb")

# Swedish population per year
data = api.get_table_data(
    table_id="TAB5890",
    value_codes={"Tid": ["2022", "2023", "2024"], "ContentsCode": "0000053A"},
)

pl.DataFrame(data)
shape: (3, 3)
tabellinnehåll år value
str str i64
"Antal" "2022" 10521556
"Antal" "2023" 10551707
"Antal" "2024" 10587710

Have a look at the Examples or see the Reference for more details.