Skip to content

Method API ​

Look up arguments and options when registering a function. See Connect a Python function for the full flow.

python_method ​

python
from decision_layer.methods import Column, DataInput, Scope, python_method

method = python_method(
    function,
    name="my_team.analysis",
    version="1.0.0",
    inputs={"data": DataInput(columns={...})},
)
ArgumentMeaning
First argumentPython function to execute
name, versionRequired Method name and version
inputsRequired mapping from data arguments to DataInput
outputResult shape: default "auto", or "table", "estimate"
requires_packagesRequired package versions, such as {"statsmodels": ">=0.14,<0.16"}
checksAdditional data checks
option_checksOption checks executed before querying
adaptOptional function converting the returned value to a supported shape
providesCapability names used by Recipes and analysis goals

Ordinary function arguments become calculation options, with types and defaults inferred from the signature. Use parameters for explicit overrides. The docstring supplies the Method description.

requires_packages checks installed versions; it does not install packages at runtime.

DataInput and Column ​

Each inputs key names a function argument receiving a DataFrame. Declare a separate input for each table.

python
inputs={
    "data": DataInput(
        columns={
            "value": Column(source="measure", dtype="number"),
            "group": Column(source="dimension"),
        },
        minimum_rows=10,
    ),
}
Column optionMeaning
sourceRequired: "measure", "dimension", or a list allowing both
dtypeRequire "number", "string", "boolean" or "time"; omitted means unrestricted
multiple=TrueSelect several metrics or dimensions; default False
required=FalseOptional input; default True
role="entity_key"Key identifying each row, such as customer or order ID
descriptionExplanation of the input

An entity_key must be one required dimension declared as an entity key by the semantic provider. Each DataInput allows one. Selecting a key does not establish statistical independence.

Function arguments matching declared columns receive DataFrame column names. Multiple columns receive names such as confounders_0, confounders_1 and are passed as a list. Select actual Cube references through bindings at execution time.

Common DataInput optionMeaning
minimum_rowsMinimum row count; default 1
formatDefault "dataframe"; "records" provides a list of row dicts
time_granularityQuery by "day", "week", "month", "quarter" or "year"
period_parameterOption naming a comparison date range
period_role="comparison"Query a separately selected comparison period
filters_parameterOption supplying additional query filters

Return values ​

Function resultAdaptation
DataFrame or list of row dictsTable with default settings
NumberEstimate with default settings
DictOne-row table with default settings
{"value": number, ...}Estimate with details when output="estimate"

output="table" and output="estimate" require the selected shape; mismatches raise an error. Convert unsupported external-library objects inside the function or through adapt.

Checks and errors ​

Decision Layer checks required inputs, types and declared data conditions. Each Method does not need its own handling for those checks.

  • checks run after querying and before calculation. Arguments use the DataInput names.
  • option_checks receive only calculation options and run before querying.
  • Returning False or raising ValueError or AssertionError records a failed check and stops calculation. None or True passes.
  • Exceptions in the calculation function itself propagate as Python errors. Programming failures are not successful results.

Local sessions ​

APIPurpose
session.register(method)Add a Method to the session
session.list_methods()List registered manifests
session.find_methods(...)Search Methods and their input requirements
await session.run(name, bindings=..., params=..., scope=...)Execute locally and inspect the result

bindings selects semantic references; params supplies calculation options. Use Scope(date_range=(start, end), time_dimension=date_reference) for dates.

Inspect trial.result and trial.attempts for results and query attempts. Trials are not automatically stored on the server. Continue with Register in a project for service use.

For advanced control over queries, see the SDK examples. See the implementation for the complete registration signature.