Dynamic remote import is an extensible python module that allows you to import packages (modules, classes, methods and functions, etc.) from remote repositories directly into RAM.
Perhaps it will be useful when deploying code in centralized code repositories and downloading new updates to runtime. For example, if you have a service in a container, it can reload modules after the expiration of time or on command without restarting the container.
This module implies an extension. To do this, it is divided into two entities:
- Import Core
- Transport
The "import core" can work with any transport object satisfying certain conditions, so you can write your own transport. To add your own transport module, you need:
- Implement "get" method or function in it, which takes the name of the module and returns either None, if nothing is found, or a string or bytestring representing python code. Please remember, the way to search for modules in python (https://docs.python.org/3/reference/import.html#searching).
- Save your transport module to the "clients" folder.
- Add the module definition to the "transport_catalog" module.
Use the git to install remote import.
git clone https://github.com/MrCa4/RemoteImport.gitImport remote import core module
For Example:
from remote_import import remote_import_coreSelect the transport and the necessary parameters
remote_import_core.init('http', url="http://127.0.0.1:9000")Import necessary module.
from foo.bar import modulefrom foo.bar import module
from foo.bat import aa, bb
from foo.bat.aa import test as t
from foo.bas import *
import foo.bar.moduleHTTP/HTTPS, SMB
- Response with python obj(class, method function, etc) data must contain "Content-type" header:
Content-type: text/plain- When mask import is used, You must add index.html in package dir
on the similarity of the file
"__init__", For example:
index.html
__all__ = ["a_aa", "a_bb"]In this case response must contain "Content-type" header:
Content-type: text/htmlFor tests use simple http server:
python -m http.server 9000Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.