Skip to content
Back to top
View this page

# CSV reader and writer

Agate contains CSV readers and writers that are intended to be used as a drop-in replacement for `csv`. These versions add unicode support for Python 2 and several other minor features.

Agate methods will use these version automatically. If you would like to use them in your own code, you can import them, like this:

    from agate import csv

Due to nuanced differences between the versions, these classes are implemented seperately for Python 2 and Python 3. The documentation for both versions is provided below, but only the one for your version of Python is imported with the above code.

## Python 3

`agate.csv_py3.reader` | A replacement for Python's `csv.reader()` that uses `csv_py3.Reader`.
`agate.csv_py3.writer` | A replacement for Python's `csv.writer()` that uses `csv_py3.Writer`.
`agate.csv_py3.Reader` | A wrapper around Python 3's builtin `csv.reader()`.
`agate.csv_py3.Writer` | A wrapper around Python 3's builtin `csv.writer()`.
`agate.csv_py3.DictReader` | A wrapper around Python 3's builtin `csv.DictReader`.
`agate.csv_py3.DictWriter` | A wrapper around Python 3's builtin `csv.DictWriter`.

## Python 3 details

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

  A replacement for Python’s `csv.reader()` that uses `csv_py3.Reader`.

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

  A replacement for Python’s `csv.writer()` that uses `csv_py3.Writer`.

class agate.csv_py3.Reader(f, field_size_limit=None, line_numbers=False, header=True, **kwargs)

  Bases: `object`

  A wrapper around Python 3’s builtin `csv.reader()`.

class agate.csv_py3.Writer(f, line_numbers=False, **kwargs)

  Bases: `object`

  A wrapper around Python 3’s builtin `csv.writer()`.

class agate.csv_py3.DictReader(f, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)

  Bases: `DictReader`

  A wrapper around Python 3’s builtin `csv.DictReader`.

class agate.csv_py3.DictWriter(f, fieldnames, line_numbers=False, **kwargs)

  Bases: `DictWriter`

  A wrapper around Python 3’s builtin `csv.DictWriter`.