# fetch\_client 函数

## 简要

获取适用于当前超线程的内建无服务器云函数产品客户端实例。

如果在当前超线程中从未创建过内建无服务器云函数产品客户端实例，默认创建新的客户端实例并将其设置为适用于当前超线程的内置客户端实例，反之复用已创建的客户端实例。

```python
def fetch_client() -> Client
```

该函数不允许指定被创建无服务器云函数产品客户端的访问凭据，这意味着您的应用程序只能使用可被自动查找并设置的环境凭据或文件凭据，详情请参阅最佳实践篇：

{% content-ref url="../../../python-best-practices/other-products/select-credential-type" %}
[select-credential-type](https://smallso.gitbook.io/tencent-cloud-sdk/python-best-practices/other-products/select-credential-type)
{% endcontent-ref %}

### 兼容性

在 Tencent Cloud SDK for Python 0.1.3 或更低版本中，您可以考虑使用非公开实验性 API 替代该函数：

```python
def get_builtin_client() -> Client
```

请注意，函数 `get_builtin_client` 与 `fetch_client` 不同，它试图在多个超线程上下文中共享同一个内建地无服务器云函数产品客户端实例，这可能会在多线程模型的应用程序中产生意外的脏数据。

最佳实践是升级并集成最新的 Tencent Cloud SDK for Python 版本。

## 参数

该函数没有参数。

## 返回值

该函数返回适用于当前超线程的内置无服务器云函数产品客户端实例。如果在相同的超线程上下文中多次调用该函数，每次调用返回的无服务器云函数产品客户端实例是相同的。

## 异常

该函数可能会主动引发以下异常类型：

#### EnvironmentError

没有找到可用的文件凭据或环境凭据。

#### KeyError

查找到的文件凭据缺失必要的访问凭据字段。

## 示例

接下来我们将通过一段 Python 代码向您演示如何使用该函数：

```python
from tencent.cloud.serverless import functions
function_client: functions.Client = functions.fetch_client()
```

如果当前复用的无服务器云函数产品客户端实例不再干净，您可以考虑使用函数 `destroy_client` 销毁适用于当前超线程的内置无服务器云函数产品客户端实例。

## 适用于

#### Tencent Cloud SDK for Python

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


---

# 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/fetch-client-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.
