Clojure-CSV is a small library for reading and writing CSV files. The main features:
This library aims to be as permissive as possible with respect to deviation from the standard, as long as the intention is clear. The only correctness checks made are those on the actual (minimal) CSV structure. For example, some people think it should be an error when lines in the CSV have a different number of fields -- you should check this yourself. However, it is not possible, after parsing, to tell if the input ended before the closing quote of a field; if you care, it can be signaled to you.
The API has changed in the 2.0 series; see below for details.
Updated library to 2.0.2, with a bug fix for malformed input by attil-io.
Updated library to 2.0.1, which adds the :force-quote option to write-csv. Big thanks to Barrie McGuire for the contribution.
Updated library to 2.0.0; essentially identical to 2.0.0-alpha2.
Updated library to 2.0.0-alpha2..
Rewritten parser for additional speed increases.
Benchmarks to help monitor and improve performance.
Updated the library to 2.0.0-alpha1.
Major update: Massive speed improvements, end-of-line string is configurable for parsing, improved handling of empty files, input to parse-csv is now a string or Reader, and a new API based on keyword args instead of rebinding vars.
###Previously...
If you are using Leiningen, you can simply add
[clojure-csv/clojure-csv "2.0.1"]
to your project.clj and download it from Clojars with
lein deps
The clojure-csv.core
namespace exposes two functions to the user:
Takes a CSV as a char sequence or string, and returns a lazy sequence of vectors of strings; each vector corresponds to a row, and each string is one field from that row. Be careful to ensure that if you read lazily from a file or some other resource that it remains open when the sequence is consumed.
Takes the following keyword arguments to change parsing behavior:
A character that contains the cell separator for each column in a row.
A string containing the end-of-line character for reading CSV files. If this setting is nil then \n and \r\n are both accepted.
A character that is used to begin and end a quoted cell.
If this variable is true, the parser will throw an exception on parse errors that are recoverable but not to spec or otherwise nonsensical.
Takes a sequence of sequences of strings, basically a table of strings, and renders that table into a string in CSV format. You can easily call this function repeatedly row-by-row and concatenate the results yourself.
Takes the following keyword arguments to change the written file:
A character that contains the cell separator for each column in a row.
A string containing the end-of-line character for writing CSV files.
A character that is used to begin and end a quoted cell.
If this variable is true, the output will have ever field quoted, whether this is needed or not. This can apparently be helpful for interoperating with Excel.
Clojure-CSV was originally written for Clojure 1.0, before many of the modern features we now enjoy in Clojure, like keyword args, an IO library and fast primitive math. The 2.0 series freshens up the API to more modern Clojure API style, language capabilities, and coding conventions. The JARs for the 1.0 series will remain available indefinitely (probably a long, long time), so if you can't handle an API change, you can continue to use it as you always have.
Here's a summary of the changes:
Please let me know of any problems you are having.
Eclipse Public License
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close