Skip to content

Python SDK Quick Start

This article provides a quick start for common operations using the Python SDK. You will learn how to install the SDK, configure access credentials, and perform basic operations such as retrieving the latest upgrade information.

Notes

  • When making requests using the Python SDK, you need to initialize a Client instance. This article creates a Client by loading default configurations. For more configuration options about the client, please refer to Configuring the Client.

Prerequisites

  • Registered upgradeLink account.
  • Obtained AccessKey and AccessSecret.
  • Configured URL application upgrade strategy.

Obtain Credentials

img.jpg

Install Python SDK

  • Please install the Python compilation and runtime environment first. Check if Python is installed successfully with the following command:
shell
  python --version

If there is no suitable Python compilation and runtime environment currently, please refer to Python Installation for download and installation.

  • Execute the following command to install the Python SDK code package.
shell
pip install upgradelink-api-python
  • Use the following code to import the Python SDK code package.
python
import upgradelink_api_python

Quick Usage

The following sample program demonstrates how to initialize a Client and retrieve the latest upgrade information for a URL application.

Get Latest Upgrade Information for URL Application

python

from upgradelink_api_python import models as upgrade_link_models
from upgradelink_api_python.client import Client

def main():
    # Create configuration object
    config = upgrade_link_models.Config(
        access_key="mui2W50H1j-OC4xD6PgQag",  # Example key, please replace with your actual key
        access_secret="PEbdHFGC0uO_Pch7XWBQTMsFRxKPQAM2565eP8LJ3gc",  # Example key, please replace with your actual key
        protocol="HTTPS",
        endpoint="api.upgrade.toolsetlink.com"
    )
    
    # Create client
    client = Client(config)
    
    # Set request parameters
    url_key = "uJ47NPeT7qjLa1gL3sVHqw"  # Unique identifier for URL application
    version_code = 1  # Current application version number
    appoint_version_code = 0  # Specified version number, 0 indicates the latest version
    dev_model_key = ""  # Device model identifier, optional
    dev_key = ""  # Device identifier, optional
    
    # Build request object
    request = upgrade_link_models.UrlUpgradeRequest(
        url_key=url_key,
        version_code=version_code,
        appoint_version_code=appoint_version_code,
        dev_model_key=dev_model_key,
        dev_key=dev_key
    )
    
    try:
        # Call API interface
        response = client.url_upgrade(request)
        
        # Process response result
        if response.code == 200:
            print("Request successful!")
            print(f"Message: {response.msg}")
            print(f"Trace ID: {response.trace_id}")
            
            # Process upgrade data
            if response.data:
                data = response.data
                print("\nUpgrade Information:")
                print(f"URL Key: {data.url_key}")
                print(f"Version Name: {data.version_name}")
                print(f"Version Code: {data.version_code}")
                print(f"URL Path: {data.url_path}")
                print(f"Upgrade Type: {data.upgrade_type}")  # 1: Forced upgrade, 2: Recommended upgrade, 3: Optional upgrade
                print(f"Upgrade Prompt Content: {data.prompt_upgrade_content}")
                
                # Handle different upgrade types
                if data.upgrade_type == 1:
                    print("\nThis is a forced upgrade. Please upgrade the application immediately.")
                    # Execute forced upgrade logic
                elif data.upgrade_type == 2:
                    print("\nThis is a recommended upgrade. It is recommended that users upgrade the application.")
                    # Execute recommended upgrade logic
                elif data.upgrade_type == 3:
                    print("\nThis is an optional upgrade. Users can choose whether to upgrade.")
                    # Execute optional upgrade logic
        else:
            print(f"Request failed, error code: {response.code}")
            print(f"Error message: {response.msg}")
            print(f"Trace ID: {response.trace_id}")
            
    except Exception as e:
        print(f"Error occurred when calling API: {e}")

if __name__ == "__main__":
    main()

toolsetlink@163.com