Code Editor
The Code Editor is where developers write UDFs using standard Python libraries and installed dependencies. The Editor, Module, Visualize, and Settings tabs 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.
Debug
The code editor highlights errors in the code and shows error logs to help debug.
Module
A Fused UDF can import Python objects from its accompanying utils Module, defined in the Module's code editor. The module's default name is utils
and can be changed to avoid naming collisions. In this example, UDF imports the function arr_to_plasma
from its utils
Module.
@fused.udf
def udf(bbox):
from utils import arr_to_plasma
return arr_to_plasma(arr.values, min_max=(0, .8))
Visualize
Valid vector tables or raster objects returned by UDFs can be rendered on the map. The "Visualize" tab is where the output's visual style can be configured. See the layer styling page for more details on syntax and internals.
Settings
The Settings tab contains functionality to share the UDF, toggle its cache, and configure its metadata.
Share snippets
UDFs saved in the UDF Builder can be called with HTTP endpoints using shared and private tokens.
The "Share" section shows snippets to run the UDF using a public token. This allows any application to invoke the UDF without authentication - including cURL
calls, Lonboard, Leaflet, Mapbox, Google Sheets, DuckDB, the Fused App Builder, and Python applications with fused.run
.
Private snippets
The "Snippets" section shows snippets that can only be called by services authenticated with a private token. These include Python
, cURL
, and fused.load
.
Cache
UDFs with an active share token will display a toggle to optionally cache the output to speed up execution.
When a UDF that has caching enabled is called, Fused executes the UDF and stores its output the first time it sees the code and parameters. Subsequent calls to the UDF with the same code and parameters skip execution and return the cached output.
By default, the cache is written to the S3 bucket Fused provisions for the user that owns the UDF. You may get in touch to configure something different.
Metadata
Default parameter values
UDFs by default run with the parameters specified in their function declaration. Predefined default parameter values take precedence and appear in the layer's dropdown in the navigation bar.
Default view state
Clicking the "Zoom to layer" button on the UDF layer zooms the viewport to the preconfigured view, or the extent of the output object if no default view is set.
The default view state can be set automatically to the present map view, or manually.
Image preview
UDFs in the UDF Catalog show a preview thumbnail. The image can be set in the "Image preview" field with a URL.
Tags
UDF tags can be set to help with discoverability in the UDF Catalog.
Description
UDFs can be documented using Markdown with a brief description of their purpose, code, and associated datasets. The description appears in the UDF profile and README.md
file.
Toolbar
The toolbar at the top of the code editor includes buttons to configure, duplicate, download, and delete a UDF, as well as view its history and push it to GitHub.
GitHub
Organizations with the GitHub Integration enabled can push UDFs to a GitHub repository as a Pull Request or restore a prior version of a UDF from the commit history.
Download
Clicking "Download" saves the UDF and downloads a .zip
file with the UDF code, module, and configuration.
Auto, Tile, and File
On UDF Builder, UDFs can explicitly be set to run as Tile or File - or autoselect between the two if the bbox
object is typed.