Python CSV, and delimiter-spaced files, for humans!
Comma: A Python CSV Library for Humans
This library tries to make manipulating CSV files a great experience.

Features
Here are some of the features that comma supports:
- Robust autodetection of CSV parameters
clevercsv) and
encoding (thanks to chardet).
- Single-line usage,
comma.load(...), no syntax to remember or parameters to tweak. - Simple, Pythonic interface to access/modify the rows using standard
listand
dict operations, i.e. row[0] and row["street"] are equivalent.
- Column slices using the header name, i.e.
table["street"]. - In-place editing of the dataset, including multiple lines.
- Opening files directly from an URL.
Installation
If you use pip:
script pip install 'comma[autodetect,net]' or if you use pipenv: script pipenv install 'comma[autodetect,net]'
Why?
Although Python, fortuitously, is "batteries included", on occasion, some of the libraries end up being designed with APIs that don't map well to what turns out to be the most common usage patterns. This is what happened with the various urllib libraries, incredibly powerful, but limiting users by its complexity---it was not straightforward, for instance, to use cookies: One of several problems that requests by @ken-reitz addressed. Indeed, requests abstracts power beneath simplicity, smart defaults, and discoverability.
For the CSV format, we are confronted with a similar situation. While both the JSON and YAML formats have packages that provide, one-command means to load content from files in those respective formats to a nested Python object, for the CSV format, the standard library has you use an iterator to access the data. Many details require significant syntax change (for instance the difference between having lists or dictionaries depends on the class that is used to read the file).
Since then, we also have several excellent libraries that, by providing great auto-detection (of dialect, file format, encoding, etc.) allow for hiding many details from the end user.
All this to say, comma will try to do exactly what you want when you do:
import comma
data = comma.load("file.csv")
data[0]["field"] = "changed value"
comma.dump(data, filename="file_modified.csv")
Alternatives
Python is fortunate to have a lot of very good libraries to read/write CSV and tabular files in general. (Some of these were discovered through the excellent Awesome Python list.)
clevercsv: An
csv
module, and as such does not improve on the complex syntax. This
library is the culmination of serious peer-reviewed
research, and comma uses it
internally to improve auto-detection.
csvkit: This is a set of
csvpy <file.csv> to open a Python shell with the CSV
data loaded into a Python object called reader, to quickly run
some Python logic on the data. While it is technically possible to
use csvkit's internals in a project, this is not documented.
pandas: An advanced data
pyexcel: This library provides
tablib: This library was
requests,
pipenv and many other goodies to
Python---and then included in the Jazzband
collective. The focus of this library is on interoperating between many
different file formats (such as XLS, CSV, JSON, YAML, DF, etc., ...,
even LaTeX booktabs!). It seems to have a very high adoption rate
because it is a dependency for many Jazzband libraries. The API is
class-based rather than method-based. A companion library,
prettytable focuses on
pretty printing tabular data (including from a CSV file).
tabulator: This
Although not specifically restricted to Python, the AwesomeCSV resource is also interesting.
Miscellaneous
Although not specifically a Python library, nor designed to read/write CSV files (but instead to compare them), daff is a really cool project: It provides a diff of tabular data with cell-level awareness.
Another unrelated project is Grist, a spreadsheet PaaS, which among other useful features, allows the use of Python within formulas.
Acknowledgements
Thanks to @zbanks for the name of the package! Thanks to @rfreling, @adamfinkelstein for discussing ideas before I got started on this. Thanks to @GjjvdBurg and collaborators for awesome, awesome contribution to text processing science and our Python community with clevercsv.
License
This project is licensed under the LGPLv3 license, with the understanding that importing a Python modular is similar in spirit to dynamically linking against it.
- You can use the library
commain any project, for any purpose, as long
- If you make improvements to
comma, you are required to make those