Loading...

verticapy.sdk.vertica.udf.import_lib_udf#

verticapy.sdk.vertica.udf.import_lib_udf(udf_list: list, library_name: str, include_dependencies: None | str | list[str] = None) bool#

Install a library of Python functions in Vertica. This function will only work when it is executed directly in the server.

Parameters#

udf_list: list

List of tuples that includes the different functions.

  • function, function:

    Python Function.

  • arg_types, dict | list:

    List or dictionary of the function input types. Example: {"input1": int, "input2": float} or [int, float]

  • return_type, type | dict:

    Function output type. In the case of many outputs, it must be a dictionary including all the outputs types and names. Example: {"result1": int, "result2": float}

  • parameters, dict:

    Dictionary of the function input optional parameters. Example: {"param1": int, "param2": str}

  • new_name, str:

    New function name when installed in Vertica.

library_name: str

Library Name.

include_dependencies: str | list, optional

Library files dependencies. The function copies and pastes the different files in the UDF definition.

Returns#

bool

True if the installation was a success, False otherwise.

Examples#

Import the math module. This example will use the math.exp and math.isclose functions:

import math

Important

Python is type-agnostic, but Vertica requires specific data types. It’s important to specify input, output, and parameter types when generating User-Defined Extensions (UDx). These functions will be automatically installed, allowing you to call them directly using SQL.

from verticapy.sdk.vertica.udf import import_lib_udf

import_lib_udf(
    [
        (math.exp, [float], float, {}, "python_exp"),
        (math.isclose, [float, float], bool, {"abs_tol": float}, "python_isclose"),
    ],
    library_name = "python_math",
)

Important

In this example, we utilized a standard Python function. If you wish to use a non-standard function, you’ll need to install it on each node individually.

Note

For now, Vertica does not allow the installation of the library from the client side. Additionally, you need to have the right database privileges. You can use the generated code to move it to the server and request the administrator with the necessary privileges to install it. Please look at: generate_lib_udf() for more information.

See also

generate_lib_udf() : Generates the UDF code.