Register a Utility Function
Ask AI
weighted_mean helper) that you register once and call by its alias from other objects, instead of copying it into each. Define it once and every object that uses it stays in sync. Write the function body, set an alias, and create.
What is it?
Section titled “What is it?”A Utility Function / Global Function is a reusable piece of Python you register once and share across objects, instead of re-writing the same helper each time. In the platform it is called a Global Function. Once registered, select it in any object that accepts inputs and call it by its alias.
For example, register weighted_mean once and call weighted_mean(values, weights) in every Report that needs it, so the calculation lives in one place instead of drifting across copies.
How to Register
Section titled “How to Register”Follow these steps to register a Global Function.
Open the Create Form
Section titled “Open the Create Form”
Open the Create Form
Section titled “Open the Create Form”On the Resources → Global Functions page, click + New Global Function.
The form opens with an editable name field at the top left (New Global Function). Type a descriptive name (for example, Weighted Mean) and confirm to land on the full form.
Set the Output Type and Alias
Section titled “Set the Output Type and Alias”
Set the Output Type and Alias
Section titled “Set the Output Type and Alias”Set the Output Type (optional) - the type of value the function returns (for example, Numerical, String, Boolean).
Set the Alias * - the name used to call the function in code (for example, weighted_mean).
Define Arguments and Inputs
Section titled “Define Arguments and Inputs”
Define Arguments and Inputs
Section titled “Define Arguments and Inputs”Click Add Arguments to define what your function takes in as input (for example, values and weights). Each argument becomes a variable you can use in the Definition.
Under Input, select any other Global Functions this one relies on, so you can call them by their alias inside the definition (for example, a roc_auc Global Function reused by another function like gini):
# Global Function: gini (alias: gini)# Input: roc_auc <- another Global Function, selected here so it can be called by its alias belowreturn 2 * roc_auc(scores, labels) - 1
Write the Logic
Section titled “Write the Logic”
Write the Logic
Section titled “Write the Logic”In the Definition editor, write the function body in Python. The arguments you defined are already in scope, so use them directly. Whatever the function returns is what callers receive when they call it by its alias. You can import standard libraries (numpy, math, datetime, etc.).
Write the logic directly, not wrapped in a def. The platform builds the function signature from the Alias and Arguments you set.
For example, the weighted_mean Global Function, using the values and weights arguments:
"""Return the weighted mean of values, or None if the weights sum to zero."""total = sum(weights)if not total: return Nonereturn sum(v * w for v, w in zip(values, weights)) / total
Fill in Properties and Create
Section titled “Fill in Properties and Create”
Fill in Properties and Create
Section titled “Fill in Properties and Create”Fill in the Properties (Description and Group), then click Create at the bottom right. The Global Function is saved as a draft and you land on its details page.
What’s Next
Section titled “What’s Next”To use a Global Function, select it in the Input or Resources section of any object that supports it, then call it by its alias in that object’s definition. It appears in code autocomplete inside the editor.
Next steps:
- Use the function inside a Data Aggregate, Feature, or Report.
- Send it for approval so it can be used outside your draft workspace.
Was this page helpful?
Thanks for the feedback.