columncheck
columncheck

how columncheck fits in

Install

consolepip install columncheck

Use

consolecolumncheck data.csv                       # structure only
columncheck data.csv --header a,b,c        # ... and the columns it must have
columncheck data.csv --sniff               # guess , ; tab or | first
columncheck data.tsv --delimiter $'\t'
columncheck data.csv --allow-ragged         # field counts may vary
columncheck data.csv --json                 # for a dashboard, exit 1 on problems
pythonfrom columncheck import lint_csv, sniff_delimiter

problems = lint_csv(open("data.csv", "rb").read(), expected_header=["id", "total"])
for problem in problems:
    print(problem)            # line 418: 4 field(s), header has 5 (ragged-row)

Checks

code what it means
bomthe file starts with a byte order mark; the first column is \ufeffname
nul-bytea NUL byte, which most parsers choke on later
empty-fileno header row at all
empty-headerthe header row is empty, or a column has no name
padded-header" a " — invisible in a spreadsheet, painful in SQL
duplicate-headerthe same name twice; DictReader silently keeps the last
ragged-rowa row whose field count differs from the header
missing-column / extra-columnthe file is not what you expected
encodingthe bytes are not valid in the encoding you asked for
malformedthe CSV itself is broken

Quoted fields containing commas or newlines are handled properly, and row numbers stay correct across a multi-line quoted field.

Limits

spreadsheet and wrong for a 30 GB dump — use a streaming validator there.

Development

consolepython -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

The suite covers every line of the package (pytest --cov --cov-branch), and the examples in the docstrings run as tests through --doctest-modules.

License

MIT.

Other libraries here

One problem each, standard library only, no runtime dependencies.