Skip to main content

Backport of Python 3 csv module

Project description

Latest Version Join the chat at

The API of the csv module in Python 2 is drastically different from the csv module in Python 3. This is due, for the most part, to the difference between str in Python 2 and Python 3.

The semantics of Python 3’s version are more useful because they support unicode natively, while Python 2’s csv does not.


pip install backports.csv


First make sure you’re starting your file off right:

from backports import csv

Then be careful with your files to handle the encoding. I suggest using io.TextIOWrapper, opening your file in binary mode, and declaring your desired encoding when constructing your TextIOWrapper.

from backports import csv
from io import TextIOWrapper

def read_csv(filename):
    with TextIOWrapper(open(filename, 'rb'), encoding='utf-8') as f:
        reader = csv.reader(f)
        for row in reader:
            yield row

def write_csv(filename, rows):
    with TextIOWrapper(open(filename, 'wb'), encoding='utf-8') as f:
        writer = csv.writer(f)
        for row in rows:


This is a port of the csv module in the Python 3 standard libary. Because of this, backports.csv follows the same license as Python, whatever that may be at any given point in time.

1.0.1 (2016-02-11)

  • Better error messages for invalid dialects. - thanks to @kengruven for the bug report

1.0 (2016-02-11)

  • Initial Release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for backports.csv, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size backports.csv-1.0.1-py2.py3-none-any.whl (12.6 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size backports.csv-1.0.1.tar.gz (11.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page