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.1

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

Total release size: 3.5 MB

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

Download URL threshio-0.2.1-py3-none-win_arm64.whl
Size 439.1 kB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
9817c6ddad560010f2c6ceb11712e69bf1ac5d362b8b69c02a2dafe5a03a2fb5
BLAKE2b-256 checksum
How to use checksums
df50670550160362ce6ca03ab6386e6d36c534ee4c317c5d9313f805ee73a369
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.2.1-py3-none-win_amd64.whl

Download URL threshio-0.2.1-py3-none-win_amd64.whl
Size 496.0 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
a0bbf5edf6e75af2525346a77d63053ada4ecc6551ae0e956a20c9fc4281f3d5
BLAKE2b-256 checksum
How to use checksums
434f146c29a7ffd5aa79acd65dd9ef2de846efa385a08c1f037b6ac3e39b8f24
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.2.1-py3-none-musllinux_1_2_x86_64.whl

Download URL threshio-0.2.1-py3-none-musllinux_1_2_x86_64.whl
Size 455.7 kB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
2c58f01d24dad1735895e72962cc41b1c13e5e1c1814dcdcd6e6241f386a3b76
BLAKE2b-256 checksum
How to use checksums
fe497270d6cb13fa2827b6524a950d5508ffe9f592eb2b68fcdd829494af568b
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.2.1-py3-none-musllinux_1_2_aarch64.whl

Download URL threshio-0.2.1-py3-none-musllinux_1_2_aarch64.whl
Size 427.3 kB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
56b6f939097560f191bbb809bb2d62a9986a2da2f7004b19963bd73c7137a4ae
BLAKE2b-256 checksum
How to use checksums
4575661a7569051d9b168bef0718f0e95dd0883b2d142a3be15bb6a84719b127
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.2.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL threshio-0.2.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 443.9 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
c782e5ab8170a2711e66d24d87c8a070aa6903bbaa3dee764ee30f98a302784a
BLAKE2b-256 checksum
How to use checksums
14129825274dc1abaa69ff6e685c34ab5ca2cb8a3e782c4dc5b89d2dda82bd55
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.2.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL threshio-0.2.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 415.0 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
249e3a8afaf05a00d2c4e78c420194e5c7d739f609f86c37f23fd85caea672a5
BLAKE2b-256 checksum
How to use checksums
c918002efb98afef848c97bb272d95f9937ccc6de774eaaca74ac750acaed0b9
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.2.1-py3-none-macosx_13_0_x86_64.whl

Download URL threshio-0.2.1-py3-none-macosx_13_0_x86_64.whl
Size 424.7 kB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
61e7fcad6c80b42c7119b277d9f246ec04e7c99add19cf96b445756b13df8876
BLAKE2b-256 checksum
How to use checksums
657ba66e937bec93452001ff2390e36ce6cf079ae659550215b3ae91f18b36fe
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.2.1-py3-none-macosx_13_0_arm64.whl

Download URL threshio-0.2.1-py3-none-macosx_13_0_arm64.whl
Size 394.8 kB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
a55be02a2d65d79b7afeeda5f5585c3c30cdfe5263583c3f3230cfa0c5d9f8df
BLAKE2b-256 checksum
How to use checksums
07b2c32ab00c5b8c68bc42d646f05ca766af7bb9f62efb269fac926c2af57dd7
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.2.1

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.1-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