# bind\_function 方法

## 简要

将给定无服务器云函数绑定在另一个 Python 原生函数、类方法或类实例方法上。之后对被绑定可调用对象的调用将被重定向为对给定无服务器云函数的调用。

```python
def bind_function(self,
    region_id: str,
    namespace_name: str,
    function_name: str,
    function_version: str = None,
    function_async: bool = False,
    include_attributes: list = None
) -> object
```

{% hint style="info" %}
该方法是一个装饰器，您应该以 Python 装饰器语法使用它，否则行为是未定义的。
{% endhint %}

## 参数

该方法的参数和参数描述如下：

| 参数                  | 类型         | 必选 | 描述                                                                           |
| ------------------- | ---------- | -- | ---------------------------------------------------------------------------- |
| region\_id          | str        | 是  | 绑定的无服务器云函数所在数据中心的唯一标识符。                                                      |
| namespace\_name     | str        | 是  | 绑定的无服务器云函数所在命名空间的名称。                                                         |
| function\_name      | str        | 是  | 绑定的无服务器云函数名称。                                                                |
| function\_version   | str        | 否  | <p>绑定的无服务器云函数版本名称。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认为最新版本。</p>         |
| function\_async     | bool       | 否  | <p>绑定的无服务器云函数是否以异步的方式运行。</p><p>如果该参数被忽略或设置为 <code>None</code>，默认以同步方式运行。</p> |
| include\_attributes | list\<str> | 否  | 需要包含当前实例的属性名称列表实例，这些属性将被优先添加到绑定的无服务器云函数调用事件。如果被绑定的可调用对象不是类方法或类实例方法，该参数将被忽略。  |

## 返回值

该方法返回装饰器处理器函数实例。

被绑定可调用对象被调用时将在内部调用方法 [`easy_invoke`](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client-lei/easy-invoke-method) 实现对给定无服务器云函数的调用，其被绑定可调用对象的返回值与方法 [`easy_invoke`](https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client-lei/easy-invoke-method) 的返回值一致。

## 异常

该方法预期行为不会主动引发任何异常。

## 示例

下面我们将通过一段 Python 代码向您演示如何使用该方法：

```python
@function_client.bind_function(
    region_id = 'ap-shanghai',
    namespace_name = 'default',
    function_name = 'addend',
    function_version = '1',
    function_async = False,
    include_attributes = None
)
def addend(
    value1: int,
    value2: int
) -> int:
    raise NotImplementedError

return_value: int = addend(
    value1 = 10,
    value2 = 20
)
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-serverless-functions >= 0.1.1


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/serverless-functions/class-and-method/client/bind-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
