Skip to content

Script Development / Uploading User Python Modules

In some cases, the Python module required by the user is not published on the PyPI platform, but exists directly in the form of files.

In this case, you can upload these files to the "user-python-packages/" directory in the DataFlux Func resource directory and reference them directly in the Script.

1. Uploading Python Modules

Users can choose the upload method according to their actual situation; there is no difference in the result.

Uploading Directly to the Host Machine

If the user has access to the host machine, they can directly upload Python files/directories to the {installation directory}/data/resources/user-python-packages/ directory using familiar SSH tools.

The default installation directory is /usr/local/dataflux-func. If you are not sure, you can use cat /etc/dataflux-func to check.

Uploading via "File Management"

If the user does not have access to the host machine, they can enable "Management / Experimental Features / Enable File Management" and then upload in "Management / File Management".

enable-file-manager.png

upload-zip-file.png

unzip-file.png

To prevent user-uploaded zip archives from breaking the directory structure after extraction, extracting in "File Management" forcibly creates a directory.

Therefore, if the uploaded zip archive already contains a directory layer, there will be one extra directory level after extraction.

Depending on the actual situation, simply move the Python module directory to user-python-packages/xxxxx.

move-user-pkg.png

move-dest.png

Go to the user-python-packages/ directory and confirm the Python package directory to be uploaded.

user-pkg-ready.png

2. Using Uploaded Python Modules

Assume the uploaded Python module is as follows:

my_pkg/__init__.py
1
from my_pkg.hello_world import hello_world
my_pkg/hello_world.py
1
2
def hello_world():
    return 'Hello, world!!!'

Then, you can directly import this module in the Script and use it, for example:

Python
1
2
3
4
5
import my_pkg

def run():
    data = my_pkg.hello_world()
    print(data)

use-user-pkg.png

3. Precautions

For self-uploaded Python modules, be careful not to have the same name as other Python modules, and do not delete or rename directories that already exist in extra-python-packages.