Mat-IO Module
The mat-io module provides tools for loading and saving MAT-files, including MATLAB's classdef-based datatypes such as datetime, table and string. It supports almost all MATLAB object types, including user-defined objects and handle class objects. Additionally, it includes utilities to convert the following MATLAB datatypes into their respective Pythonic objects, and vice versa:
stringdatetime,durationandcalendarDurationtableandtimetablecontainers.Mapcategorical- Enumeration Instance Arrays
Data is returned in the same format as scipy.io.loadmat, i.e., as a dictionary of {var_name: var_data}.
Installation
pip install mat-io
Usage
Loading MAT-files
from matio import load_from_mat
file_path = "path/to/your/file.mat"
data = load_from_mat(
file_path,
raw_data=False,
add_table_attrs=False,
mdict=None,
variable_names=None,
)
raw_data: IfTrue, returns raw property maps of Opaque class objects.add_table_attrs: IfTrue, adds custom Matlab Table or Timetable properties aspandas.DataFrameattributes.mdict: If provided, this dictionary will be updated with the data from a MAT-file.variable_names: A list of variable names to load from file.
Supported MAT-file versions are v4, v6, v7 and v7.3.
Saving MAT-files
from matio import save_to_mat
file_path = "path/to/your/file.mat"
mdict = {"var1": data1, "var2": data2}
save_to_mat(
file_path,
mdict=mdict,
version="v7.3",
global_vars=None,
oned_as="col",
do_compression=True,
)
file_path: The file to save data.mdict: A dictionary of{var_name: var_data}to write to MAT-files.version: The MAT-file version to save to. Supported versions arev7.3andv7. Defaults tov7.3which is based on the HDF5 format.global_vars: A list of variable names that are to be marked as global variables.saveobj_classes: A list of class names that implementsaveobjmethods.oned_as: The 2D shape to apply to unitnumpy.ndarrays. Eitherroworcol. Defaults tocol.do_compression: IfFalse, does not compress data when saving.
List variables in a MAT-file
from matio import whosmat
file_path = "path/to/your/file.mat"
vars = whosmat(file_path)
# Returns {variable_name: dims, classname}
print(vars)
Opaque Class Objects
Opaque class objects are what MATLAB calls object instances. Opaque objects have different types. The most common is MCOS, which is used for all user-defined classdefs, enumeration classes, as well as most MATLAB datatypes like string, datetime and table.
Opaque objects are returned as an instance of class MatlabOpaque with the following attributes:
classname: The class name, including namespace qualifiers (if any).type_system: An interal MATLAB type identifier. UsuallyMCOS, but could also bejavaorhandle.properties: A dictionary containing the property names and property values.class_alias: This is an optional attribute containing class aliases, if any.
If the raw_data parameter is set to False, then load_from_mat converts these objects into a corresponding Pythonic datatype, if available. For a list of conversion rules between MATLAB and Python datatypes, see the documentation.
When writing objects, matio tries to guess the class name of the object. For example, pandas.DataFrames could be read in as table or timetable. User-defined objects must contain a dictionary of property name, value pairs wrapped around a MatlabOpaque instance.
from matio import save_to_mat
from matio.utils import MatlabOpaque
prop_map = {"prop1": val1, "prop2": val2}
mat_obj = MatlabOpaque(properties=prop_map, classname="MyClass")
mdict = {"var1": mat_obj}
data = save_to_mat(file_path="temp.mat", mdict=mdict)
If the class implements a custom saveobj method, this can be specified in the saveobj_classes argument in save_to_mat. The property map for such classes must contain a single property called any. Typically, the value of this property would be in a format output by the saveobj method. This would be the input for the loadobj method in the class, if defined. More information here.
Wrapper Classes
This package uses wrapper classes to represent Matlab object data to help distinguish from basic datatypes. These are as follows:
MatlabOpaque: A wrapper class for all opaque objects with three attributes:properties,classname,type_system.propertiesis a name-value pair dictionary for each property of the class saved to a MAT-fileMatlabOpaqueArray: A wrapper class subclassed fromnumpy.ndarrayto represent object arrays. Each item in this array is aMatlabOpaqueobject.MatlabEnumerationArray: A wrapper class subclassed fromnumpy.ndarrayto represent enumeration instance arrays. Each item in this array is of typeenum.Enum.MatlabContainerMap: A wrapper class subclassed fromcollections.UserDictto representcontainer.Mapobjects. During save, dictionaries are converted to astruct. Wrap dictionaries aroundMatlabContainerMapto write tocontainer.Mapinstead.
To save these types to a MAT-file, data must be wrapped around the relevant wrapper class. These can be imported from matio.utils. An example is shown below:
# Save dictionary as container.Map
from matio.utils import MatlabContainerMap
from matio import save_to_mat
map = {"a": 1, "b": 2}
map = MatlabContainerMap(map)
var_dict = {"myVar": map}
save_to_mat("file.mat", var_dict)
Contribution
Feel free to create a PR if you'd like to add something, or open up an issue if you'd like to discuss!
Acknowledgement
Huge thanks to mahalex for their breakdown of MAT-files. A lot of this wouldn't be possible without it.
Release files for mat-io 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mat_io-1.0.0.tar.gz | 594.2 kB | Details |
Built distributions (wheels)
Total release size: 11.3 MB
Release files / mat_io-1.0.0.tar.gz
| Download URL | mat_io-1.0.0.tar.gz |
|---|---|
| Size | 594.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
168b6887866b3720ebeaf74ee318a2d1fda26125c8faa11fbb5efa0d4dbdeb1a
|
|
BLAKE2b-256 checksum How to use checksums |
8a37b17c6e93fc339817346823f0f54de746e885d5eb942235bfa40818a47c06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp313-cp313-win_amd64.whl
| Download URL | mat_io-1.0.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 439.3 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
07f8d1603aebe7d80f01fee9ed15d337016e184b9280b8dd5f5964555ff5b33d
|
|
BLAKE2b-256 checksum How to use checksums |
7e04912fa6b448d29223be2bef79ac1cc4842d646aec86d305c3d9d75a4c3266
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp313-cp313-win32.whl
| Download URL | mat_io-1.0.0-cp313-cp313-win32.whl |
|---|---|
| Size | 425.6 kB |
| Tags | CPython 3.13 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
66e52ca181c71f31f18bc73324e6d9b0eb73db82a165e8d62d11b30baba82b0c
|
|
BLAKE2b-256 checksum How to use checksums |
070129ee802d1a1491bbd102ea716473e7fb0d9db39e5ba1ceb022a22f7a8b2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | mat_io-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
4afa61f663e0de08c1d09b7f4fecdd71df806db621cb86df1245a33fe7365162
|
|
BLAKE2b-256 checksum How to use checksums |
8496230ae3d3a306851caae51332716f8479ea704ebac8954b6cd06def236424
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | mat_io-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
452b728a6c8183754a011bde78781fa8dc660e27adc2725fb066b371babf418f
|
|
BLAKE2b-256 checksum How to use checksums |
74ad3684072c0152f90440d44c8376c975a6f143a7b0cc55c114771ee9717c41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | mat_io-1.0.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 452.9 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
280b9d1d465ebce67e0e2b11142e8f6d1be5fa651918c0bfdc15237b1e6a3077
|
|
BLAKE2b-256 checksum How to use checksums |
311f3fbe564149332ee9639ba385d66807550929fd3a86410a3d66d58761e6e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp312-cp312-win_amd64.whl
| Download URL | mat_io-1.0.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 440.3 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
11361e8b16c329295e898cab37bae7dc6bc06b370d3b774ac377609d9fe889b6
|
|
BLAKE2b-256 checksum How to use checksums |
539cccec6457fd130e2602658b8e3a04bd0c1b6192a9298d58e5b4a4be53ff6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp312-cp312-win32.whl
| Download URL | mat_io-1.0.0-cp312-cp312-win32.whl |
|---|---|
| Size | 425.9 kB |
| Tags | CPython 3.12 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
c6ebaf90d3dadfbfa47b26147521d298060ddae8203f582f8cf22a66ed54eab6
|
|
BLAKE2b-256 checksum How to use checksums |
e2c7f02c0467d9b540c0e1ce0b6539644fd61ed185b964a0e3495366321407e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | mat_io-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
4a7c40ef1c8e7a503904f3a5aef93360458d94f76cacee4116ba078071f3c7f5
|
|
BLAKE2b-256 checksum How to use checksums |
371cffebb520f8f15b866d8235d8ef97c41ffa594ae70dee26ae898b85e345c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | mat_io-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
376109e48149f6c2020b605f812ce88eff6a5dbd7ea43a05211ba11a648c0a0f
|
|
BLAKE2b-256 checksum How to use checksums |
4bbc149e6c584135172e91fbf176957af62ba6620752271ceda2079fef5c9747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | mat_io-1.0.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 454.4 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0490198ca4662b4765f8f77cb672f2954fda47f38e515081b24c5dec8fbcf589
|
|
BLAKE2b-256 checksum How to use checksums |
594f61c5dd2e7eac7d9b78fe1c113651472f70691f5dd0e08f5f973c7c59994b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp311-cp311-win_amd64.whl
| Download URL | mat_io-1.0.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 442.2 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1d05fb60448100e060c79d6f86820974d85c1efd7224eabf67d8f7e6dd0af02f
|
|
BLAKE2b-256 checksum How to use checksums |
fdad27ee887835f0889e8070e6c3ea25ce43b075c1ad12b5535c3cf252938981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp311-cp311-win32.whl
| Download URL | mat_io-1.0.0-cp311-cp311-win32.whl |
|---|---|
| Size | 428.4 kB |
| Tags | CPython 3.11 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
d681dcee209543978b58f4e12a09f359c37ea001fe92913288ae521402df720c
|
|
BLAKE2b-256 checksum How to use checksums |
a4ebd6154f3bb42e32294dbb4bb68aa856e08cd70a6e13e8f78541627ac9d7f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | mat_io-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
1358963c797cfc7791e0a29ea3391838949c49f32b5b2110035d4d2a84a27641
|
|
BLAKE2b-256 checksum How to use checksums |
c2113aaa3cce892d77f3c4a60f9899f6b57af2ac7bbd83ec53a9ca4cc1270827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | mat_io-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
22aab7814322caeae47b5a58aa9e65a287bedede793e838673c3159f1e852061
|
|
BLAKE2b-256 checksum How to use checksums |
3b28beafc397c6ad614b2023e7c9e25ad1dd034c6f412d118a8a2d0573f8e1f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency logRelease files / mat_io-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | mat_io-1.0.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 455.5 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0c9a8cf151f413fd0f567ec72fa06a1161a9450cbc2a2a458d400984d5bc86c4
|
|
BLAKE2b-256 checksum How to use checksums |
46011c7aa1b1e78e0c655841e37a1344c91178e6338ae88c32817390d57e7feb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2026.
Transparency log