Skip to main content
Vane Data / Reference

vane.attach_function

vane.attach_function registers an Expression UDF callable as a SQL function on a Vane connection. The SQL alias uses the same distributed runtime and projection-only placement rule as the Python Expression wrapper.

Signature

text
vane.attach_function(
    fn_or_function: Any,
    alias: str | None = None,
    *,
    connection: Any | None = None,
    replace: bool = False,
    parameters: Any = None,
    return_dtype: Any | None = None,
    input_names: Any = None,
    schema: Mapping[str, Any] | None = None,
    batch_size: int | None = None,
    gpus: float | None = None,
    actor_number: int | None = None,
) -> None

Parameters

NameTypeDescriptionDefault
fn_or_functionDecorated UDF, instantiated vane.cls object, or synchronous raw callableCallable to registerRequired
aliasNon-empty str or NoneSQL function name; defaults to the configured UDF or callable nameNone
connectionVane connection or NoneConnection that owns the registration; defaults to vane.default_connection()None
replaceboolAtomically replace an existing Vane alias owned by the same connectionFalse
parametersList or tuple of SQL typesSQL input types; required for every registration formNone
return_dtypeSQL type or NoneRequired for a raw scalar callable or a vane.func without a configured return typeNone
input_namesSequence of non-empty strings or NoneRequired with schema for a raw batch callable; accepted by vane.func.batch and instantiated vane.cls or vane.cls.batch as an explicit alternative to inferred names; invalid for vane.func and raw scalar callablesNone
schemaOne-entry output mapping or NoneRequired with input_names for a raw batch callable; invalid for decorated UDFsNone
batch_sizePositive integer or NoneBatch size for a raw batch callable or row-oriented vane.cls; decorated batch settings cannot be overriddenNone
gpusFinite non-negative number or NoneGPU resource for a raw batch callable; decorated settings cannot be overriddenNone
actor_numberPositive integer or NoneRuns a zero-argument raw callable class as Actors; decorated class settings cannot be overriddenNone

Accepted callables

CallableRequired configuration
vane.funcparameters; return_dtype may come from the decorator or this call
vane.func.batchparameters; return type and execution settings come from the decorator
Instantiated vane.cls or vane.cls.batchparameters; class return type, Actor count, and GPU settings come from the decorator
Raw scalar callableparameters and return_dtype
Raw batch callableparameters, input_names, and schema

Pass an instantiated decorated class such as Scorer(), not the decorated class object Scorer.

Returns and errors

The function returns None. Registration validates the complete configuration before replacing an existing alias. Built-in functions, aliases owned by another connection, and aliases with incompatible SQL signatures are not overwritten. DuckDB may cancel an active transaction while registering the function.

The alias is VOLATILE, but this does not provide exactly-once execution. Retrying backends may replay calls, so external effects must be idempotent. Actor-local state has the same independence, ordering, and reconstruction limits described in Execution guarantees.

The registered function remains projection-only: it can appear in a SQL SELECT list but not in WHERE, JOIN, GROUP BY, HAVING, or aggregate arguments.

Example

example.py
import vane




@vane.func(return_dtype="BIGINT")
def add_one(value):
    return value + 1




vane.attach_function(add_one, parameters=["BIGINT"])
result = vane.sql("SELECT add_one(value) AS value FROM (VALUES (0), (1), (2)) AS t(value)")


print(result.order("value").fetchall())
vane.detach_function("add_one")
vane.close()

Output:

text
[(1,), (2,), (3,)]