A CSV library for Dart
Parse, write, stream, query and validate CSV from Dart, with types inferred for you and no dependencies to pull in.
Install#
dart pub add csv_plusimport 'package:csv_plus/csv_plus.dart';A first example#
final codec = CsvCodec();
final csv = codec.encode([
['name', 'age', 'score'],
['Alice', 30, 95.5],
['Bob', 25, 88.0],
]);
final rows = codec.decode(csv);
// rows[1] == ['Alice', 30, 95.5] (String, int, double)Note what came back. 30 is an int and 95.5 is a double, not strings you have to convert yourself.
Guides#
- Parse CSVTurn a CSV string into typed rows.
- Read a fileLoad a .csv from disk into rows or a table.
- Write CSVEncode rows back out, with correct quoting.
- Headers and rowsAddress fields by column name instead of index.
- Type inferenceHow types are guessed, and how to take control.
- Query and groupFilter, sort, aggregate and group rows.
- CSV to JSONConvert rows to maps and JSON.
- Schema and validationDeclare column types, validate, coerce.
- TSV and delimitersTabs, semicolons, pipes and custom separators.
- Large filesStream files of any size in constant memory.
What it does#
- RFC 4180 parsing, including quoted fields, embedded newlines and escaped quotes
- Automatic type inference, guarded so identifier-like values are not corrupted
- Typed decoders for whole grids, and per-column schemas with validation and coercion
- A queryable table with filter, sort, aggregate and group
- Streaming decode with backpressure, for files larger than memory
- TSV, semicolon, pipe and fully custom delimiters, quoting and line endings
- Comment preambles, leading-row skipping and row windowing
dart:convertintegration, so it fuses with other codecs
Zero dependencies#
csv_plus depends on nothing outside the Dart SDK. That keeps your dependency graph small, avoids version conflicts in an app that already pins a lot, and means there is no transitive package to audit. The core library is pure Dart and runs anywhere Dart does, including the browser; file helpers live in a separate io.dart import so the core never pulls in dart:io.