super-csv

raw JSON →
5.0.0 verified Fri May 01 auth: no python

A CSV processor library for Python, maintained by Open edX. Version 5.0.0 provides tools for reading and writing CSV files with a focus on handling BOM (Byte Order Mark) characters and encoding issues. The library supports Python 2.7 and 3.5+.

pip install super-csv
error ImportError: No module named 'super_csv'
cause Library not installed or wrong import path.
fix
Install via 'pip install super-csv' and import as 'from super_csv import ...'.
error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
cause CSV file has a BOM (Byte Order Mark) but encoding is not set to 'utf-8-sig'.
fix
Pass encoding='utf-8-sig' when creating SuperCsvReader.
error AttributeError: 'SuperCsvReader' object has no attribute 'next'
cause Using Python 3's iterator protocol incorrectly. In Python 3, use 'next(reader)' instead of 'reader.next()'.
fix
Replace 'reader.next()' with 'next(reader)'.
breaking Python 2.7 support was dropped in version 4.0.0. Upgrade to Python 3.5+.
fix Use Python 3.5 or later.
gotcha The default encoding for SuperCsvReader is 'utf-8', which fails on files with BOM. Use 'utf-8-sig' to handle BOM correctly.
fix Specify encoding='utf-8-sig' when opening files.
deprecated The function `super_csv.update_from_dict` was deprecated in v4.1.0 and removed in v5.0.0. Use `SuperCsvWriter.writerow` with a dict instead.
fix Replace calls to `update_from_dict` with `writer.writerow(dict_data)`.
pip install super-csv==4.1.0

Basic CSV read/write with BOM-safe encoding.

from super_csv import SuperCsvReader, SuperCsvWriter
import os

# Reading a CSV file
reader = SuperCsvReader('data.csv', encoding='utf-8-sig')
for row in reader:
    print(row)

# Writing a CSV file
writer = SuperCsvWriter('output.csv', encoding='utf-8-sig')
writer.writeheader(['name', 'age'])
writer.writerow({'name': 'Alice', 'age': 30})
writer.close()