csv

A CSV parser for Rust, with Serde support.

Latest version: 1.3.1 registry icon
Maintenance score
55
Safety score
100
Popularity score
70
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
1.3.1 0 0 0 0 0
1.3.0 0 0 0 0 0
1.2.2 0 0 0 0 0
1.2.1 0 0 0 0 0
1.2.0 0 0 0 0 0
1.1.6 0 0 0 0 0
1.1.5 0 0 0 0 0
1.1.4 0 0 0 0 0
1.1.3 0 0 0 0 0
1.1.2 0 0 0 0 0
1.1.1 0 0 0 0 0
1.1.0 0 0 0 0 0
1.0.7 0 0 0 0 0
1.0.6 0 0 0 0 0
1.0.5 0 0 0 0 0
1.0.4 0 0 0 0 0
1.0.3 0 0 0 0 0
1.0.2 0 0 0 0 0
1.0.1 0 0 0 0 0
1.0.0 0 0 0 0 0
0.15.0 0 0 0 0 0
0.14.7 0 0 0 0 0
0.14.6 0 0 0 0 0
0.14.5 0 0 0 0 0
0.14.4 0 0 0 0 0
0.14.3 0 0 0 0 0
0.14.2 0 0 0 0 0
0.14.1 0 0 0 0 0
0.13.8 0 0 0 0 0
0.13.7 0 0 0 0 0
0.13.6 0 0 0 0 0
0.13.5 0 0 0 0 0
0.13.4 0 0 0 0 0
0.13.3 0 0 0 0 0
0.13.2 0 0 0 0 0
0.13.1 0 0 0 0 0
0.13.0 0 0 0 0 0
0.12.19 0 0 0 0 0
0.12.18 0 0 0 0 0
0.12.17 0 0 0 0 0
0.12.16 0 0 0 0 0
0.12.15 0 0 0 0 0
0.12.14 0 0 0 0 0
0.12.13 0 0 0 0 0
0.12.12 0 0 0 0 0
0.12.11 0 0 0 0 0
0.12.10 0 0 0 0 0
0.12.9 0 0 0 0 0
0.12.8 0 0 0 0 0
0.12.7 0 0 0 0 0
0.12.6 0 0 0 0 0
0.12.5 0 0 0 0 0
0.12.4 0 0 0 0 0
0.12.3 0 0 0 0 0
0.12.2 0 0 0 0 0
0.12.1 0 0 0 0 0
0.12.0 0 0 0 0 0
0.11.0 0 0 0 0 0
0.10.2 0 0 0 0 0
0.10.1 0 0 0 0 0
0.10.0 0 0 0 0 0
0.9.0 0 0 0 0 0
0.8.1 0 0 0 0 0
0.8.0 0 0 0 0 0
0.7.5 0 0 0 0 0
0.7.4 0 0 0 0 0
0.7.3 0 0 0 0 0
0.7.2 0 0 0 0 0
0.7.1 0 0 0 0 0
0.7.0 0 0 0 0 0
0.6.3 0 0 0 0 0
0.6.2 0 0 0 0 0
0.6.1 0 0 0 0 0
0.6.0 0 0 0 0 0
0.5.2 0 0 0 0 0
0.5.1 0 0 0 0 0

Stability
Latest release:

1.3.1 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Unlicense   -   The Unlicense

Not a wildcard

Not proprietary

OSI Compliant


MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



csv

A fast and flexible CSV reader and writer for Rust, with support for Serde.

Build status crates.io

Dual-licensed under MIT or the UNLICENSE.

Documentation

https://docs.rs/csv

If you're new to Rust, the tutorial is a good place to start.

Usage

To bring this crate into your repository, either add csv to your Cargo.toml, or run cargo add csv.

Example

This example shows how to read CSV data from stdin and print each record to stdout.

There are more examples in the cookbook.

use std::{error::Error, io, process};

fn example() -> Result<(), Box<dyn Error>> {
    // Build the CSV reader and iterate over each record.
    let mut rdr = csv::Reader::from_reader(io::stdin());
    for result in rdr.records() {
        // The iterator yields Result<StringRecord, Error>, so we check the
        // error here.
        let record = result?;
        println!("{:?}", record);
    }
    Ok(())
}

fn main() {
    if let Err(err) = example() {
        println!("error running example: {}", err);
        process::exit(1);
    }
}

The above example can be run like so:

$ git clone git://github.com/BurntSushi/rust-csv
$ cd rust-csv
$ cargo run --example cookbook-read-basic < examples/data/smallpop.csv

Example with Serde

This example shows how to read CSV data from stdin into your own custom struct. By default, the member names of the struct are matched with the values in the header record of your CSV data.

use std::{error::Error, io, process};

#[derive(Debug, serde::Deserialize)]
struct Record {
    city: String,
    region: String,
    country: String,
    population: Option<u64>,
}

fn example() -> Result<(), Box<dyn Error>> {
    let mut rdr = csv::Reader::from_reader(io::stdin());
    for result in rdr.deserialize() {
        // Notice that we need to provide a type hint for automatic
        // deserialization.
        let record: Record = result?;
        println!("{:?}", record);
    }
    Ok(())
}

fn main() {
    if let Err(err) = example() {
        println!("error running example: {}", err);
        process::exit(1);
    }
}

The above example can be run like so:

$ git clone git://github.com/BurntSushi/rust-csv
$ cd rust-csv
$ cargo run --example cookbook-read-serde < examples/data/smallpop.csv