csvt — typed CSV for Python
Read CSVT files — CSV with a YAML front-matter schema — as zero-copy Apache Arrow data, and write Arrow data back to typed, diff-friendly text.
import csvt
import polars as pl
df = pl.from_arrow(csvt.reader("scores.csvt")) # zero-copy
df = csvt.polars.read("scores.csvt") # same data, cached as Parquet
csvt.write(df, "out.csvt", description="generated")
The package is a thin binding over the csvt-core Rust engine: the same
parser, schema merge and converter that power the csvt CLI. It is
library-only — use the CLI for command-line operations.
Install
The distribution is published as csvt-py; the import package is csvt.
pip install csvt-py # core (pyarrow)
pip install "csvt-py[polars]" # extras: polars, pandas, duckdb
From a checkout:
uv venv .venv
uv pip install --python .venv/bin/python maturin pyarrow
.venv/bin/maturin develop --manifest-path csvt-py/Cargo.toml
Requirements: Python ≥ 3.10, pyarrow ≥ 15 (Rust ≥ 1.85 when building from
source). Optional extras: polars, pandas, duckdb.
Platform wheels
The abi3 wheel is currently published for Linux x86_64 only. On macOS and
Windows, pip/uv falls back to the sdist and compiles the Rust extension, so you
need:
- Rust ≥ 1.85 (
rustup, with the host toolchain); - Windows: Visual Studio Build Tools with the "Desktop development with
C++" workload (this provides
link.exe, thekernel32.lib-style system libraries andcl.exefor the bundled zstd); - macOS: the Xcode command line tools (
xcode-select --install).
A C compiler is required on every platform because csvt-core's Parquet
dependency builds zstd from source.
To find out early that no wheel exists for your platform, ask for one:
pip install --only-binary=:all: csvt-py # fails clearly instead of compiling
Windows + git-bash (MSYS2) gotcha. git-bash ships a Unix link.exe in
/usr/bin; it shadows MSVC's linker, and the build fails with
link: extra operand / Try 'link --help' for more information. Install from
PowerShell or cmd.exe instead, or put MSVC's tools first in PATH:
Start menu -> "x64 Native Tools Command Prompt for VS 2022" -> pip install csvt-py
(the developer prompt puts MSVC's link.exe ahead of the MSYS2 one).
Quick start
import csvt
# Front-matter + resolved columns as a dict
info = csvt.get_schema("data.csvt")
info["csvt_version"] # "1.0"
[(c["name"], c["type"]) for c in info["columns"]]
# Zero-copy Arrow record batch reader
reader = csvt.reader("data.csvt") # pyarrow.RecordBatchReader
table = reader.read_all() # pyarrow.Table
Paths behave like the CLI: .csvt.gz / .csv.gz are decompressed
transparently, and a plain .csv picks up a sibling <file>.csvt.yaml
front-matter when present. Excel workbooks (.xlsx / .xlsm) are read too.
Read options
csvt.ReadOptions says where the schema comes from and how the body is laid
out; pass it as options= to reader, get_schema and every adapter:
import csvt
opts = csvt.ReadOptions(
schema=csvt.Schema( # ... or a path: schema="schemas/q1.yaml"
{"id": csvt.Column("int64", nullable=False), "score": "float64"}
),
sheet="Q1", # worksheet name or 0-based index
skip_rows=2, # banner rows above the header
has_header=True, # False -> names come from the schema
)
csvt.reader("report.xlsx", options=opts) # pyarrow.RecordBatchReader
csvt.polars.read("report.xlsx", options=opts) # cached Parquet
A Schema replaces the document's own front-matter, so it types a workbook
that carries no CSVT notes. csvt.Schema.from_schema_info(csvt.get_schema(path))
turns one file's resolved schema into a reusable object; ReadOptions are part
of the adapters' cache key, so two worksheets of one workbook get two caches.
Engines
csvt.reader() hands out a single-use stream, which makes it a poor fit for
repeated queries. The engine adapters parse the file once into a Parquet cache
and let the engine read that:
import duckdb
import csvt
csvt.polars.scan("data.csvt") # pl.LazyFrame — lazy, pushdown, reusable
csvt.polars.read("data.csvt") # pl.DataFrame
csvt.pandas.read("data.csvt") # pd.DataFrame
con = duckdb.connect()
csvt.duckdb.register(con, "data.csvt") # view named "data", stays queryable
con.sql("SELECT * FROM data WHERE score > 90").show()
All three share one Parquet file per source, so mixing them costs one parse.
Each adapter is imported on first use — import csvt does not pull in Polars,
Pandas or DuckDB.
API
| Function | Returns | Description |
|---|---|---|
csvt.reader(path, cache_path=None, *, options=None) |
pyarrow.RecordBatchReader |
Zero-copy stream of typed Arrow record batches (cached as Parquet) |
csvt.get_schema(path, *, options=None) |
SchemaInfo |
Front-matter and resolved columns |
csvt.validate(path, *, options=None, data=True) |
list[str] |
Every validation problem (empty = valid); data=False checks the schema only |
csvt.ReadOptions(*, schema=None, skip_rows=0, has_header=True, sheet=None) |
ReadOptions |
How a document is read (schema source, worksheet, header, skipped rows) |
csvt.Schema(columns, *, …) / csvt.Column(type, *, …) |
Schema / Column |
A typed front-matter / column definition |
csvt.Schema.from_schema_info(info) |
Schema |
Rebuild a schema from the dict get_schema() returns |
csvt.write(data, path, *, description=None, null_values=None, format=None) |
None |
Serialize Arrow-compatible data (PyArrow, Polars, Pandas) to CSVT (or JSON Lines, by extension) |
csvt.polars.scan(path, *, cache=None, options=None) |
polars.LazyFrame |
Lazy scan over the Parquet cache (predicate/projection pushdown) |
csvt.polars.read(path, *, cache=None, options=None) |
polars.DataFrame |
Eager read of the Parquet cache |
csvt.pandas.read(path, *, cache=None, dtype_backend=None, options=None) |
pandas.DataFrame |
Read the Parquet cache with pandas |
csvt.duckdb.register(con, path, *, name=None, cache=None, replace=False, options=None) |
str |
Create a view over the Parquet cache; returns the view name |
All of them raise csvt.CsvtError on parse, merge, validation or I/O errors.
Writing
import pyarrow as pa
table = pa.table({"id": [1, 2], "name": ["a", "b"]})
csvt.write(table, "out.csvt", description="generated")
# Anything implementing the Arrow PyCapsule stream protocol works
import polars as pl
csvt.write(pl.DataFrame({"x": [1, 2]}), "out.csvt")
The CSVT schema is derived from the Arrow schema (names, types, nullability),
so read → write → read round-trips values, types and nulls. Empty tables
keep their typed schema as a header-only file.
JSON Lines
Reading accepts both body syntaxes — csvt.reader() and csvt.get_schema()
handle .jsonlt (embedded front-matter) and plain .jsonl / .ndjson
(typed by a sibling <file>.jsonl.csvt.yaml). Writing picks the format from
the extension:
csvt.write(table, "out.jsonlt") # front-matter + one JSON object per row
csvt.write(table, "out.jsonl") # body only — no schema in the file
csvt.write(table, "out.txt", format="jsonlt") # explicit override
A .jsonl target cannot store description/null_values; passing either is
an error rather than a silent drop — write .jsonlt if you need them. v1
covers flat records: variant columns hold JSON text, and nested values are
rejected on read.
Caching
reader() always caches the parsed data as Parquet in
$TMPDIR/csvt-cache/. Pass cache_path to reuse a specific file — you own its
invalidation:
csvt.reader("data.csvt") # fresh temp file each call
csvt.reader("data.csvt", cache_path="data.parquet") # reuse this file
The engine adapters cache for you: one file per source, named after it, reused
while the source's size and modification time are unchanged and rebuilt when
they are not. Pass cache= to choose the directory (default
$TMPDIR/csvt-cache):
csvt.polars.scan("data.csvt", cache="cache") # cache/data-1a2b3c4d5e6f.parquet
See docs/caching.md for details and benchmarks.
Type checking
The package ships PEP 561 stubs (py.typed + core.pyi), so mypy --strict
and IDE completion work out of the box:
import csvt
info = csvt.get_schema("data.csvt") # csvt.core.SchemaInfo
name: str = info["columns"][0]["name"]
Documentation
Development
uv venv .venv
uv pip install --python .venv/bin/python maturin pyarrow pytest polars pandas duckdb mypy pyarrow-stubs pandas-stubs ruff
.venv/bin/maturin develop --manifest-path csvt-py/Cargo.toml
.venv/bin/pytest csvt-py/tests -v
.venv/bin/ruff format csvt-py
.venv/bin/ruff check csvt-py
License
MIT
Metadata
Release files for csvt-py 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| csvt_py-0.3.1.tar.gz | 209.8 kB | Without provenance | Details for csvt_py-0.3.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| csvt_py-0.3.1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for csvt_py-0.3.1-cp310-abi3-win_amd64.whl |
| csvt_py-0.3.1-cp310-abi3-manylinux_2_34_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.34+ x86-64 | Details for csvt_py-0.3.1-cp310-abi3-manylinux_2_34_x86_64.whl |
Total release size: 11.5 MB
Release files / csvt_py-0.3.1.tar.gz
| Download URL | csvt_py-0.3.1.tar.gz |
|---|---|
| Size | 209.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
169dc09d209ca95b06c0b51c8a7e93a84b873fda52ba2e21528be69b75f1020d
|
|
BLAKE2b-256 checksum How to use checksums |
d14a9d8f877319de6498095e8eab12954a0ba378884c301aa04f9467fe4cd94b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / csvt_py-0.3.1-cp310-abi3-win_amd64.whl
| Download URL | csvt_py-0.3.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6c630fa37ebf5e4ec195ae9fdefb5909bd08561d25059d3c16ea94ac517edc26
|
|
BLAKE2b-256 checksum How to use checksums |
a85453dd4da74a2c45251b3ba5de3939e385be532734b56a2b58f17413407a9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / csvt_py-0.3.1-cp310-abi3-manylinux_2_34_x86_64.whl
| Download URL | csvt_py-0.3.1-cp310-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a0dd1a746f60931717890b78db19586b6ab1bd26fe62754cea3aa68c51afb86a
|
|
BLAKE2b-256 checksum How to use checksums |
4cab735a688d33ea50d53615901cc233fc5a4814907f94d3fdfe0eb34c685406
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for csvt-py 0.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.