Linear TSV

1.1.0 · active · verified Thu Apr 16

Linear TSV is a Python library providing a simple, line-oriented, and portable tabular data format. Unlike standard CSV, it uses escape codes for newlines and tabs within field data, enabling robust processing with line-oriented shell tools. The format aligns with the TEXT serialization mode of Postgres and MySQL, making it ideal for reliable data exchange. It is currently at version 1.1.0 and maintains an active release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a `linear-tsv` formatted string using the `tsv.un()` function. It shows how to handle embedded newlines and tabs using their defined escape sequences (`\n`, `\t`) and also the `\N` representation for `NULL` values. The `tsv.un()` function returns a generator of lists of strings.

import tsv
import io

# Example TSV data string with escaped newline and tab
data_string = "col1\tcol2\nval1a\\nwithnewline\tval1b\\twithtab\nval2a\t\\N"

# Use io.StringIO to simulate a file stream
data_stream = io.StringIO(data_string)

# Parse the TSV stream to a generator of lists of strings
parsed_data = list(tsv.un(data_stream))

# Print the parsed data
for row in parsed_data:
    print(row)

# Output:
# ['col1', 'col2']
# ['val1a\nwithnewline', 'val1b\twithtab']
# ['val2a', '\N']

view raw JSON →