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.2.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.2.0
File Actions
threshio-0.2.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for threshio-0.2.0-py3-none-win_arm64.whl
threshio-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for threshio-0.2.0-py3-none-win_amd64.whl
threshio-0.2.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for threshio-0.2.0-py3-none-musllinux_1_2_x86_64.whl
threshio-0.2.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details for threshio-0.2.0-py3-none-musllinux_1_2_aarch64.whl
threshio-0.2.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.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
threshio-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for threshio-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
threshio-0.2.0-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for threshio-0.2.0-py3-none-macosx_13_0_x86_64.whl
threshio-0.2.0-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for threshio-0.2.0-py3-none-macosx_13_0_arm64.whl

Total release size: 3.5 MB

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

Download URL threshio-0.2.0-py3-none-win_arm64.whl
Size 436.8 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
fa806ab315d60dda4efa2d27ec2b72668cb5c1951c5b353f083669b80d3d0227
BLAKE2b-256 checksum
How to use checksums
312d3749c059926f7363e5ef146045d99e472baa817f4fc096ce3f2091cc5c8e
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-win_amd64.whl
Size 493.1 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
91038cf59d30cfc491627fd3366214320364b19282d3de399d3a95981bce5c60
BLAKE2b-256 checksum
How to use checksums
c2a58489dfa1dc77d1b304da8c38cc84516dacc64e590286a3ce94365b60984c
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-musllinux_1_2_x86_64.whl
Size 453.4 kB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
9beda316fd040441691752eb026d44da346cb2b247c149ba3bccbc262ba8bb69
BLAKE2b-256 checksum
How to use checksums
449de5eab649dc0b56a443da77e403cf16d5e40a1d60b7dacd23a8b06fdad912
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-musllinux_1_2_aarch64.whl
Size 425.1 kB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
48aa172a1aabf36375dd93e8e22d29aa54953b93ddaa52152c4945eeb1a4dbb6
BLAKE2b-256 checksum
How to use checksums
aed110b7a7da99ba60320210c78cad406df7db1258ab26a23d01e3eba769be39
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 441.0 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
c4dc8c7499b69125461384816649ec45c0b9100e3fc92b9a90b2471bf47799ff
BLAKE2b-256 checksum
How to use checksums
cf5e37f32048afb8ba684139a6b98e36230e2b9bb50b67d1fc69fbd33a8fb4e1
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 412.8 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
e068deef3d199326cd702667936f8295d16a5a27c4e740400b1432f7f34f1997
BLAKE2b-256 checksum
How to use checksums
59fa6191d8f7ab440b252fd7045484d1ae4073dedafb11afc4943f4327edb41a
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-macosx_13_0_x86_64.whl
Size 421.9 kB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
348d810e66ff56ddba1424b908a5f1c08eae8fc1fb71f7f3d032f6334fe40a9f
BLAKE2b-256 checksum
How to use checksums
3c5aa5c9dab29913f32800dde10149c4296305c1ae487ba86a1a66b2b8abeb0a
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 2, 2026.

Transparency log

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

Download URL threshio-0.2.0-py3-none-macosx_13_0_arm64.whl
Size 392.3 kB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
c44db76c161c4855eadaf7e23b5ca750137a409bf6ab796d63d5939016b0616a
BLAKE2b-256 checksum
How to use checksums
fc3c80d059fb5e61dab4a896660a89649aed4e8620a232c9fe77d12225a08bf5
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 2, 2026.

Transparency log

Security for threshio 0.2.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.2.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 2, 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