Skip to main content

threshio

Know a delimited file before your code reads it.

A CSV, TSV or pipe-delimited export arrives from somewhere you do not control. threshio says how it is written, what its columns hold, and whether its rows fit the schema you expect, value by value, with a stable code for everything that is wrong and the fix when there is one. Then it hands the rows that fit, and the rows that do not, to pyarrow, polars or DuckDB without a copy.

pip install threshio

No dependencies: the package carries libthresh, the C library of thresh, built for Linux (glibc and musl), macOS and Windows on x86-64 and arm64. Python 3.9 and later.

The files below are an invented orchard's harvest, from the repository's examples/data. Every block on this page is run by the package's tests, and its output compared with what is shown.

A first look

import threshio

print(threshio.sniff("data/harvest.csv"))

schema = threshio.infer("data/harvest.csv").schema
print(schema)

report = threshio.validate("data/harvest.csv", schema)
print(report)
data/harvest.csv: delimiter=, quote=" escape=doubled newline=lf header=yes confidence=high
Schema(lug_id int64, picked_on date, orchard_row string, lug_kg decimal, cultivar string, bruised bool, remark string)
pass  data/harvest.csv  40 rows  0 rejected

sniff reads the dialect and says how sure it is. infer reads every row and gives the schema the values fit. validate checks a file against a schema: yours, or one infer wrote. A schema is JSON (schema.save(path), threshio.Schema.load(path)), and every call that takes one also takes a dict, JSON text, a .json path, or columns inline: "lug_id:int64,lug_kg:decimal(5,2)".

A bad delivery

The same columns, with what goes wrong in a real feed:

report = threshio.validate("data/harvest_dirty.csv", schema)
print(report)
for line in report.rejected_lines:
    print(line.row, line.errors)
print(report.column("lug_kg").samples)
fail  data/harvest_dirty.csv  30 rows  4 rejected
5 [RowError(column='lug_kg', code='not_decimal')]
9 [RowError(column='picked_on', code='not_in_format')]
13 [RowError(column='bruised', code='not_bool')]
22 [RowError(column=None, code='ragged')]
[Sample(row=5, value='18,5', code='not_decimal')]

A file that fails is a report, not an exception: its result is pass, fail or error (it could not be read, or its dialect is not settled), and problems says why. Each column has its nulls, mismatches, conformance and statistics (report.column("lug_kg").stats: min, max, distinct values, the most common, their shapes).

Where code should not go on with a file that fails, check raises:

strict = schema.with_column("lug_id", nullable=False)
try:
    threshio.check("data/harvest_dirty.csv", strict)
except threshio.FileFailed as e:
    print(e)
    print(e.report.rejected_sample)
data/harvest_dirty.csv: fail: 5 of 30 rows rejected
[5, 9, 13, 17, 22]

Into pyarrow, polars and DuckDB

read opens the file and is itself an Arrow stream (the PyCapsule protocol), typed by the schema: decimals as decimal128, dates as date32, bools as bool. Nothing is copied on the way.

import pyarrow as pa

table = pa.table(threshio.read("data/harvest.csv", schema))
print(table.num_rows, table.schema.field("lug_kg").type)

reader = threshio.read("data/harvest_dirty.csv", schema, rejects=True)
good, bad = pa.table(reader), pa.table(reader.rejects)
print(good.num_rows, bad.num_rows, bad.column("_errors")[0])
print(reader.report())
40 decimal128(18, 1)
26 4 [{'column': 'lug_kg', 'code': 'not_decimal'}]
fail  data/harvest_dirty.csv  30 rows  4 rejected

polars.DataFrame(threshio.read(...)) takes it the same way, and in DuckDB a Reader is a table:

import duckdb

harvest = threshio.read("data/harvest.csv", schema)
print(duckdb.sql("select cultivar, count(*) from harvest group by 1 order by 2 desc, 1 limit 2").fetchall())
[('Brookwood', 10), ('Ember Pip', 9)]

With no schema, read infers one from the file first. A Reader is read once; rejects=True keeps the rows that did not fit, with _row, _errors and _extra, for a stream of their own.

When thresh knows the fix

A file thresh cannot read says why, with a code, and the fix when there is one, as options to call again with:

first = threshio.infer("data/windows.csv")
problem = first.files[0].problems[0]
print(problem.code, problem.fix)

again = threshio.infer("data/windows.csv", **problem.fix)
print(again.ok)
column_not_utf8 {'encoding': 'cp1252'}
True

The message names the command line's flags; fix is this package's options. Every code is listed in PROBLEMS.md.

For an AI

describe is everything thresh can say of a file in one bounded document. With shapes_only=True it holds none of the file's values (digits become 9, letters a), so it can go to an AI, or into an issue:

d = threshio.describe("data/harvest_dirty.csv", shapes_only=True)
print(d.rejected_lines[0].text)
print([(c.name, c.stats.shapes[0].value) for c in d.columns[:3]])
prompt = "Write a loader for this file.\n\n" + d.to_json()
9,a,9-9-9,a9,9.9,a a,a,a 9
[('lug_id', '9'), ('picked_on', '9-9-9'), ('orchard_row', 'a9')]

Options

Every call takes the same keyword options, each the command line's flag of the same name; a call ignores those it has no use for. Left out (or None), the sniffer settles the dialect and nothing else changes.

Option Value
delimiter, comment one character, as "," or "\t"
quote one character, or False for none
escape "doubled" or "backslash"
newline "lf", "crlf" or "cr"
header True or False
encoding "utf8", "latin1" or "cp1252" (UTF-16 is told by its byte order mark)
nulls a list of strings read as null in every column
ragged "pad" or "truncate" a short or long row, rather than reject it
threshold the fraction of a column's values (and of rows) that must fit
strict extra columns, ragged rows and ambiguous dates fail the file
day_first ambiguous dates read day first
keep_empty an empty line is a one-field record
sample_bytes the sniffer's first window
sample_rows, jobs infer: the first rows only; files read at once
shapes_only, shape_names values (and names) as shapes in what comes back
mmap False reads through a buffer, not a mapping
cancel a threshio.Cancel: .set() from another thread stops the call

A sniffed dialect pins the next file the same way: threshio.validate(path, schema, **sniff.dialect.options).

What comes back

Call Returns
sniff(path) Sniff: dialect, warnings, problems, ok
infer(*paths) Inference: schema, each file's outcome and notes, problems, ok
columns(spec) Schema from the inline form
validate(path, schema) Report: result, rows, columns, rejected_lines, problems, passed
check(path, schema) the Report, or FileFailed with it
describe(path, schema=None) Description: a Report with every column's statistics, the schema, the encoding
read(path, schema=None, rejects=False) Reader: an Arrow stream of rows, .rejects, .report()

Every result has to_json(), the document thresh wrote (REPORT.md), and raw, the same as a dict.

Exceptions are for the call, not the file: ArgumentError (a call made wrongly), SchemaError, ReadError (reading failed partway), Interrupted (a cancel), all threshio.Error; and FileFailed from check and from read of a file it cannot read.

Calls release the GIL and use a handle of their own, so threads may call at once; infer reads several files on threads of its own. A Reader is used from one thread at a time.

More

Whole scripts, each with its output: examples/python. Apache-2.0.

Metadata

Release files for threshio 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for threshio 0.3.0
File Actions
threshio-0.3.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for threshio-0.3.0-py3-none-win_arm64.whl
threshio-0.3.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for threshio-0.3.0-py3-none-win_amd64.whl
threshio-0.3.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for threshio-0.3.0-py3-none-musllinux_1_2_x86_64.whl
threshio-0.3.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details for threshio-0.3.0-py3-none-musllinux_1_2_aarch64.whl
threshio-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for threshio-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
threshio-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for threshio-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
threshio-0.3.0-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for threshio-0.3.0-py3-none-macosx_13_0_x86_64.whl
threshio-0.3.0-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for threshio-0.3.0-py3-none-macosx_13_0_arm64.whl

Total release size: 3.5 MB

Release files / threshio-0.3.0-py3-none-win_arm64.whl

Download URL threshio-0.3.0-py3-none-win_arm64.whl
Size 442.3 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
1e1b1690996804f6371f46ad3a548da624d0abe822be8c9e2dda773853842830
BLAKE2b-256 checksum
How to use checksums
5dbad241fb08c51d8a1b264cc480da7f767e88c754844607bd8f136262a03d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-win_amd64.whl

Download URL threshio-0.3.0-py3-none-win_amd64.whl
Size 499.1 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
89afc614c9570ba1e21ca0b5bf17d494563b866fa064e0c84242edbfa4f5f1cb
BLAKE2b-256 checksum
How to use checksums
21286341c74c46f40da78ebe59e061a9ff8d4052c82bb448763459119a5142d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-musllinux_1_2_x86_64.whl

Download URL threshio-0.3.0-py3-none-musllinux_1_2_x86_64.whl
Size 459.5 kB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
f53c8f8fee866f2b6fe7a4f9ab4e085bfbca72979776b0ab6f8f192aebc004da
BLAKE2b-256 checksum
How to use checksums
8f85147f4503fb16f29f3e440c4cbbaa56c25f82e36c37d0aab5b515ca4faf75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-musllinux_1_2_aarch64.whl

Download URL threshio-0.3.0-py3-none-musllinux_1_2_aarch64.whl
Size 430.8 kB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
3f666de71bad476b23164a1c20ec0d4a3cb19ad629f9ac784110f142a5f96bc2
BLAKE2b-256 checksum
How to use checksums
457a772baf23b64cc52d835e5f5dd1919f264522125ee0b1db5944cc8dc75b64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL threshio-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 447.8 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
f6dc4434a82b014a359b959728cefdc125fcf95c03a7901cd12403913371a116
BLAKE2b-256 checksum
How to use checksums
62c6a98ee350b921fd32bb5c62ac511d3f2a4eaeca20567821ddfa0fff910a80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL threshio-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 418.5 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
42a484bd1b2a410e797525ff9c16b3736ad852bbda485e2dca4a6333b2bce9b3
BLAKE2b-256 checksum
How to use checksums
501dd4b2d5ae62a67c4e55b148b9a3f4f1b1f9bf6c956909b19fce6fa080c02f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-macosx_13_0_x86_64.whl

Download URL threshio-0.3.0-py3-none-macosx_13_0_x86_64.whl
Size 425.6 kB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
8ee67985ab68b40e5d408cec2a89a08d1ae310baca12302b7891ee8050b16909
BLAKE2b-256 checksum
How to use checksums
d6a164b6dab337fc4d761f77b9b79da40138e3d9db9f10fec09b30a5557f36a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / threshio-0.3.0-py3-none-macosx_13_0_arm64.whl

Download URL threshio-0.3.0-py3-none-macosx_13_0_arm64.whl
Size 398.1 kB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
8369b0864c2d21274dcc9594c211f4969917703d825b3992cdc77612c2d08890
BLAKE2b-256 checksum
How to use checksums
3e02d5d75877525852e53f411040553b9cb50603343d86e72f61a32507df5399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for threshio 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for threshio-0.3.0-py3-none-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page