memimport

Helps import Python extensions from memory, e.g. extensions from Zip files or Web.


Keywords
memory, importer, zip, loader
Licenses
MIT/X11/CERN-OHL-P-2.0
Install
pip install memimport==0.13.0.0.post5

Documentation

memimport for Python 3

operating system Python implementation Python versions licenses development status
latest tag build status latest version package format monthly downloads

memimport is a part of py2exe, which helps import Python extensions from memory, e.g. extensions from Zip files or Web.

This repo via CI to build it as Python extensions, beacause the original has been built into the py2exe runstubs, only run with script, no REPL.

Development of memimport is hosted here: https://github.com/SeaHOH/memimport.
Development of py2exe is hosted here: https://github.com/py2exe/py2exe.

Installation

pip install memimport

Usage

import zipextimporter
import sys

sys.path.insert(0, 'path/to/libs.zip')

then

zipextimporter.install()            # default, prefer `hook=False`, `hook=True` as fallback

or

zipextimporter.install(hook=False)  # better compatibility, monkey patch `zipimport.zipimporter`
                                    # equal to empty argument, `hook=True` as fallback

or

zipextimporter.install(hook=True)   # not recommend, install to `sys.path_hooks`

then

import ext_mod_in_zip      # now, support __init__.pyd in packages

ext_mod_in_zip             # <module 'ext_mod_in_zip' from 'path\\to\\libs.zip\\ext_mod_in_zip\\__init__.pyd'>
ext_mod_in_zip.__file__    # 'path\\to\\libs.zip\\ext_mod_in_zip\\__init__.pyd'>
ext_mod_in_zip.__loader__  # <ZipExtensionImporter object 'path\to\libs.zip\'>

import py_mod_in_zip

py_mod_in_zip              # <module 'py_mod_in_zip' from 'path\\to\\libs.zip\\py_mod_in_zip\\__init__.py'>
py_mod_in_zip.__file__     # 'path\\to\\libs.zip\\py_mod_in_zip\\__init__.py'>
py_mod_in_zip.__loader__   # <zipimporter object 'path\to\libs.zip\'>

More usage see source or use help function.