Install & Compatibility
Where this runs
tested against v3.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.9
✕ build_error
✓ 12.4s
181MB installed
● package 181MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
vectors_to_df
✓ from stats_can import vectors_to_df
✗ from statscan import Statscan
get_cube_metadata
✓ from stats_can import get_cube_metadata
✗ from statscan import Statscan
zip_table_to_dataframe
✓ from stats_can import zip_table_to_dataframe
✗ from statscan import Statscan
This quickstart demonstrates how to initialize the Statscan client and fetch data for a given Statistics Canada data cube ID. The data is returned as a pandas DataFrame. It also shows a commented example for applying basic filters.
from statscan import Statscan
import pandas as pd
# Initialize the Statscan client
sc = Statscan()
# Fetch data for a specific cube ID (e.g., '17-10-0007-01' for Consumer Price Index)
df = sc.get_data("17-10-0007-01")
# Print the first few rows of the DataFrame
print(df.head())
# You can also specify filters, e.g., for specific geographies or dates
# df_filtered = sc.get_data(
# "17-10-0007-01",
# filters={
# 'GEO': ['Canada', 'Ontario'],
# 'REF_DATE': ['2023-01', '2023-02']
# }
# )
# print(df_filtered.tail())
Debug
Known issues
breakingVersion 3.0.0 introduced a complete API rewrite. All methods from previous versions (v2.x) are removed. Users must now instantiate the `Statscan` class and use its methods (e.g., `get_data`, `get_table_data`).fixRewrite code to use the new `Statscan` class and its methods. Consult the v3.x documentation for updated usage patterns.
affects: <3.0.0 to >=3.0.0
gotchaRepeatedly fetching table metadata can be slow and may hit API rate limits. The library defaults to caching table metadata, but you can explicitly configure `tables_dir` and `cache_dir` for persistent caching and improved performance.fixInitialize `Statscan` with `sc = Statscan(tables_dir='/path/to/tables_cache', cache_dir='/path/to/data_cache')` for optimized performance and reduced API calls. Ensure these directories exist and are writable.
affects: >=3.0.0
gotchaData availability from Statistics Canada is dynamic. Specific cube IDs, dimension combinations, or date ranges may not exist or return empty results, leading to empty DataFrames or `ValueError` exceptions.fixAlways verify the existence and structure of data for the desired cube ID and filters on the official Statistics Canada website before attempting to fetch it. Implement error handling for `ValueError` or check for empty DataFrames.
affects: All
Upgrade
Version history
3.2.3latest on PyPI · released Apr 14, 2026
Audit
Dependencies
pandasrequiredRequired for data manipulation and returning data as DataFrames.
requestsrequiredUsed for making HTTP requests to the Statistics Canada API.