The classes and functions in this module serve as a replacement for Python 2’s core csv module on Python 2. These versions add support fo non-ascii encodings as well as several other minor features.

If you are using Python 2, these classes and functions will automatically be made available as part of the agate import. This means you can access them by:

from agate import DictReader

Or, if you want to use them as a drop-in replacement for csv:

import agate as csv
class agate.csv_py2.UTF8Recoder(f, encoding)

Bases: six.Iterator

Iterator that reads an encoded stream and reencodes the input to UTF-8.

class agate.csv_py2.UnicodeReader(f, encoding='utf-8', maxfieldsize=None, **kwargs)

Bases: object

A CSV reader which will read rows from a file in a given encoding.

class agate.csv_py2.UnicodeWriter(f, encoding='utf-8', **kwargs)

Bases: object

A CSV writer which will write rows to a file in the specified encoding.

NB: Optimized so that eight-bit encodings skip re-encoding. See:
class agate.csv_py2.UnicodeDictReader(f, fieldnames=None, restkey=None, restval=None, *args, **kwargs)

Bases: csv.DictReader

Defer almost all implementation to csv.DictReader, but wraps our unicode reader instead of csv.reader().

class agate.csv_py2.UnicodeDictWriter(f, fieldnames, restval='', extrasaction='raise', *args, **kwds)

Bases: csv.DictWriter

Defer almost all implementation to csv.DictWriter, but wraps our unicode writer instead of csv.writer().

class agate.csv_py2.Reader(f, encoding='utf-8', maxfieldsize=None, **kwargs)

Bases: agate.csv_py2.UnicodeReader

A unicode-aware CSV reader.

class agate.csv_py2.Writer(f, encoding='utf-8', line_numbers=False, **kwargs)

Bases: agate.csv_py2.UnicodeWriter

A unicode-aware CSV writer.

class agate.csv_py2.DictReader(f, fieldnames=None, restkey=None, restval=None, *args, **kwargs)

Bases: agate.csv_py2.UnicodeDictReader

A unicode-aware CSV DictReader.

class agate.csv_py2.DictWriter(f, fieldnames, encoding='utf-8', line_numbers=False, **kwargs)

Bases: agate.csv_py2.UnicodeDictWriter

A unicode-aware CSV DictWriter.

agate.csv_py2.reader(*args, **kwargs)

A drop-in replacement for Python’s csv.reader() that leverages Reader.

agate.csv_py2.writer(*args, **kwargs)

A drop-in replacement for Python’s csv.writer() that leverages Writer.