function

Python SDK for writing Crossplane composition functions.

This SDK provides the building blocks for implementing Crossplane composition functions in Python. Composition functions are serverless components that extend Crossplane's composition capability, allowing you to programmatically control how infrastructure is composed and managed.

Quick Start

Install the SDK:

pip install crossplane-function-sdk-python

Create a composition function by subclassing Runtime:

from crossplane.function.runtime import Runtime
from crossplane.function.request import RunFunctionRequest
from crossplane.function.response import RunFunctionResponse


class MyFunction(Runtime):
    def Run(self, request: RunFunctionRequest) -> RunFunctionResponse:
        # Your composition logic here
        return response.to(request)

Modules

  • runtime — Base class for implementing the function runtime and gRPC server.
  • request — Types and utilities for parsing RunFunctionRequest messages.
  • response — Types and utilities for building RunFunctionResponse messages.
  • resource — Kubernetes resource types used in function pipelines.
  • logging — Structured logging utilities for function output.

Protobuf Types

The RunFunctionRequest and RunFunctionResponse types are generated from proto3 schema definitions. See the proto modules for API reference:

  • [proto.v1.run_function_pb2][crossplane.function.proto.v1.run_function_pb2] — Current API
  • [proto.v1beta1.run_function_pb2][crossplane.function.proto.v1beta1.run_function_pb2] — Legacy API

Proto-generated fields behave like standard Python types but follow protobuf Python conventions.

 1# Copyright 2025 The Crossplane Authors.
 2#
 3# Licensed under the Apache License, Version 2.0 (the "License");
 4# you may not use this file except in compliance with the License.
 5# You may obtain a copy of the License at
 6#
 7#     http://www.apache.org/licenses/LICENSE-2.0
 8#
 9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Python SDK for writing Crossplane composition functions.
16
17This SDK provides the building blocks for implementing [Crossplane composition
18functions](https://docs.crossplane.io/latest/concepts/composition-functions) in
19Python. Composition functions are serverless components that extend Crossplane's
20composition capability, allowing you to programmatically control how infrastructure
21is composed and managed.
22
23## Quick Start
24
25Install the SDK:
26
27```shell
28pip install crossplane-function-sdk-python
29```
30
31Create a composition function by subclassing `Runtime`:
32
33```python
34from crossplane.function.runtime import Runtime
35from crossplane.function.request import RunFunctionRequest
36from crossplane.function.response import RunFunctionResponse
37
38
39class MyFunction(Runtime):
40    def Run(self, request: RunFunctionRequest) -> RunFunctionResponse:
41        # Your composition logic here
42        return response.to(request)
43```
44
45## Modules
46
47- **runtime** — Base class for implementing the function runtime and gRPC server.
48- **request** — Types and utilities for parsing `RunFunctionRequest` messages.
49- **response** — Types and utilities for building `RunFunctionResponse` messages.
50- **resource** — Kubernetes resource types used in function pipelines.
51- **logging** — Structured logging utilities for function output.
52
53## Protobuf Types
54
55The `RunFunctionRequest` and `RunFunctionResponse` types are generated from
56proto3 schema definitions. See the proto modules for API reference:
57
58- [`proto.v1.run_function_pb2`][crossplane.function.proto.v1.run_function_pb2]
59  — Current API
60- [`proto.v1beta1.run_function_pb2`][crossplane.function.proto.v1beta1.run_function_pb2]
61  — Legacy API
62
63Proto-generated fields behave like standard Python types but follow
64[protobuf Python conventions](https://protobuf.dev/reference/python/python-generated/).
65"""