Developer

Language: English
Appearance

Theme

Accent colour

Your theme and colour carry over to satelit.md and the app.

Sign in

Where should the theme change?

Choose where the new theme applies.

You can change it any time from the header.

Cookbook · Python 3.9+

Monthly cost of living report

On the 1st of the month, a report ready to publish: what the basic basket costs today and in the cheapest shop, what got dearer or cheaper over 30 days by group, and the ANRE tariffs in force.

Runs on
Python 3.9+
One run
5 credits
A month
5 credits
Set up in
5 min
$ MONTHS=12 DAYS=30 python3 basket_report.pyreports/report-2026-11.md: basket 723.35 lei, 12 groups, 9 tariffs, 5 credits

How it works

  1. Get the basket over the last MONTHS months from /v1/indexes/basket: the total, the cheapest total, the monthly and yearly change.
  2. Get what got dearer and cheaper over DAYS days from /v1/indexes/moves, by product group.
  3. Get the household tariffs from /v1/tariffs, each with its ANRE decision.
  4. Write report-YYYY-MM.md for the article and basket-YYYY-MM.csv for the chart.

What it costs: 2 credits for the basket, 2 for the moves, 1 for the tariffs: 5 credits a month. Fits in the Start plan.

How to run it

bash
export SATELIT_KEY=sat_live_...
MONTHS=12 DAYS=30 python3 basket_report.py

What it outputs

stdout
reports/report-2026-11.md: basket 723.35 lei, 12 groups, 9 tariffs, 5 credits

The full script

basket_report.py
#!/usr/bin/env python3
"""Cost of living report: the food basket, what got dearer or cheaper, and household tariffs, once a month.

    SATELIT_KEY=sat_live_... python3 basket_report.py

Optional: MONTHS (12, the basket's span), DAYS (30, the moves' window), OUT_DIR (reports).
Writes report-YYYY-MM.md and basket-YYYY-MM.csv. Standard library only.
Put it in cron: 0 9 1 * * python3 /path/basket_report.py
"""
import csv
import json
import os
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
from datetime import date
from pathlib import Path

sys.stdout.reconfigure(encoding="utf-8")  # names hold ă, ș, ț whatever the console's code page

BASE = os.environ.get("SATELIT_BASE", "https://api.satelit.md/v1")
KEY = os.environ["SATELIT_KEY"]
MONTHS = int(os.environ.get("MONTHS", "12"))
DAYS = int(os.environ.get("DAYS", "30"))
OUT = Path(os.environ.get("OUT_DIR", "reports"))
credits_used = 0
attribution = ""


def api(path, **params):
    global credits_used, attribution
    query = urllib.parse.urlencode({"lang": "ro", **params})
    req = urllib.request.Request(f"{BASE}{path}?{query}", headers={"Authorization": f"Bearer {KEY}"})
    for attempt in range(3):
        try:
            with urllib.request.urlopen(req, timeout=20) as res:
                body = json.load(res)
                credits_used += body["meta"].get("credits", 0)
                attribution = attribution or body["meta"].get("attribution", "")
                return body["data"]
        except urllib.error.HTTPError as err:
            retry = err.headers.get("Retry-After")
            if err.code in (429, 503) and retry and attempt < 2:
                time.sleep(int(retry))
                continue
            raise SystemExit(f"{path}: {err.code} {err.read().decode()}")


def pct(n):
    return "n/a" if n is None else f"{n:+.2f}%"


def main():
    basket = api("/indexes/basket", months=MONTHS)
    moves = api("/indexes/moves", days=DAYS)
    tariffs = api("/tariffs")
    month = date.today().strftime("%Y-%m")
    OUT.mkdir(parents=True, exist_ok=True)

    points = basket["points"]
    first, last = points[0], points[-1]
    span = (last["total"] / first["total"] - 1) * 100 if first["total"] else 0
    with open(OUT / f"basket-{month}.csv", "w", newline="", encoding="utf-8") as f:
        out = csv.writer(f)
        out.writerow(["date", "total_lei", "cheapest_total_lei"])
        out.writerows([p["date"], p["total"], p["cheapest_total"]] for p in points)

    groups = sorted(moves["groups"], key=lambda g: g["change_pct"])
    lines = [
        f"# Cost of living in Moldova, {month}",
        "",
        "## Food basket",
        f"- {len(basket['items'])} products, {last['date']}: **{last['total']:.2f} lei** "
        f"(the cheapest shop for each: {last['cheapest_total']:.2f} lei)",
        f"- Since {first['date']}: {span:+.2f}%; month on month {pct(basket['change_mom'])}, year on year {pct(basket['change_yoy'])}",
        "",
        f"## Prices in shops, {moves['from']} to {moves['to']}",
        f"- {moves['compared']} products compared: {moves['up']} dearer, {moves['down']} cheaper, {moves['same']} unchanged, "
        f"on average {moves['change_pct']:+.2f}%",
        *[f"- {g['label']}: {g['change_pct']:+.2f}% ({g['up']} up, {g['down']} down)" for g in groups],
        "",
        "## Household tariffs",
        *[f"- {t['label']} ({t['provider']}): {t['value']} {t['unit']}, since {t['valid_from']}, {t['decision']}" for t in tariffs],
        "",
        f"_{attribution}_",
    ]
    report = OUT / f"report-{month}.md"
    report.write_text("\n".join(lines) + "\n", "utf-8")
    print(f"{report}: basket {last['total']:.2f} lei, {len(groups)} groups, {len(tariffs)} tariffs, {credits_used} credits")


if __name__ == "__main__":
    main()

Routes used

Data in this cookbook

Updated:

Questions about this cookbook

What is in the basket?

The list is in data.items: product, quantity and unit. total is the basket's price in shops; cheapest_total is the same basket bought from the cheapest shop for each product.

How far back does the history go?

Shop prices have history from 28 October 2026. For a month or a year with no data, change_mom and change_yoy are null and the report writes n/a.

Can I publish the report?

Yes, with the line from meta.attribution, which the script puts at the end. The tariffs come from ANRE's public decisions, named in the report.