DEV Community

HighPrecis
HighPrecis

Posted on

Logging Brix Readings with Python: A Tiny Batch Consistency Tracker

Disclosure: I work with HighPrecis, which sells the refractometer mentioned at the end.

Small juice and syrup producers often take sugar readings in degrees Brix before bottling, then write them on paper. That works until you want to answer simple questions like "is this supplier's fruit getting sweeter?" or "which batches were outside target?". Here is a tiny Python script that turns those readings into a log you can actually query.

The data

One CSV row per reading:

date,batch,product,brix
2026-10-01,B101,apple juice,11.8
2026-10-01,B101,apple juice,11.9
2026-10-02,B102,apple juice,12.6
2026-10-03,B103,ginger syrup,48.2
Enter fullscreen mode Exit fullscreen mode

Taking two or three readings per batch and averaging them smooths out sampling noise.

The script

import csv
from collections import defaultdict
from statistics import mean

TARGETS = {"apple juice": (11.5, 12.5), "ginger syrup": (47.0, 50.0)}

readings = defaultdict(list)
with open("brix_log.csv", newline="") as f:
    for row in csv.DictReader(f):
        readings[(row["date"], row["batch"], row["product"])].append(float(row["brix"]))

for (date, batch, product), values in sorted(readings.items()):
    avg = round(mean(values), 1)
    low, high = TARGETS.get(product, (None, None))
    status = "OK"
    if low is not None and not (low <= avg <= high):
        status = "OUT OF RANGE"
    print(f"{date} {batch:<5} {product:<13} {avg:>5} °Brix  {status}")
Enter fullscreen mode Exit fullscreen mode

Output:

2026-10-01 B101  apple juice    11.8 °Brix  OK
2026-10-02 B102  apple juice    12.6 °Brix  OUT OF RANGE
2026-10-03 B103  ginger syrup   48.2 °Brix  OK
Enter fullscreen mode Exit fullscreen mode

Making the readings trustworthy

The script is only as good as the numbers going in:

  • Zero the meter with distilled water before a session.
  • Stir the batch and sample from the middle.
  • Clean the prism between samples.
  • Use a meter with automatic temperature compensation (ATC), because refractive index shifts with temperature and a cold sample can read differently from a warm one.

Ideas to extend it

  • Plot average Brix per product over time with matplotlib to spot drift.
  • Export out-of-range batches to a separate CSV for review.
  • Add a column for the fruit supplier and group by it.

For reference, the readings in my examples come from a digital Brix refractometer with a 0-55% range and ATC, which shows the value as a number, so it's easy to type straight into the CSV.

Top comments (0)