baml.csv.Record

One raw CSV record. Yielded by iterating a `Reader`.

Reference version

Signature

class baml.csv.Record

One raw CSV record. Yielded by iterating a Reader.

Where Python's csv.DictReader hands you a finished dict of strings, a Record converts on demand: get<int>("amount") reads one cell and leaves the others untouched. to_map() is there when you do want the whole dict.

Records are snapshots and stay valid after the reader advances. Each one carries the headers in force when it was read, so name-based access keeps working on a record you held onto.

The cell-decodable types, shared by get, get_at, and decode, are string, int, bigint, float, bool, any enum (matched against variant names), baml.time.Instant, baml.time.PlainDate, baml.time.PlainDateTime, and optionals of those. Any other T is a configuration mistake, not a data problem, and throws Error { kind: Options }.

A "null cell" is an unquoted cell that is empty or matches ReaderOptions.null_values; quoting a cell always makes it data. The one asymmetry: an empty cell read as T = string is "", not null, since an empty string is a perfectly good string and CSV cannot tell the two apart.

Source:<builtin>/baml/ns_csv/csv.bamlbytes 989913551

Fields

_handle

$rust_type

Instance methods

function

decode

<T>(self) -> T throws baml.csv.Error

Applies the full typed-decode rules to this one record — useful for routing heterogeneous rows.

Always throws on failure, whatever the reader's on_error policy says.

T must be a flat class. Each field is matched to a column by its declared name (no @alias), or positionally by declaration order when the reader has no headers. An optional field tolerates an absent column, a missing cell, and a null cell; a required one tolerates none of the three.

Throws

  • Error { kind: Decode } when a cell will not convert, or when a required field's cell is missing or null.
  • Error { kind: Header } when a required field has no matching column, or its column name is duplicated.
  • Error { kind: Options } when T is not a class, or a field's type is not cell-decodable.
function

fields

(self) -> string[]
function

get

<T>(self, column: string) -> T | null throws baml.csv.Error

Converts the cell under header column to T.

Returns

null for a column name absent from the headers, a missing cell, or a null cell.

Throws

  • Error { kind: Decode } when a cell exists but cannot convert to T.
  • Error { kind: Header } when the name is duplicated in the header, or when name-based access is used with no headers at all — use get_at for positional access.
  • Error { kind: Options } when T is not cell-decodable.
function

get_at

<T>(self, index: int) -> T | null throws baml.csv.Error

Converts the cell at index to T, positionally.

Works with or without headers. An out-of-range or negative index reads as a missing cell rather than an error.

Returns

null for a missing or null cell.

Throws

  • Error { kind: Decode } on conversion failure.
  • Error { kind: Options } when T is not cell-decodable.
function

length

(self) -> int

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 747779