PyMatReader

raw JSON →
1.2.2 verified Fri May 01 auth: no python

A convenient reader for MATLAB .mat files, handling various data types and structures. Current version 1.2.2, requires Python ≥3.10. Regular updates.

pip install pymatreader
error AttributeError: 'Namespace' object has no attribute '...'
cause Accessing a variable by name that doesn't exist in the .mat file, or using wrong case.
fix
List available keys: print(data.keys()) and then access the correct key.
error ValueError: Unknown mat file type, version ...
cause File might be corrupted or unsupported format (e.g., MATLAB v4).
fix
Try opening with scipy.io.loadmat as fallback, or check file integrity.
error ModuleNotFoundError: No module named 'h5py'
cause Trying to read a v7.3 file without h5py installed.
fix
Install h5py: pip install h5py.
gotcha By default, pymatreader returns variables as attributes of a simple namespace object. If you expect a dict, use `ignore_fields=False` or access via `data['varname']`.
fix Use `data['varname']` or set `ignore_fields=True` (default) to get attribute-style access.
breaking pymatreader 1.0+ dropped support for Python 2 and Python <3.10. The API changed from returning dicts to returning a namespace object.
fix Use `data = read_mat('file.mat').__dict__` to get a dict, or update code to use attribute access.
deprecated The `matfile` function is deprecated in favor of `read_mat`.
fix Replace `from pymatreader import matfile` with `from pymatreader import read_mat`.

Basic usage to read a .mat file and access its variables.

from pymatreader import read_mat
import os

# Read a MATLAB .mat file
data = read_mat('example.mat')
# Access variables by name
# data.variable_name
print(data.keys())