Skip to main content

pxweb-client

A small Python client for the v1 API of PxWeb, the publishing platform that many national statistics offices use for their databases. Use it to list tables, inspect their variables, and download data as plain records, ready for pandas, polars or anything else.

PxWeb API v2 is not supported yet.

Install

pip install pxweb-client

The import name is pxweb. Its only dependency is httpx.

Usage

Point the client at a server's API root (the URL up to /api/v1), a database and a language. The examples use SiStat, the database of the Statistical Office of Slovenia; for SiStat specifically, see sistat.

from pxweb import PxWebClient

with PxWebClient("https://pxweb.stat.si/SiStatData/api/v1", "Data", "en", user_agent="my-app/1.0") as px:
    px.tables()                       # tables and folders at the database root
    # [TableInfo(id='0156101S.px', text='Average annual and monthly air temperatures [°C] by ...', ...), ...]

    meta = px.metadata("0156101S.px")
    for v in meta.variables:
        print(v.code, "|", v.text, "|", v.value_texts[:3])
    # METEOROLOŠKA POSTAJA | METEOROLOGICAL STATION | ('SLOVENIA', 'Bilje', 'Bovec')
    # OBDOBJE, LETO | PERIOD, YEAR | ('1981-1990', '1991-2000', '2001-2010')
    # MERITVE | MEASURE | ('Average temperature - ANNUAL', 'January', 'February')

    records = px.get_records(
        "0156101S.px",
        {
            "METEOROLOGICAL STATION": ["Ljubljana, Bežigrad", "Maribor, Tabor"],
            "PERIOD, YEAR": "201*",
        },
    )
    # [{'METEOROLOGICAL STATION': 'Ljubljana, Bežigrad', 'PERIOD, YEAR': '2010',
    #   'MEASURE': 'Average temperature - ANNUAL', 'value': 10.7}, ...]

Pass your own user_agent so server operators can tell your application apart; the default is pxweb-python/<version>.

Selections

Keys are variables, given as their code or their label, case-insensitively. Values can be:

Selection Meaning
"Ljubljana, Bežigrad" or "10" one value, by label or code
["10", "Maribor, Tabor"] several values
"2020*", "*" glob pattern over codes and labels
"top:5" the first 5 values in the table's order

Matching ignores case and accents ("cas" matches "čas"); pxweb.fold exposes the same rule. Every variable you leave out is sent with all its values selected. PxWeb would otherwise drop it from the result without telling you.

Pass codes=True to also get a <variable>_code key with the raw value codes. Queries that exceed the server's cell limit are split into several requests and merged. Requests are kept under the server's rate limit (read from its ?config endpoint) automatically.

Errors and logging

Every error is a pxweb.PxWebError: APIError for error responses (with status_code) and failed requests, QueryError (also a ValueError) for selections that don't match the table. If the server's limits can't be read, a warning is logged to the pxweb logger and defaults are used.

Testing your code

pxweb.testing.FakePxWeb is an in-memory PxWeb v1 server for httpx.MockTransport. Give it a table listing and recorded metadata and json-stat2 responses; it answers queries by slicing them.

import httpx
from pxweb import PxWebClient
from pxweb.testing import FakePxWeb

fake = FakePxWeb("Data", tables=[...], metadata={"T.px": meta}, data={"T.px": dataset})
px = PxWebClient("https://example.test/api/v1", "Data", "en", transport=httpx.MockTransport(fake))

Development

uv sync
uv run pytest            # offline tests against recorded fixtures
uv run ruff check .
uv run mypy

The test fixtures are responses recorded from SiStat. Data © SURS, see their terms of use.

Metadata

Release files for pxweb-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pxweb-client 0.1.0
File Size Uploaded Provenance Actions
pxweb_client-0.1.0.tar.gz 17.6 kB With provenance Details for pxweb_client-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pxweb-client 0.1.0
File Interpreter ABI Platform Actions
pxweb_client-0.1.0-py3-none-any.whl Python 3 none any Details for pxweb_client-0.1.0-py3-none-any.whl

Total release size: 32.3 kB

Release files / pxweb_client-0.1.0.tar.gz

Download URL pxweb_client-0.1.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a41d939e5d68793e028581634381767f1d1f726ff3e01b723fd067964a42da0e
BLAKE2b-256 checksum
How to use checksums
b6bd0128f7d7bc91cce105b69260da65353c8aef07903c61150905f802121c33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pxweb_client-0.1.0-py3-none-any.whl

Download URL pxweb_client-0.1.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af9848a25f3c8537a8f8467dc0798e827c2534289079724b07f331c0f18685e6
BLAKE2b-256 checksum
How to use checksums
11077058c09a9b1b0e737873738845673687c55bf96c7bd34010733548709d90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pxweb-client 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pxweb_client-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page