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.10+ and PyArrow 14+. Installation brings in PyArrow automatically.

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, selection keywords, and values in the member table's dimension column. The geography axis uses geography. Other axes follow their IVT dimension names, so a time dimension may be named census_year, reference_period, or time.

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.

table = ivt.to_arrow(geography=2, census_year=[1, 2])
members = ivt.to_member_table(geography=2, census_year=[1, 2])

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

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

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.

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(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 for selection keywords. Enum values are 1-based member positions. Use enum members as codes when calling to_arrow() or to_member_table(). 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

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.
  • to_member_table() returns one PyArrow table of member attributes, without decoding cells.
  • pyivt.__version__ gives the package version.

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.

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

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.10
File Size Uploaded Provenance Actions
pyivt-0.0.10.tar.gz 1.6 MB With provenance Details for pyivt-0.0.10.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyivt 0.0.10
File Actions
pyivt-0.0.10-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for pyivt-0.0.10-cp310-abi3-win_amd64.whl
pyivt-0.0.10-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for pyivt-0.0.10-cp310-abi3-manylinux_2_28_x86_64.whl
pyivt-0.0.10-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for pyivt-0.0.10-cp310-abi3-manylinux_2_28_aarch64.whl
pyivt-0.0.10-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for pyivt-0.0.10-cp310-abi3-macosx_11_0_arm64.whl
pyivt-0.0.10-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for pyivt-0.0.10-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 11.7 MB

Release files / pyivt-0.0.10.tar.gz

Download URL pyivt-0.0.10.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
f3b214fc1a20a57c79377437181a3c44b7f544f479fb4e7acc0fec2414fc8e76
BLAKE2b-256 checksum
How to use checksums
9f893d89ae9167d2ededb86a439541f9b3ff5da47a56dddd64a0e440cf2104f0
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 10, 2026.

Transparency log

Release files / pyivt-0.0.10-cp310-abi3-win_amd64.whl

Download URL pyivt-0.0.10-cp310-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
78b5dd8bbeecf66a1a41728cdf4a0ba3f560decee66bd78e09f2c69bb7024c12
BLAKE2b-256 checksum
How to use checksums
b6e3f88b3edcd65fad1f030f7a7fa21a190eb9e7d8930638754e0d36855e9fab
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 10, 2026.

Transparency log

Release files / pyivt-0.0.10-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL pyivt-0.0.10-cp310-abi3-manylinux_2_28_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
c476e2c09ee255271cb53789c571909221ab617809054b303ae5339c872ae035
BLAKE2b-256 checksum
How to use checksums
187f3683ac036a59853245c7694fd3ab30c4b90f08ebbd4fa7f6d77926bcf9e4
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 10, 2026.

Transparency log

Release files / pyivt-0.0.10-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL pyivt-0.0.10-cp310-abi3-manylinux_2_28_aarch64.whl
Size 2.2 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
ca9dc857101f7d1a682b4e5ad9c9778a2ac6e168ec39f596e5f1be83ac4b18c1
BLAKE2b-256 checksum
How to use checksums
205f5bf38bc66f09f3eb6cd236a9e258131dc2c61037808b4a8c0947bf0f14eb
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 10, 2026.

Transparency log

Release files / pyivt-0.0.10-cp310-abi3-macosx_11_0_arm64.whl

Download URL pyivt-0.0.10-cp310-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1edd7de7fcb5f12839b090a1b77dd23e96006cb655fc772f1a435cb1d518df7e
BLAKE2b-256 checksum
How to use checksums
578c78d14af6d8186452adf1c6f9874ee1aa21b02e98bca14201904e221b9e11
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 10, 2026.

Transparency log

Release files / pyivt-0.0.10-cp310-abi3-macosx_10_12_x86_64.whl

Download URL pyivt-0.0.10-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9f7d6e77a9badf9f1640437feb6d4abac62112b73b249b2962fda7be8a04483c
BLAKE2b-256 checksum
How to use checksums
5058b1ea2139d8f77246881c124d0852a0dec6647e01096be86cfbd3af185124
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 10, 2026.

Transparency log

Security for pyivt 0.0.10

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 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pyivt-0.0.10.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 10, 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