Code Editor
The Code Editor is where developers write UDFs using standard Python libraries and installed dependencies. The Editor tab contain functionality to organize code, create HTTP endpoints, and configure the UDF.
Editor
The editor contains the UDF's function declaration. Whenever code is updated, Fused automatically runs the function named udf
that is decorated with @fused.udf
and returns the output. Other UDFs declared in the editor are ignored unless referenced by the main udf
function.
Default Parameters hierarchy
Just like any other Python function, UDFs can have default parameters. In Workbench, these can be set in 2 different location though:
- In the UDF Layer (the left side of the code editor)
- In Python directly
The hierarchy is as follows:
- Workbench UDF Layer UI
- In-Python parameter (when defining the function)
- HTTP Request / Calling UDF with shared token
Example: Hierarchy of default parameters
Let's start with a simple UDF:
@fused.udf
def udf(my_default_param: float = 1.5):
print(f"{my_default_param=}")
return my_default_param
In Workbench, without defining else we would get 1.5
back:
Now we can set default parameters in the UDF layer UI:
In this case Workbench overwrites the default parameter in the Python code with the value set in the UI:
And finally, if you call this UDF through HTTPS / Shares token, then the default parameter will of course be overwritten by the value you provide:
Rationale
We decide to prioritize the UI-based parameters over Python so that non technical users can interact with a UDF in Map View without having to interact with Python at all:
Regardless of the defaults defined in Python, the UI-based parameters will always take precedence.
Debug
The code editor highlights errors in the code and shows error logs to help debug.
Profiler
UDF Builder comes with a built-in profiler that can be used to analyze the performance of a UDF.
This gives you the line-by-line execution time in the UDF.
Note:
- Values are only available for the current run of the UDF.
- Running the same UDF twice might lead to different runtimes especially if you call cached functions or cached UDFs.
- When a line is called multiple times the profiler shows the sum time of all calls & number of hits:
Save a UDFs
UDFs show an asterisk (*
) next to their name when changes have been made since the last save. Clicking the "Save" icon saves the present state of the UDF under your account's UDFs.
If the "Save" icon appears greyed out, it means you're viewing a read-only version of the UDF. Make a copy to create a new version than can be modified and saved.
Utils Module
A Fused UDF can import Python objects from its accompanying utils Module, defined in the Utils Tab's code editor. You can import functions from it in your UDF with from utils import my_function
.
Here is an example in the Public Overture_Maps_example UDF:
@fused.udf
def udf(
bounds: fused.types.Bounds,
release: str = "2025-01-22-0",
):
from utils import get_overture
gdf = get_overture(
bounds=bounds,
release=release,
)
return gdf
Auto, Tile, and Single (Viewport, Parameter)
On UDF Builder, UDFs can explicitly be set to run as Tile or File - or autoselect between the two if the bounds
object is typed.