Registry / data / stats-can

stats-can

JSON →
library3.2.3pypypi✓ verified 83d ago

Stats-can is a Python library designed to easily read data from Statistics Canada into pandas DataFrames. It simplifies access to the StatsCan API, allowing users to fetch specific data cubes by ID and apply filters for dimensions like geography, time, and characteristics. The current version is 3.2.3, with major releases refactoring the API for robustness, and minor releases addressing bug fixes and performance improvements.

pip install stats-can
INSTALL
IMPORT
SIG · STATS-CAN
S
stats-can
datapythonv3.2.3
Install
9.9s avg
Import
Disk
181MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
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
musl
glibc
py 3.10
✓ —
✓ 10.3s
py 3.11
✓ —
✓ 9.05s
py 3.12
✓ —
✓ 8.95s
py 3.13
✓ —
✓ 8.9s
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`).
fix
Rewrite 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.
fix
Initialize `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.
fix
Always 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.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
stats-can — pip install stats-can · libregistry