Skip to content

API Reference

Client

cbspy.client.Client

CBS Statline open data client.

Parameters:

Name Type Description Default
base_url str

CBS OData API base URL. Override for testing.

_DEFAULT_BASE_URL
http_client Client | None

Custom httpx.Client instance. Created automatically if not provided.

None

list_tables(language=None)

List available CBS tables.

Parameters:

Name Type Description Default
language str | None

Filter by language ("en" or "nl"). Returns all if None.

None

Returns:

Type Description
DataFrame

Polars DataFrame with columns: id, title, description, period,

DataFrame

frequency, record_count, modified.

get_metadata(table_id)

Get metadata and column definitions for a CBS table.

Parameters:

Name Type Description Default
table_id str

CBS table identifier (e.g. "37296eng").

required

Returns:

Type Description
TableMetadata

TableMetadata with column properties.

get_data(table_id, periods=None)

Fetch dataset as a Polars DataFrame with human-readable column names.

Parameters:

Name Type Description Default
table_id str

CBS table identifier (e.g. "37296eng").

required
periods list[str] | None

Optional list of CBS period codes to filter by.

None

Returns:

Type Description
DataFrame

Polars DataFrame with resolved column names and decoded periods.

Data Models

Column

cbspy.models.Column

Bases: BaseModel

A column (property) in a CBS dataset.

display_name property

Return English name if available, otherwise Dutch.

TableMetadata

cbspy.models.TableMetadata

Bases: BaseModel

Metadata for a CBS dataset table.

Exceptions

cbspy.exceptions.CBSError

Bases: Exception

Base exception for cbspy.

cbspy.exceptions.TableNotFoundError

Bases: CBSError

Raised when a CBS table ID does not exist.

Use client.list_tables() to discover available tables.

cbspy.exceptions.APIError

Bases: CBSError

Raised when the CBS API returns an error response.