Import Python modules from dicts and JSON formatted documents
Paker
Paker is module for importing Python packages/modules from dictionaries and JSON formatted documents. It was inspired by httpimporter.
Installation
From PyPI
pip install paker
From source
git clone https://github.com/desty2k/paker.git
cd paker
pip install .
Usage
In Python script
You can import Python modules directly from string, dict or bytes (without disk IO).
import paker
import logging
MODULE = {"somemodule": {"type": "module", "code": "fun = lambda x: x**2"}}
logging.basicConfig(level=logging.NOTSET)
if __name__ == '__main__':
with paker.loads(MODULE) as loader:
# somemodule will be available only in this context
from somemodule import fun
assert fun(2), 4
assert fun(5), 25
print("6**2 is {}".format(fun(6)))
print("It works!")
To import modules from .json
files use load
function. In this example paker will serialize and import mss