imibare

The statistics East African governments publish, gathered into one register and kept exactly as they were published.

IMIBARE · DOCS · HOW-TO GUIDES

Query with DuckDB

Query the latest imibare data from DuckDB over HTTPS, with no Python package or credentials.

If you prefer SQL, DuckDB can read an imibare Parquet file directly from its download URL. This route needs no account, API key, or Python package from us.

Install DuckDB

Install the Python package if you will run DuckDB from Python. If you use the DuckDB command-line client or another binding, install DuckDB through that tool instead.

pip install duckdb

Query 1 dataset

The download URL is https://api.imibare.org/v1/data/{id}/download. Replace {id} with the dataset ID you want to query.

import duckdb

duckdb.sql("""
    SELECT *
    FROM read_parquet('https://api.imibare.org/v1/data/rw.nisr.cpi.monthly/download')
    ORDER BY date DESC
    LIMIT 10
""").show()

The endpoint returns the latest published Parquet version. Use the dataset page to check the source, columns, update history, and meaning of values before you write an analysis.

Reuse the URL in several queries

A small helper keeps long URLs out of your SQL. It also makes it harder to accidentally query 2 different dataset IDs while copying examples.

import duckdb

def data_url(dataset_id: str) -> str:
    return f"https://api.imibare.org/v1/data/{dataset_id}/download"

# The general CPI index, newest months first
duckdb.sql(f"""
    SELECT date, value
    FROM read_parquet('{data_url("rw.nisr.cpi.monthly")}')
    WHERE category = 'general_index_(cpi)'
    ORDER BY date DESC
    LIMIT 12
""").show()

# Annual average CPI by category
duckdb.sql(f"""
    SELECT
        date_trunc('year', date) AS year,
        category,
        AVG(value) AS average_cpi
    FROM read_parquet('{data_url("rw.nisr.cpi.monthly")}')
    GROUP BY 1, 2
    ORDER BY 1 DESC, 2
""").show()

# USD exchange rate in 2024
duckdb.sql(f"""
    SELECT date, rwf_per_unit
    FROM read_parquet('{data_url("rw.bnr.fx.daily")}')
    WHERE currency = 'USD'
      AND year(date) = 2024
    ORDER BY date
""").show()

Keep a local table

read_parquet() downloads a remote file for each query. If you plan to query the same dataset often, write it into a local DuckDB database once and refresh it when you need a new version.

connection = duckdb.connect("imibare.duckdb")
connection.sql(f"""
    CREATE OR REPLACE TABLE rw_cpi AS
    SELECT * FROM read_parquet('{data_url("rw.nisr.cpi.monthly")}')
""")

connection.sql("SELECT count(*) FROM rw_cpi").show()

Run the CREATE OR REPLACE statement again when you want the newest published data. Keep a note of the version and source you used if you need another person to reproduce the result later.

Return a pandas DataFrame

DuckDB’s .df() method returns the result as a pandas DataFrame. Use it when SQL is the best way to filter or join data but the next step belongs in pandas.

frame = duckdb.sql(f"""
    SELECT date, value
    FROM read_parquet('{data_url("rw.nisr.cpi.monthly")}')
    WHERE category = 'general_index_(cpi)'
    ORDER BY date
""").df()

Historical data

We also store dataset history in Apache Iceberg tables. The public download URL intentionally serves the latest version, while Iceberg time travel needs R2 Data Catalog credentials that we do not issue publicly today.

If you have those credentials, table names replace the dots in an ID with underscores. A topic that contains a hyphen keeps that hyphen, so quote the resulting SQL identifier.