tencent cloud

Tencent Cloud Blockchain as a Service

Release Notes
Product Introduction
Overview
Product Features
Underlying Engine
Strengths
Scenarios
Basic Concepts
Purchase Guide
Purchase Page Description
Overdue Payment Instructions
Pricing and Specification Description
Getting Started
Hyperledger Fabric
Operation Guide
Consortium
Event Center
Network Overview
Connection Management
Contract Management
Organization Management
Node Management
Blockchain Browser
Certificate management
Audit Log
Node Monitoring and Logs
Development Guide
Hyperledger Fabric
Application System Integration
API Documentation
History
Introduction
API Category
Making API Requests
Hyperledger Fabric 2.3 APIs
Data Types
Error Codes
FAQs
Product Policy
Data Processing And Security Agreement
Contact Us

Python SDK

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-04-10 00:41:11

Overview

Welcome to use the TBaaS product Software Development Kit (SDK) 3.0. SDK 3.0 is a companion tool for the TencentCloud API 3.0 platform. To facilitate Python developers in debugging and integrating with the TBaaS product API, here we introduce the TBaaS product development kit suitable for Python and provide a simple example for first-time use of the development kit. This allows you to quickly obtain the TBaaS product Python SDK and start making calls.

Dependent Environment

1. Dependent Environment: Python 2.7, 3.6 - 3.12.
2. Enable the TBaaS product through the Tencent Cloud console.
3. Obtain SecretID and SecretKey as well as the API call address (tbaas.tencentcloudapi.com).

Obtaining Installation

Install the Python SDK and before first-time use of the TencentCloud API, users need to apply for and obtain security credentials in the Tencent Cloud console. Security credentials include SecretID and SecretKey. SecretID is used to identify the identity of the API caller. SecretKey is used to encrypt signature strings and as the server-side verification key for signature string. SecretKey must be kept safely to avoid leakage.

Install Via Pip (Recommended)

Run the following command to install the TencentCloud API Python SDK in your project. If pip is not yet installed in your project environment, please see the pip official website to install it.
pip install tencentcloud-sdk-python
Note
If both Python2 and Python3 environments are set up in your project environment, use the pip3 command to initiate installation in the Python3 environment.

Install Via a Source Code Package

1. Go to the Github code hosting address to download the latest code.
2. Unzip the obtained source code package and execute the following command to install.
$ cd tencentcloud-sdk-python
$ python setup.py install

API List

View the detailed API list in the API document.

Example

Take calling the InvokeFabricChaincode API to execute a transaction with a Fabric user contract as an example:
# -*- coding: utf-8 -*-

import json
import types
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tbaas.v20180416 import tbaas_client, models
try:
# Instantiate an authentication object. Input parameters need to be passed in, including the SecretId and SecretKey of your Tencent Cloud account. Here, you also need to pay attention to keeping the confidentiality of the key pair.
cred = credential.Credential("", "")
# Instantiate an http option. It is optional and can be skipped if there are no specific requirements.
httpProfile = HttpProfile()
httpProfile.endpoint = "tbaas.intl.tencentcloudapi.com"

# Instantiate a client option. It is optional and can be skipped if there are no specific requirements.
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
# Instantiate the client object to request the product. clientProfile is optional.
client = tbaas_client.TbaasClient(cred, "ap-hongkong", clientProfile)

Instantiate a request object. Each API corresponds to a request object.
req = models.InvokeFabricChaincodeRequest()
params = {
"ClusterId": "fabric-65z42qi150",
"ChannelId": "channel-9xej4d",
"ChaincodeName": "fact",
"FuncName": "Set",
"FuncParam": [ "key", "value" ],
"WithAsyncResult": False
}
req.from_json_string(json.dumps(params))

# The returned resp is an instance of InvokeFabricChaincodeResponse, corresponding to the request object.
resp = client.InvokeFabricChaincode(req)
# Output a json-formatted string response
print(resp.to_json_string())

except TencentCloudSDKException as err:
print(err)


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan