Skip to main content

Client library for the PxWeb API to easily load data into a DataFrame.

Project description

pxwebpy

GitHub Actions Workflow Status PyPI - Version PyPI - Python Version uv ruff
Client library for the PxWeb API to easily load data into a DataFrame.

Get started | Examples | Reference

Features

  • Automatic query batching to handle large queries to respect rate limits
  • Multithreading for faster data fetching on large queries
  • In-memory caching for quicker iterative use and exploration
  • Wildcard support in queries
  • BYODF (Bring Your Own DataFrame): native return formats for use with pandas or polars
  • Search for tables, browse and list tables, get metadata, and more

It has been tested with Statistics Sweden and Statistics Norway.

[!NOTE]
pxwebpy only supports version 2.0 of the PxWeb API.

Quick start

from pxweb import PxApi
import polars as pl

# Prepare to get data from the Statistics Norway API by using the builtin URL
api = PxApi("ssb")

# Set the language to english
api.language = "en"

# Check the population per year in Norway during the 1990's
data = api.get_table_data(
    "06913",
    value_codes={"Region": "0", "ContentsCode": "Folkemengde", "Tid": "199*"},
)

# Turn it into a polars dataframe
df = pl.DataFrame(data)

# A quick look at the result
print(df)
shape: (10, 4)
┌─────────────────────┬──────────────────────┬──────┬─────────┐
│ region              ┆ contents             ┆ year ┆ value   │
│ ---                 ┆ ---                  ┆ ---  ┆ ---     │
│ str                 ┆ str                  ┆ str  ┆ i64     │
╞═════════════════════╪══════════════════════╪══════╪═════════╡
│ 0 The whole country ┆ Population 1 January ┆ 1990 ┆ 4233116 │
│ 0 The whole country ┆ Population 1 January ┆ 1991 ┆ 4249830 │
│ 0 The whole country ┆ Population 1 January ┆ 1992 ┆ 4273634 │
│ 0 The whole country ┆ Population 1 January ┆ 1993 ┆ 4299167 │
│ 0 The whole country ┆ Population 1 January ┆ 1994 ┆ 4324815 │
│ 0 The whole country ┆ Population 1 January ┆ 1995 ┆ 4348410 │
│ 0 The whole country ┆ Population 1 January ┆ 1996 ┆ 4369957 │
│ 0 The whole country ┆ Population 1 January ┆ 1997 ┆ 4392714 │
│ 0 The whole country ┆ Population 1 January ┆ 1998 ┆ 4417599 │
│ 0 The whole country ┆ Population 1 January ┆ 1999 ┆ 4445329 │
└─────────────────────┴──────────────────────┴──────┴─────────┘

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pxwebpy-0.5.5.tar.gz (153.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pxwebpy-0.5.5-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file pxwebpy-0.5.5.tar.gz.

File metadata

  • Download URL: pxwebpy-0.5.5.tar.gz
  • Upload date:
  • Size: 153.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pxwebpy-0.5.5.tar.gz
Algorithm Hash digest
SHA256 ecceb8a5deea3d84f6b50f55c5ee8319d9a294e61a7d9ed496bf154742fa313e
MD5 1b87ae28f62ba6919deedfa281f22e10
BLAKE2b-256 a95d8d55502427b6fc3faaf56acc61ff4b99472cf1a31143b7ca626fbff3aa40

See more details on using hashes here.

File details

Details for the file pxwebpy-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: pxwebpy-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pxwebpy-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 492364f81d532f2f436a142fc009e97a50a5ff87077fd2a1023798323fa8a0e9
MD5 631c6c1aa1da2d83f28bd10224a3f48a
BLAKE2b-256 01f8bbc7ff9c06dbd07f3d14f0a81548f4eed55d256cab4ffac3f80e126fb17e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page