Use the Python package when you want an imibare dataset as a DataFrame. We keep the interface small:
load() reads data and catalog() tells you what data exists.
Install and import
Install the base package for pandas support. Add an extra only when you need Polars or private Iceberg history access.
| If you want to | Install |
|---|---|
| pandas DataFrames and the bundled catalog | pip install imibare |
| Polars DataFrames | pip install 'imibare[polars]' |
| Historical Iceberg snapshots | pip install 'imibare[iceberg]' |
import imibare as imi
Load data
Call imi.load() with a 4-segment dataset ID. It returns the latest published data through the
public API unless you explicitly request a historical version.
def load(
dataset_id: str,
start: int | str | None = None,
end: int | str | None = None,
engine: Literal["pandas", "polars"] = "pandas",
version: str | None = None,
force_download: bool = False,
) -> pd.DataFrame | pl.DataFrame
Choose the arguments
| Argument | Default | Use it when | What we do |
|---|---|---|---|
dataset_id | required | You know the dataset to load | Validate the 4-segment ID and retrieve that dataset |
start | None | You want rows on or after a year or ISO date | Treat an integer such as 2020 as 2020-01-01 |
end | None | You want rows on or before a year or ISO date | Apply an inclusive upper bound |
engine | "pandas" | Your analysis uses Polars | Return pl.DataFrame when you pass "polars" |
version | None | You have R2 Data Catalog access and need history | Read the snapshot published on or before YYYY-MM-DD |
force_download | False | You need to bypass a local cache | Download the latest API file without revalidating the cache |
start and end accept an integer year, an ISO date string, or None. Both bounds are
inclusive, so start=2020, end=2023 keeps the complete 2020 through 2023 period.
Get the result
load() returns a pandas DataFrame by default and a Polars DataFrame when engine="polars".
Its columns match the dataset record from catalog() and
GET /v1/datasets/{id}, with dates parsed as datetime columns.
Use the public path unless you have a reason not to. A version request reads our Iceberg catalog
directly and needs the [iceberg] extra plus credentials that we do not issue publicly.
Handle errors and warnings
| What happens | What you receive | What to do |
|---|---|---|
The ID is malformed, unknown, or has no snapshot before version | ValueError | Check the dataset ID and requested date |
| The ID exists but no data has been published | FileNotFoundError | Check the dataset page or wait for the pipeline to publish |
| The API fails and there is no usable cache | RuntimeError | Retry later or load the dataset before you need offline access |
| Polars or Iceberg support is missing | ImportError | Install the matching extra |
| The API fails but a cache exists | UserWarning and cached data | Read the warning, which states when the file was last confirmed current |
Examples
import imibare as imi
# Latest complete dataset
cpi = imi.load("rw.nisr.cpi.monthly")
# Kenya uses the same interface
kenya_cpi = imi.load("ke.knbs.cpi.monthly")
# Inclusive year or exact-date bounds
recent_cpi = imi.load("rw.nisr.cpi.monthly", start=2020, end=2023)
usd_2024 = imi.load("rw.bnr.fx.daily", start="2024-01-01", end="2024-12-31")
# A Polars DataFrame
polars_cpi = imi.load("rw.nisr.cpi.monthly", engine="polars")
# The newest file, without using the cache
fresh_cpi = imi.load("rw.nisr.cpi.monthly", force_download=True)
Browse the catalog
Call imi.catalog() when you need IDs or want to inspect coverage before loading. The catalog
ships with the package, so it works offline and represents the data known when your installed
package version was released.
def catalog(
country: str | list[str] | None = None,
topic: str | None = None,
frequency: str | None = None,
) -> list[DatasetMeta]
Filter the records
| Argument | Accepted values | What it matches |
|---|---|---|
country | An ISO alpha-2 code, a list of codes, or None | Country, case-insensitively: "RW", "KE", or ["RW", "KE"] |
topic | A metadata topic or None | Exact metadata topic, such as "prices" |
frequency | A frequency slug or None | daily, monthly, quarterly, annual, or irregular |
The metadata topic is not always the third part of the ID. For example,
rw.nisr.cpi.monthly has the metadata topic prices, so use a topic you have seen in a
catalog record rather than guessing from the ID.
# All bundled records
all_datasets = imi.catalog()
# Country and frequency filters
kenya = imi.catalog(country="KE")
monthly = imi.catalog(country="KE", frequency="monthly")
# Consumer price and inflation datasets in both countries
prices = imi.catalog(topic="prices")
for dataset in imi.catalog(country="RW"):
print(dataset.id, dataset.name)
catalog() returns an empty list when nothing matches. Upgrade the package to see datasets that
were added after your installed release.
Read dataset metadata
Each DatasetMeta is a record from the bundled catalog. It describes the publisher, coverage,
schema, formats, and reuse information, but leaves the live last_updated and version empty
because those values can change after the package ships.
@dataclass
class DatasetMeta:
id: str
country: str
country_name: str
name: str
institution: str
institution_slug: str
topic: str
frequency: str
coverage_start: str
coverage_end: str
pipeline: Literal["automated", "curated", "stale"]
source_url: str
source_format: str
formats: list[str]
license: str
license_basis: str
columns: list[ColumnSpec]
last_updated: str = ""
version: str = ""
notes: str | None = None
license_url: str | None = None
Use the API record when you need the live version,
update date, or version history. The license field records what the publisher states; it is not
a license granted by imibare.
@dataclass
class ColumnSpec:
name: str
type: str
description: str
unit: str | None
Check the installed version
imibare.__version__
The value is a string, such as "0.3.0". It tells you which bundled catalog and package behavior
you have installed.
Configure the package
You normally need no configuration. Set these variables only when you use a different API host or private Iceberg history access.
| Variable | Needed for | Why |
|---|---|---|
IMIBARE_API_URL | A mirror or local API | Replaces the default https://api.imibare.org host |
R2_ACCOUNT_ID | version= | Identifies the Cloudflare account that owns the catalog |
R2_BUCKET | version= | Names the R2 bucket |
R2_CATALOG_URL | version= | Points to the Iceberg REST catalog |
R2_CATALOG_TOKEN | version= | Authenticates to the Iceberg catalog |
Understand the cache
We keep the latest file for each dataset at this path, next to a latest.etag file that records
the API version we received. The cache makes repeated analysis quicker while still checking for
changes on a predictable schedule.
~/.imibare/cache/{country}/{institution}/{topic}/{frequency}/latest.parquet
| Cache state | What load() does |
|---|---|
| File is less than 1 hour old | Uses it with no request |
| File is older than 1 hour and unchanged | Sends its ETag, receives 304 Not Modified, and keeps it for another hour |
| File is older than 1 hour and changed | Downloads the replacement |
| API is unavailable and a file exists | Returns the file with a UserWarning |
force_download=True | Skips this process and downloads the latest file |
Delete ~/.imibare/cache/ if you need to clear every cached dataset. Removing the directory is
safe, but the next call for each dataset will need to download it again.