Skip to main content

statcan-dl

Takes a local snapshot of Statistics Canada's health tables — all 400-odd of them — and leaves you with Parquet files you can open in pandas.

This is not a query API. It mirrors what StatCan publishes to your disk in one shot: no API key, no auth, no rate limits to negotiate. Run it once to get the tables, re-run it later to pick up revisions. Every step skips work already on disk, so an interrupted run resumes where it stopped.

Expect roughly 10 GB and 20–60 minutes on a decent connection for the full health subject.

Install

pip install git+https://github.com/ink-waffle/statcan-dl

Get the data

statcan-dl

That writes to output/statcan/ relative to your current directory. The part you'll actually use is output/statcan/tables/:

import pandas as pd

df = pd.read_parquet("output/statcan/tables/13100489 — Perceived health.parquet")
df.head()

Every table arrives in StatCan's long format — one row per (period, geography, characteristic) combination:

Column Meaning
REF_DATE reference period
GEO geography (Canada, a province, a health region…)
VALUE the number, as a float
UOM, SCALAR_FACTOR unit and multiplier — read these before comparing values
STATUS suppression / quality flag; non-empty means VALUE needs care
remaining columns that table's own dimensions — Sex, Perceived health, Characteristics for the table above

Don't need all of it? Narrow it:

statcan-dl --pids 13100489,13100098       # just these tables
statcan-dl --limit 20                     # first 20, useful for a trial run
statcan-dl --subject 1310                 # a narrower branch of the subject tree
statcan-dl -o ~/data/statcan -w 16        # elsewhere, more parallelism

Subject codes are a hierarchy and match by prefix, so 13 is all of Health and 1310 is a branch within it. List what you'd get without downloading:

python -m statcan_dl.download --list

Dimension metadata

The CSVs give you dimension values but not the structure behind them. output/statcan/table_metadata.json holds that, keyed by product ID — which dimensions a table has, every member of each, and how members nest via parent:

import json

meta = json.load(open("output/statcan/table_metadata.json"))
for dim in meta["13100489"]["dimensions"]:
    print(dim["position"], dim["name"], len(dim["members"]))

That parent field is what lets you tell a total apart from its components — necessary if you're aggregating, since totals sit in the same column as the things they total.

What it produces

output/statcan/
├── csv/<pid>/              raw CSV archives, as extracted
├── tables/                 one Parquet per table  ← use these
└── table_metadata.json     dimensions and members, per table

csv/ is an intermediate; it exists so re-runs don't re-download and so you can go back to the source if a conversion looks wrong. Delete it once you have tables/ and you save most of the disk.

Converting drops seven bookkeeping columns that carry no information once a table stands alone: DGUID, UOM_ID, SCALAR_ID, VECTOR, COORDINATE, TERMINATED, SYMBOL.

Pipeline steps

Step Does
download lists cubes via the WDS API, fetches each table's CSV archive
metadata fetches dimensions and members via getCubeMetadata
combine CSV → Parquet, dropping bookkeeping columns and typing VALUE

Run one on its own with --only, or exclude one with --skip-<step>:

statcan-dl --only combine
statcan-dl --skip-metadata

Individual steps are also importable and directly runnable:

python -m statcan_dl.download --limit 5
python -m statcan_dl.combine

Caveats

  • VALUE becomes text instead of a float when a table mixes numbers with suppression markers that won't parse. Check the dtype before doing arithmetic.
  • Archived tables are excluded. They're still on StatCan's site, but they're superseded and often overlap live tables.
  • Titles are truncated to 120 characters in filenames. The full title is in the Parquet metadata under statcan_title, and in table_metadata.json.
  • English only — the loader requests -eng.zip archives.

Tests

pip install -e ".[dev]"
pytest                  # runs the real pipeline over 3 small tables
pytest -m "not network" # offline only

Licence

MIT. The data itself is published by Statistics Canada under the Open Licence.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statcan_dl-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statcan_dl-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file statcan_dl-0.1.0.tar.gz.

File metadata

  • Download URL: statcan_dl-0.1.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for statcan_dl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb4f3ca3edf21b8d17bfa4fe5ee7758d2d676113e828f53dfffac56125054e9b
MD5 a0cf521996d21a4a052f1b08eefc5c9b
BLAKE2b-256 e6567d9db25d8fb282dc8b5e4733f68519576d1511f9a22616270fbacefaf21a

See more details on using hashes here.

Provenance

The following attestation bundles were made for statcan_dl-0.1.0.tar.gz:

Publisher: release.yml on ink-waffle/statcan-dl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file statcan_dl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: statcan_dl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for statcan_dl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c69b9a94efe6f712db26f4d7df8dc00cd19eb88a5a035323cb97d6e8aee12e47
MD5 4dd00f0db75fc0de047287721d873d6a
BLAKE2b-256 6260e5a582f03caae13a2f5dd00ca33d7cf643e84d4f82768efe4ac5b3bc00a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for statcan_dl-0.1.0-py3-none-any.whl:

Publisher: release.yml on ink-waffle/statcan-dl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page