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
VALUEbecomes 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 intable_metadata.json. - English only — the loader requests
-eng.ziparchives.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb4f3ca3edf21b8d17bfa4fe5ee7758d2d676113e828f53dfffac56125054e9b
|
|
| MD5 |
a0cf521996d21a4a052f1b08eefc5c9b
|
|
| BLAKE2b-256 |
e6567d9db25d8fb282dc8b5e4733f68519576d1511f9a22616270fbacefaf21a
|
Provenance
The following attestation bundles were made for statcan_dl-0.1.0.tar.gz:
Publisher:
release.yml on ink-waffle/statcan-dl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statcan_dl-0.1.0.tar.gz -
Subject digest:
fb4f3ca3edf21b8d17bfa4fe5ee7758d2d676113e828f53dfffac56125054e9b - Sigstore transparency entry: 2306859529
- Sigstore integration time:
-
Permalink:
ink-waffle/statcan-dl@8da53a522f314568dcacb9d6adbefb3e3f8a1f39 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ink-waffle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8da53a522f314568dcacb9d6adbefb3e3f8a1f39 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c69b9a94efe6f712db26f4d7df8dc00cd19eb88a5a035323cb97d6e8aee12e47
|
|
| MD5 |
4dd00f0db75fc0de047287721d873d6a
|
|
| BLAKE2b-256 |
6260e5a582f03caae13a2f5dd00ca33d7cf643e84d4f82768efe4ac5b3bc00a0
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statcan_dl-0.1.0-py3-none-any.whl -
Subject digest:
c69b9a94efe6f712db26f4d7df8dc00cd19eb88a5a035323cb97d6e8aee12e47 - Sigstore transparency entry: 2306859547
- Sigstore integration time:
-
Permalink:
ink-waffle/statcan-dl@8da53a522f314568dcacb9d6adbefb3e3f8a1f39 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ink-waffle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8da53a522f314568dcacb9d6adbefb3e3f8a1f39 -
Trigger Event:
push
-
Statement type: