Skip to content

CRUD

The CRUD methods are used to create, read, update and delete functions. There are two ways to use them. The first is through the SDK and the second is through the Project object. The syntax is the same for all CRUD methods. If you want to manage functions from the project, you can use the Project object and avoid to specify the project parameter. In this last case, you need to specify every parameter as keyword argument.

A function entity can be managed with the following methods.

Create:

Read:

Update:

Delete:

Create

You can create a function with the new_function(). The kwargs parameters are determined by the kind of the object, and are described in the kinds section.

New

This function create a new entity and saves it into the backend.

new_function

Parameters:

Name Type Description Default
project str

Project name.

required
name str

Object name.

required
kind str

Kind the object.

required
uuid str

ID of the object (UUID4, e.g. 40f25c4b-d26b-4221-b048-9527aff291e2).

None
description str

Description of the object (human readable).

None
labels list[str]

List of labels.

None
embedded bool

Flag to determine if object spec must be embedded in project spec.

True
**kwargs dict

Spec keyword arguments.

{}

Returns:

Type Description
Function

Object instance.

Examples:

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

Read

To read functions you can use the get_function(), get_function_versions(), list_functions() or import_function() functions.

Get

This function searches for a single function into the backend. If you want to collect a function from the backend using get_function(), you have two options:

  • The first one is to use the key parameter which has the pattern store://<project-name>/<entity-type>/<entity-kind>/<entity-name>:<entity-id>.
  • The second one is to use the entity name as identifier, the project name as project and the entity id as entity_id parameters. If you do not specify the entity id, you will get the latest version.
get_function

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
entity_id str

Entity ID.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
Function

Object instance.

Examples:

Using entity key:

>>> obj = get_function("store://my-function-key")

Using entity name:

>>> obj = get_function("my-function-name"
>>>                    project="my-project",
>>>                    entity_id="my-function-id")

Get versions

This function returns all the versions of a function from the backend.

get_function_versions

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[Function]

List of object instances.

Examples:

Using entity key:

>>> obj = get_function_versions("store://my-function-key")

Using entity name:

>>> obj = get_function_versions("my-function-name"
>>>                             project="my-project")

List

This function returns all the latest functions from the backend related to a project.

list_functions

Parameters:

Name Type Description Default
project str

Project name.

required
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
list[Function]

List of object instances.

Examples:

>>> objs = list_functions(project="my-project")

Import

This function load the function from a local yaml file descriptor.

import_function

Parameters:

Name Type Description Default
file str

Path to YAML file.

required

Returns:

Type Description
Function

Object instance.

Examples:

>>> obj = import_function("my-function.yaml")

Update

To update a function you can use the update_function() method.

update_function

Parameters:

Name Type Description Default
entity Function

Object to update.

required

Returns:

Type Description
Function

Entity updated.

Examples:

>>> obj = update_function(obj)

Delete

To delete a function you can use the delete_function() method.

delete_function

Parameters:

Name Type Description Default
identifier str

Entity key (store://...) or entity name.

required
project str

Project name.

None
entity_id str

Entity ID.

None
delete_all_versions bool

Delete all versions of the named entity. If True, use entity name instead of entity key as identifier.

False
cascade bool

Cascade delete.

True
**kwargs dict

Parameters to pass to the API call.

{}

Returns:

Type Description
dict

Response from backend.

Examples:

If delete_all_versions is False:

>>> obj = delete_function("store://my-function-key")

Otherwise:

>>> obj = delete_function("function-name",
>>>                       project="my-project",
>>>                       delete_all_versions=True)