tsv2py
raw JSON → 0.7.1 verified Fri May 01 auth: no python
High-performance parser and generator for PostgreSQL-compatible tab-separated values (TSV). Current version 0.7.1, requires Python >=3.8. Release cadence is irregular (last release 2025-01).
pip install tsv2py Common errors
error TypeError: TsvParser expected a string or file-like object, not a path ↓
cause Passing a file path string instead of a file object or TSV content string.
fix
Use open('file.tsv') or provide the TSV content as a string.
error AttributeError: module 'tsv2py' has no attribute 'TsvReader' ↓
cause TsvReader was removed in version 0.7.0.
fix
Use tsv2py.TsvParser instead.
Warnings
breaking In version 0.7.0, the API changed from classes like TsvReader to TsvParser and TsvGenerator. Old code using TsvReader will break. ↓
fix Replace TsvReader with TsvParser and adapt interface (e.g., rows via iteration).
deprecated The option to read TSV from file paths directly in the constructor was deprecated; use file-like objects. ↓
fix Use open(filename, 'r') to create a file object and pass it to TsvParser.
gotcha TsvParser expects TSV data as string or file object, not a file path. Passing a path will raise TypeError. ↓
fix Always open file first: with open(path) as f: TsvParser(f).
Imports
- tsv2py wrong
from tsv2py import tsv2pycorrectimport tsv2py
Quickstart
import tsv2py
# Parse TSV string
data = "col1\tcol2\n1\t2"
for row in tsv2py.TsvParser(data):
print(row)
# Generate TSV string
g = tsv2py.TsvGenerator()
g.append(["a", "b"])
print(g.finish())