Skip to main content

pyivt

About the Project

Read Statistics Canada Beyond 20/20 (.ivt) files, inspect bilingual metadata, and export to Apache Arrow or Parquet.

Getting Started

Prerequisites

Python 3.11+ and PyArrow 14+. Installation brings in PyArrow automatically. PyArrow 14 has wheels for Python 3.11 and 3.12 only; newer Pythons need a newer PyArrow (18+ for 3.13, 22+ for 3.14, 26+ for 3.15).

Supported platforms

pyivt publishes one abi3 wheel per platform, which installs on CPython 3.11 and every later version. Each wheel is installed and smoke-tested on its own platform on Python 3.11 and 3.15 before release, and the test suite runs on Linux, Windows and macOS with Python 3.11, 3.14 and 3.15.

OS Architectures Wheel tag
Linux (glibc 2.28+) x86_64, aarch64 manylinux_2_28
Linux (musl 1.2+, e.g. Alpine) x86_64, aarch64 musllinux_1_2
Windows x64 win_amd64
macOS x86_64, arm64 macosx

Not supported for now:

  • Windows on ARM64. No wheel is published. Installing from the sdist needs a Rust toolchain and is untested.
  • Free-threaded CPython (3.14t, 3.15t). It would need a newer PyO3 and separate non-abi3 builds.
  • Python 3.10 and older. Python 3.10 reached end of life in October 2026.

Other platforms can try the sdist, which needs a Rust toolchain to build.

Installation

pip install pyivt

With uv, run uv add pyivt.

Editor type hints

To see pyarrow.Table as the return type of ivt.to_arrow() and ivt.to_member_table() in your editor, install pyarrow-stubs in the same Python environment as pyivt and select that environment in your editor.

pip install pyarrow-stubs

Usage

Open a table

import pyivt

ivt = pyivt.open("data.ivt")
print(ivt.metadata.title.en or ivt.metadata.title.fr)

Pass an IVT file or a StatCan ZIP download as a path or complete bytes. A ZIP containing exactly one .ivt member opens automatically. If it contains several, choose one with pyivt.open("tables.zip", member="folder/table.ivt"); the member name is exact and case-sensitive. ZIP tables are streamed to a private temporary file, which is removed when the reader and its metadata are released. Opening parses metadata; exports decode the cells.

Container versions 2 and 4 are supported. Version 2 includes historical survey, agriculture, and Business Patterns tables with sparse member slots and older bilingual display fields. Version 3 remains explicitly unsupported because no real sample was found in the historical archive search. The legacy verification report records the tested files and comparison limits.

Inspect dimensions

for dimension in ivt.metadata.dimensions:
    print(dimension.slug, dimension.name.en, dimension.items)

Use the slugs as Arrow column names, select keys, and values in the member table's dimension column. The geography axis uses geography. Other axes follow their full IVT dimension titles, so a time dimension may be named census_year, reference_period, or time. IVT files store axis names cut to 15 characters; pyivt takes the full English and French titles from the table notes' variable list when the file has one, so Population and becomes Population and dwelling counts (11) and its slug population_and_dwelling_counts_11. Slugs are at most 40 characters.

Export to Parquet

import pyarrow.parquet as pq

table = ivt.to_arrow()
members = ivt.to_member_table()
pq.write_table(table, "data.parquet")
pq.write_table(members, "data.members.parquet")

To attach geography labels, filter the member table by dimension and cast code to the fact column's type before joining.

import pyarrow.compute as pc

lookup = members.filter(pc.equal(members["dimension"], "geography"))
lookup = lookup.select(["code", "label"])
lookup = lookup.set_column(0, "code", lookup["code"].cast(table["geography"].type))
labeled = table.join(lookup, keys="geography", right_keys="code")

Select a subset

On a table with geography and census_year, fix geography and keep two years.

selection = {"geography": 2, "census_year": [1, 2]}
table = ivt.to_arrow(select=selection)
members = ivt.to_member_table(select=selection)

Use Dimension.slug when the dimensions depend on the input file.

slug = ivt.metadata.dimensions[0].slug
subset = ivt.to_arrow(select={slug: [1]})
subset_members = ivt.to_member_table(select={slug: [1]})

Both methods select by the members' 1-based positions in the file. An integer fixes a dimension at one member and omits it from both outputs. A list retains the dimension and limits its members to the given codes. Omitted dimensions retain all members. An empty list gives zero fact rows and zero member rows for that dimension.

Passing dimensions as keyword arguments, as in to_arrow(geography=2), is deprecated: it still works for now but emits a DeprecationWarning.

Pivot industry by occupation with Polars

On a table with geography, labour_force, industry, and occupation dimensions, fix geography and labour force to get one value for each industry and occupation pair. With Polars installed, pivot the Arrow result into one row per industry and one column per occupation code.

import polars as pl

table = ivt.to_arrow(select={"geography": 5, "labour_force": 1})
pivoted = pl.from_arrow(table).pivot(
    on="occupation",
    index="industry",
    values="value",
)

Generate Python types for a table

pyivt codegen data.ivt --output dimensions.py

The generated module contains one IntEnum per dimension and a Dimensions typed dictionary to pass as select. Enum values are 1-based member positions. Use enum members as codes when calling to_arrow() or to_member_table(), for example ivt.to_arrow(select=Dimensions(geography=[Geography.CANADA])). NATIVE_CODES[slug][member] gives the original code as text, or None if it is missing. Add --language fr to use French labels for enum names.

API Reference

The full reference, including every public name, the stability policy and the parts still planned before v0.1.0, is in docs/api.md. The public API is exactly pyivt.__all__ plus pyivt.__version__; names that start with an underscore are private.

Opening and exporting

  • open(source, *, member=None) returns an Ivt. It accepts a path, IVT or ZIP bytes, a bytearray, an object with __bytes__, or a binary file object. member selects an IVT inside a ZIP with several tables.

  • to_arrow() returns rows in file order with unsigned member codes and a nullable float64 column named value. It builds the whole table at once, so the result plus one copy of the file must fit max_memory_bytes (an estimate in bytes, 2 GiB by default); larger exports raise pyivt.ResourceLimitError. Raise the limit with to_arrow(max_memory_bytes=8 * 2**30), or stream the table.

  • iter_batches(*, select=None, batch_size=1_048_576, max_memory_bytes=2**31) streams the same table as a pyarrow.RecordBatchReader. It takes the same select, keeps file order, and has the same schema and metadata, so its batches concatenate to to_arrow(select=...). Batches are decoded on demand without the GIL, so memory stays near one copy of the file plus two batches. Use it for tables too large to materialize:

    import polars as pl
    import pyarrow.parquet as pq
    
    with ivt.iter_batches() as reader:
        with pq.ParquetWriter("table.parquet", reader.schema) as writer:
            for batch in reader:
                writer.write_batch(batch)
    
    frame = pl.DataFrame(ivt.iter_batches(select={"geography": [1, 2]}))
    

    The full 126,198,000-row 98100532 table (208 MB file) streams in about 3 seconds with a peak working set under 300 MB.

  • Both exports decode values in parallel without the GIL. By default they use one worker per hardware thread. Set the RAYON_NUM_THREADS environment variable before the first export to use fewer, for example RAYON_NUM_THREADS=1 in each process of a multi-process job. The output is the same for any number of workers.

  • Exports from a path memory-map the file, so a selection reads only the pages it needs. Do not modify or truncate the file while an export or stream uses it: on Unix, truncating a mapped file ends the process. Set PYIVT_MMAP=0 to read the whole file into memory instead.

  • to_member_table() returns one PyArrow table of member attributes, without decoding cells.

  • pyivt.__version__ gives the installed package version, read from the package metadata.

Errors

Files that cannot be read raise a subclass of pyivt.IvtError. IvtError subclasses ValueError, so except ValueError still catches every parse error.

Exception Raised when Also a
pyivt.CorruptFileError The file is truncated, its signature or header is damaged, or a record or directory points outside the file. IvtError
pyivt.UnsupportedFormatError The file is an IVT, but its container version, descriptor, or record layout is not supported. IvtError
pyivt.ResourceLimitError A memory estimate exceeds a safety limit. Narrow the export with select, raise max_memory_bytes, or stream it with iter_batches(). IvtError, MemoryError

Messages lead with a plain explanation (Corrupt IVT file: ... or Unsupported IVT file: ...). Each exception also has location attributes, which are None when not known: offset, length, and file_len (bytes), slot (header slot), entry (directory entry), and dimension (zero-based axis). ResourceLimitError adds estimate and limit in bytes.

try:
    ivt = pyivt.open("table.ivt")
except pyivt.CorruptFileError as error:
    print(f"damaged at byte {error.offset} of {error.file_len}: {error}")
except pyivt.UnsupportedFormatError as error:
    print(f"not supported: {error}")

An unreadable path still raises OSError. Invalid arguments, such as an unknown dimension name in to_arrow(), raise ValueError.

Member lookup table

  • dimension is the first column and contains dictionary-encoded dimension slugs. Rows follow dimension order and then member order in the IVT file.
  • code contains 1-based member positions. The member table uses one unsigned integer type wide enough for the source table's largest dimension. Each fact column still uses the width of its own dimension.
  • label is a nullable string in English by default. Use to_member_table(language="fr") for French labels. Time-axis labels use ISO dates.
  • Native attributes use Arrow strings, integers, floats, or date32 dates. The native Code field, when present, is a separate text column (typically native_Code) and preserves leading zeros and duplicate values. Attributes are null where they are absent. Names that collide with dimension, code, or label receive a native_ prefix. Incompatible attributes with the same name receive numeric suffixes.
  • Export schemas use pyivt.dimension_encoding=one_based_index. The fact schema and member exports with retained dimensions also carry pyivt.table_id to identify the source table. It is a SHA-256 over the file's length, its metadata (header, members, labels, notes and legends) and its value page directory, so to_arrow() and to_member_table() carry the same ID for the same file without reading value pages. It is not the SHA-256 of the file bytes. Use it to match a member table with its fact table, not to check a file's integrity.

Metadata

meta = ivt.metadata
print(meta.title.en, meta.title["fr"])
print([(dimension.slug, dimension.items) for dimension in meta.dimensions])

Read-only IvtMetadata is available without decoding cells.

  • title, author, category, keywords, and notes use LocalizedText.
  • Table fields include product_id, universe, number_of_datapoints, version, signature, and read_only.
  • Time fields are frequency, start_date, and end_date. Known frequencies are "monthly", "quarterly", "semi_annual", and "annual".
  • Both LocalizedText and LocalizedLabels accept en and fr. Missing translations are None.

Dimensions and legends

  • Each Dimension in meta.dimensions has slug, name, description, notes, items, and members. Its type is "geographic", "normal", or "time_series".
  • meta.geographies returns Geographies with member_id, geo_label, geo_name, geo_uid, dqf_code, and tnr_short_form.
  • Each Footnote in meta.footnotes has symbol, number, and description.
  • Each MissingValue in meta.missing_values has symbol, description, and code.

License

MIT

Acknowledgments

Metadata

Release files for pyivt 0.0.11

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

Source distribution (sdist)

Source distribution for pyivt 0.0.11
File Size Uploaded Provenance Actions
pyivt-0.0.11.tar.gz 1.6 MB With provenance Details for pyivt-0.0.11.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyivt 0.0.11
File Actions
pyivt-0.0.11-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for pyivt-0.0.11-cp311-abi3-win_amd64.whl
pyivt-0.0.11-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for pyivt-0.0.11-cp311-abi3-musllinux_1_2_x86_64.whl
pyivt-0.0.11-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for pyivt-0.0.11-cp311-abi3-musllinux_1_2_aarch64.whl
pyivt-0.0.11-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details for pyivt-0.0.11-cp311-abi3-manylinux_2_28_x86_64.whl
pyivt-0.0.11-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for pyivt-0.0.11-cp311-abi3-manylinux_2_28_aarch64.whl
pyivt-0.0.11-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for pyivt-0.0.11-cp311-abi3-macosx_11_0_arm64.whl
pyivt-0.0.11-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for pyivt-0.0.11-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 14.1 MB

Release files / pyivt-0.0.11.tar.gz

Download URL pyivt-0.0.11.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
b41fabc806714047227259079d7a3a155c2b8c6eb0c7e3c9171f8bb5cb81f234
BLAKE2b-256 checksum
How to use checksums
d32e1811629dd0159b10f85d078ad27969cf42e024dd0547f2e43010a7f4de38
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-win_amd64.whl

Download URL pyivt-0.0.11-cp311-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
740254b69ed60db76e8ca39f1c12b50f521ba995307e631e665159ae9ea846d9
BLAKE2b-256 checksum
How to use checksums
390f5b6f379ed18808aba55761d721c5f43f1279ce988ff763fc321dda1882d3
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pyivt-0.0.11-cp311-abi3-musllinux_1_2_x86_64.whl
Size 2.0 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
31d9f971379d886c6c097f5b9e9c74e27a3a33d5f75efe5e28e44dad321c991e
BLAKE2b-256 checksum
How to use checksums
35c823dc72fbf5acc1aed9bdc601891fd54234626ddcfeecf8130acff9b4fed8
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pyivt-0.0.11-cp311-abi3-musllinux_1_2_aarch64.whl
Size 1.9 MB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
7e699d82cf89302629bf2dca7fd8ab045ecea328db5060195bccca2691914e75
BLAKE2b-256 checksum
How to use checksums
1497a74ce7a632e8f182b935c48775e1454c61ed77bee21e90a1a308f34f781d
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL pyivt-0.0.11-cp311-abi3-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
51bd43b1c87b07cb3598c97433fe32701a0e59b33ab89a391b053817c12597f2
BLAKE2b-256 checksum
How to use checksums
fa36c945996859de5a45ed1b7e98629ceebbbcb123f25eab2b43dc749ec1122d
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL pyivt-0.0.11-cp311-abi3-manylinux_2_28_aarch64.whl
Size 1.7 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
50791123332083179e52943e39cac5050931acb282252e26768fa8a9b83c8a31
BLAKE2b-256 checksum
How to use checksums
563c26b495c0ecffeadf686eaf75350158265f7f6c4bcc15e8a714215b1a2abe
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-macosx_11_0_arm64.whl

Download URL pyivt-0.0.11-cp311-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
df2258d2b086ef35d27944967aa6fdad442119a2d7939c88b50805aeba4c0948
BLAKE2b-256 checksum
How to use checksums
42274530afb33428bb3b13aca57040e75af9243365e3add22c00ed75a9c9dbcb
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 16, 2026.

Transparency log

Release files / pyivt-0.0.11-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pyivt-0.0.11-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.7 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
42ef4c0e55a4a92b8d916d415dc0046a9526a8b52afa1959e9c1a786d34036ba
BLAKE2b-256 checksum
How to use checksums
e1be357fa97bba91ce73a38ad3e75a0e0dc4fe1b8f4b099179a063ae6c37329a
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 16, 2026.

Transparency log

Security for pyivt 0.0.11

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 pyivt-0.0.11.tar.gz

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 16, 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