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)

Use an extracted IVT version 4 file. For a download, pass the complete IVT bytes to pyivt.open().

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() returns an Ivt. It accepts a path, IVT bytes, a bytearray, an object with __bytes__, or a binary file object.
  • 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.9

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.9
File Size Uploaded Provenance Actions
pyivt-0.0.9.tar.gz 649.4 kB With provenance Details for pyivt-0.0.9.tar.gz

Built distributions (wheels)

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

Total release size: 10.7 MB

Release files / pyivt-0.0.9.tar.gz

Download URL pyivt-0.0.9.tar.gz
Size 649.4 kB
Tags Source
SHA-256 checksum
How to use checksums
43895316b0c6a4f859086c4dcfe4874992ef992874252b0746ee8e7edeaf6c9c
BLAKE2b-256 checksum
How to use checksums
abe1902d124f916f84a8740f16d5af917c9745c453e1976d13578b5e37db34ce
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 6, 2026.

Transparency log

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

Download URL pyivt-0.0.9-cp310-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
dc24c988a0b57358eb9d53db589cf19b637fc7d38f464855eb687b6ec661b8a6
BLAKE2b-256 checksum
How to use checksums
ab623bb9a2cd49881ffc463610ab9d7229c99792f43ae7505b5b08be0623e7be
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 6, 2026.

Transparency log

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

Download URL pyivt-0.0.9-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
e1cc7b2dd43b9f222cbf0f441fd1b5a929f2376bdb677f81b9a858db475868ae
BLAKE2b-256 checksum
How to use checksums
a54affaf340c3115c95ebe8bcc383683fef330434fcb0a5dcdd45420df043372
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 6, 2026.

Transparency log

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

Download URL pyivt-0.0.9-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
4738266b638c366909b4b5121dcd99d0e7add3e1f7a9bda0b4f92672149aa2c7
BLAKE2b-256 checksum
How to use checksums
ef309a262f2c86a6c120462bcbd7048221bbc6786adbc2c4e03f1d5d9eb219c4
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 6, 2026.

Transparency log

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

Download URL pyivt-0.0.9-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
9160417fe1e61697e6af40bd6533e0caabbf681b08f818d7a0e06f59027c0edc
BLAKE2b-256 checksum
How to use checksums
a82a7105e45c3211ef062986bdf775bd652ff716ac831453152d334d76d909b9
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 6, 2026.

Transparency log

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

Download URL pyivt-0.0.9-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
5919431dd08842f3d6d0ea7abdad541aede538b456e1c7253291ebe76e62b599
BLAKE2b-256 checksum
How to use checksums
7d603efe18d601afeee9432e0a0904436829c86640a11daeec23a416988907bd
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 6, 2026.

Transparency log

Security for pyivt 0.0.9

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.9.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 6, 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