OxidizedZipFinder Meta Path Finder¶
oxidized_importer contains a pure Rust implementation of a meta path
finder that can load Python resources from zip files. Its goal is to be
a compatible reimplementation of
zipimport.zipimporter from the Python
OxidizedZipFinder are bound to zip archive data.
OxidizedZipFinder is a meta path finder and instances should
be registered on
import os import sys import oxidized_importer HERE = os.dirname(os.path.abspath(__file__)) zip_path = os.path.join(HERE, "archive.zip") zip_importer = OxidizedZipFinder.from_path(zip_path) sys.meta_path.insert(0, zip_importer)
Once an instance is registered on
sys.meta_path, it will be consulted
import is serviced by Python’s importing mechanism.
OxidizedZipFinder is similar to - but critically different from -
the standard library
OxidizedZipFinder is a meta path finder, not a
path entry finder. This means instances are bound to
sys.meta_path and not
sys.path_hooks. Support for enabling use as a path hook is planned. The
sys.path_hooks support means this importer can’t be used as
a replacement for
All I/O and zip reading in
OxidizedZipFinder is implemented in
Rust. Subtle differences in behavior as a result of zip parsing implementations
OxidizedZipFinder doesn’t yet implement support for resource
reading (e.g. the
importlib.abc.ResourceReader interface). Only loading
.pyc files is supported.
OxidizedZipFinder doesn’t validate the header of
files. If it sees a
.pyc version of a module, its bytecode will be
used as-is. (
zipimport.zipimporter validates that the content in
.pyc matches expectations.)
Support for opening just sub-directories within zip files is not yet implemented.
OxidizedZipFinder should perform substantially better than
A test importing the ~450 modules that constitute the Python standard library yielded the following results:
Ryzen 5950X Linux
Ryzen 5950X Windows
(The exact set of modules and Python versions were different between the environments so it isn’t fair to compare numbers across environments: only within the same environment.)
OxidizedZipFinder for the Python API documentation.