Skip to content

Create a function

Choose the runtime that matches the function you want to create. Its guide covers runtime-specific prerequisites, function parameters, execution, and examples.

Choose a function kind

  • Python - Create functions with the Python runtime - python

  • Container - Run functions packaged in a container image - container

  • Model serving - Serve trained models through a model serving runtime - modelserve

  • DBT - Create a DBT Function and run SQL transformations - dbt

  • Federated learning - Build federated learning functions with Flower - flower

  • Guardrail - Define guardrail functions with the Python runtime - guardrail

  • OpenInference - Use OpenInference with the Python runtime - openinference

  • TVM - Create TVM models and services with the TVM runtime - tvm

  • Hydra - Create Hydra Python functions with the Hydra runtime - hydra

New function

Use new_function() to create and save a function.

new_function

Create a new function entity in the backend.

Parameters:

Name Type Description Default
project str

Project name.

required
name str

Entity name.

required
kind str

Entity kind.

required
uuid str

Entity identifier.

None
version str

Entity version.

None
description str

Human-readable entity description.

None
labels list[str]

Entity labels.

None
embedded bool

Whether to embed the entity specification in the project specification.

False
**kwargs dict

Additional entity specification parameters.

{}

Returns:

Type Description
Function

Created function entity.

Examples:

Create a Python function:

import digitalhub as dh

function = dh.new_function(
    project="my-project",
    name="my-function",
    kind="python",
    code_src="function.py",
    handler="function-handler",
)