Skip to main content

Data Files

Read and write data files across multiple formats.

This module provides a unified interface for file-based datasets and is intended to grow as more formats are added. Currently, it includes support for JSON via JSONFile, CSV via CSVFile, HDF5 via HDF5File/HDF5Group, NumPy via NumpyFile, and plain text via TextFile.

Examples​

HDF5File("data.h5")
.write("scalar/int", 5)
.write("scalar/real", 3.14)
.write("list/values", [1, 2, 3])
.write("list/flags", [true, false, true])

var g = HDF5File("data.h5").group("experiments")
g.write("run1/value", 42)
g.write_attribute("run1/value", "units", "arb")
g.list_datasets()

var f = TextFile("notes.txt", "w")
f.write("hello\n").append("world\n")
var lines = TextFile("notes.txt").read_lines()

var csv = CSVFile("people.csv", "w")
csv.set_column_name(0, "name").set_column("name", ["Ada", "Grace"]).save()

var file = JSONFile("results", "w")
file.set_value(["samples": [1.5, 2.5]]).save()
var samples = file.value("/samples", as_list | as_real)

NumpyFile("values.npy", "w").write([1.0, 2.0, 3.0])
var values = NumpyFile("values.npy").read(as_real | as_list)
NumpyFile("archive.npz", "w").write("run1", [1, 2, 3])

Types​

NameDescription
CSVFileRepresents a CSV file held in memory.
CSVValueConverterCallable that converts one CSV string value.
HDF5FileRepresents an HDF5 file handle.
HDF5GroupRepresents an HDF5 group.
JSONFileRepresents a lazily loaded JSON document with explicit persistence.
NumpyFileRepresents a NumPy .npy or .npz file handle.
TextFileRepresents a text file handle.