CSV parser, intended for use with csvapi.
This is based on, and depends on, the Agate library.
Provided a path to a CSV, it will:
- try to guess the encoding with cchardet — encoding can be forced if needed;
- try to guess the CSV dialect (delimiter and such) by using a custom sniffing method;
- return an
agate.Table
object or raise anException
.
from csv_parser import parse
table = parse('/path/to/csv')
# force the encoding
table = parse('/path/to/csv', encoding='utf-8')