csv

Fast, flexible CSV reading and writing for Rust, with Serde support

Library
Cargo
v1.4.0
1,960 stars
Unlicense

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
52 /100 Fair
Development Activity 32
Maintenance 4
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 84
Code Quality 85
Innovation 75
Learning Curve 82

The csv crate is BurntSushi’s fast CSV parser/writer for Rust, offering both a convenient, allocation-friendly high-level API and a low-level, allocation-free csv-core layer for performance-critical or no_std contexts. It handles the messy realities of real-world CSV — custom delimiters, quoting, variable record lengths, and encoding edge cases — while integrating directly with Serde so CSV rows can be deserialized straight into typed structs (and serialized back out) with minimal boilerplate.

The repository ships as three crates (csv, csv-core, csv-index) plus an extensive tutorial and cookbook built into the docs, reflecting its long history as one of the most widely relied-upon data-parsing crates in the Rust ecosystem.

What You Get

  • High-level Reader/Writer types for parsing and generating CSV from files, byte slices, or any io::Read/io::Write
  • First-class Serde integration for deserializing CSV rows directly into typed structs and serializing structs back to CSV
  • Support for custom delimiters, quoting styles, flexible record lengths, and both StringRecord/ByteRecord (valid-UTF-8 vs raw-bytes) row types
  • A separate, allocation-free csv-core crate for no_std or performance-critical parsing without the high-level convenience layer
  • A built-in tutorial and cookbook (src/tutorial.rs, src/cookbook.rs) with runnable examples for common read/write/performance patterns

Common Use Cases

  • Loading CSV data exports (analytics, financial, log data) directly into typed Rust structs via Serde for further processing
  • Streaming very large CSV files without loading them entirely into memory, using the low-level csv-core API
  • Writing structured data (reports, batch job output) out to CSV for downstream consumption by spreadsheets or other tools
  • Handling messy real-world CSV variants (custom delimiters, inconsistent quoting, ragged rows) that stricter parsers reject

Under The Hood

Architecture - The csv crate wraps the csv-core crate’s allocation-free, no_std-compatible parsing state machine with a buffered, allocating Reader/Writer layer; StringRecord/ByteRecord (src/string_record.rs, src/byte_record.rs) represent a parsed row either as validated UTF-8 or raw bytes, and src/deserializer.rs/src/serializer.rs bridge those records to/from Serde’s Deserialize/Serialize traits so structs can be read or written directly; csv-index builds on top of csv to provide indexed/random-access reads over large CSV files.

Tech Stack - Pure Rust across three workspace crates (csv, csv-core, csv-index), dual-licensed MIT/Unlicense, with benches/bench.rs for performance regression tracking and a CI pipeline (ci/script.sh) that runs the full test and benchmark suite; the crate deliberately avoids unnecessary dependencies to keep compile times and binary size low.

Code Quality - tests/tests.rs plus embedded doc-tests throughout src/tutorial.rs and src/cookbook.rs mean the extensive documentation examples are themselves compiled and checked as part of the test suite, preventing doc drift; the split between StringRecord and ByteRecord is a deliberate design choice to handle non-UTF-8 CSV data without panicking, reflecting attention to real-world data quality issues.

API Design - The crate is unusually well-documented for a Rust library, with an in-crate tutorial that walks from basic reading through Serde integration to performance tuning (allocation reuse, csv-core fallback), which substantially lowers the learning curve for a domain (CSV parsing) that has many easy-to-miss edge cases.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers