I have a very similar function in the csv_example.py, we could repurpose.