Skip to content

Script Development / Uploading User Python Modules

In some cases, the Python modules required by users are not published on the PyPI platform but exist directly as files.

At this time, these files can be uploaded to the user-python-packages/ directory in the DataFlux Func resource catalog and referenced directly in scripts.

1. Uploading Python Modules

Users can choose the upload method based on their actual situation. There is no difference in the result.

Direct Upload 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 their preferred SSH tool, etc.

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

Uploading Using "File Management"

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

enable-file-manager.png

upload-zip-file.png

unzip-file.png

To prevent the uploaded zip archive from damaging the directory structure after extraction, extraction in "File Management" will forcibly create a directory.

Therefore, if the uploaded zip archive itself has a directory layer, there will be an extra layer of directory structure after extraction.

Based on the actual situation, move the Python module's 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 the Uploaded Python Module

Assuming 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 and use this module in a script, 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

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