Skip to content

Repository files navigation

cbspy

Release Build status codecov License

A modern Python client for CBS Statline open data that returns Polars DataFrames with human-readable column names.

Installation

pip install cbspy

Quick Start

import cbspy

client = cbspy.Client()

# Discover available tables
tables = client.list_tables(language="en")
print(tables.head())
# shape: (5, 7)
# id, title, description, period, frequency, record_count, modified

# Inspect a table's structure
meta = client.get_metadata("37296eng")
for col in meta.properties:
    print(f"{col.id}: {col.display_name} ({col.unit})")

# Fetch data with human-readable column names
df = client.get_data("37296eng")
print(df.head())
# Columns like "Total population", "Males", "Females" instead of
# "TotalPopulation_1", "Males_2", "Females_3"

# Filter by time period
df = client.get_data("37296eng", periods=["2022JJ00", "2023JJ00"])

Development

make install    # Create venv and install pre-commit hooks
make test       # Run tests with coverage
make check      # Run linting and type checking

Repository initiated with fpgmaas/cookiecutter-uv.

Releases

Packages

Contributors

Languages