tencent-cloud-sdk


Nametencent-cloud-sdk JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://github.com/nobody-night/tencent-cloud-sdk-python
SummaryTencent Cloud SDK for Python, which provides an easier-to-use abstract client and advanced features.
upload_time2023-01-16 19:25:22
maintainer
docs_urlNone
authorMIEK
requires_python>=3.6
licenseMIT License
keywords tencent-cloud sdk-python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tencent Cloud SDK for Python

[![license](https://img.shields.io/github/license/nobody-night/stopwatch-python)](LICENSE)
[![pypi](https://img.shields.io/pypi/v/tencent-cloud-sdk)](https://pypi.org/project/tencent-cloud-sdk/)

A simple, efficient and easy to use Tencent Cloud SDK implemented in Python.

By integrating and using the Tencent Cloud SDK for Python, you can achieve fast and secure access to the Tencent Cloud API in an object-oriented programming manner, without having to pay attention to implementation details.

**Features:** Tencent Cloud SDK for Python supports full asynchronous programming.

It is important to note that you cannot use `asyncio.run` to call asynchronous entry functions. See the [asynchronous programming example code](examples/invoke_cloud_function_async.py) for details.

## Navigation
- [Homepage](https://github.com/nobody-night/tencent-cloud-sdk-python)
- [Documentation](https://smallso.gitbook.io/tencent-cloud-sdk/)
- [Release Notes](https://github.com/nobody-night/tencent-cloud-sdk-python/releases)
- [License](LICENSE)

## Installation
With the Python package manager, you can quickly install the Tencent Cloud SDK for Python.

```bash
pip install tencent-cloud-sdk
```

If you want to integrate only the products you need, you can take a subcontracted installation of the Tencent Cloud SDK for Python. First we need to install the base package:

```bash
pip install tencent-cloud-sdk-auth
pip install tencent-cloud-sdk-core
```

Then install the packages for the required products, such as Serverless Cloud Function:

```bash
pip install tencent-cloud-sdk-serverless-functions
```

**Tips:** Please note that your uninstallation method should be the same as the installation method, otherwise some packages may not be removed.

## Getting Started
With the Tencent Cloud SDK for Python, you can use Tencent Cloud products with Python's object-oriented programming.

Currently Tencent Cloud SDK for Python supports programmatic use in synchronous and asynchronous ways. Asynchronous way can write applications with better performance. Below we will show you how to use the Tencent Cloud SDK for Python in multiple consecutive code snippets using synchronous programming.

### Serverless Cloud Function
For example, Invoke has created a Serverless Cloud Function:

#### Import Package
First, we need to import the packages we use:

```python
from tencent.cloud.core import errors
from tencent.cloud.auth import credentials
from tencent.cloud.serverless import functions
```

#### Access Credentials
Next, we need to instantiate an access credential so that Tencent Cloud can determine that you have the right to operate.

```python
access_credentials = credentials.Credentials(
    secret_id = 'AKIDF3sMOAU1pOgkmrKHchX6TZQ1Mo1C5qa7',
    secret_key = 'b4JL8fwxkIgsKMXGi39yYt0ECxZw4wZf'
)
```

The `secret_id` and `secret_key` given in the sample code above are demo credentials. You need to go to the [Tencent Cloud Console](https://console.cloud.tencent.com/cam/capi) to obtain credentials for your account.

##### Environmental Credentials
The best practice is to use environmental credentials. By default, the SDK will automatically search for environment variables named `TENCENTCLOUD_SECRETID` and `TENCENTCLOUD_SECRETKEY`. If you need to customize the name of an environment variable, you must explicitly initialize the `credentials.EnvironmentalCredentials` class.

##### File Credentials
Alternatively, you can use file credentials. By default, the SDK will automatically search for a credentials file named `credentials.json` in the `.`, `./.tencent` and `~/.tencent` directories. The credentials file contains 2 attributes, `secretId` and `secretKey`. If you need to customize the path to the credentials file, you must explicitly initialize the `credentials.FileCredentials` class.

By default, you do not need to explicitly initialize any credentials, and the relevant parameters should always be set to `None` or ignored.

Remember, please prioritize the use of environmental credentials or file credentials over hard-coded credentials. For more details, please see `credentials.EnvironmentalCredentials` and `credentials.FileCredentials`. 

#### Product Client
Then, we need to instantiate a product client for Serverless Cloud Function:

```python
function_client: functions.Client = functions.Client(
    access_credentials = access_credentials
)
```

The parameter `credentials_context` is optional. If you use the Tencent Cloud SDK for Python in a Serverless Cloud Function container, this parameter can be ignored or set to `None`.

#### Invoke Cloud Function
Finally, we try to Invoke a Cloud Function and get the return value. Suppose we have a Cloud Function `hello` in the namespace `default` of the data center `ap-shanghai`:

```python
return_value: str = function_client.easy_invoke(
    region_id = 'ap-shanghai',  # Unique identifier of the data center
    namespace_name = 'default', # Name of the namespace
    function_name = 'hello'     # Name of the Cloud Function
)
```

The local variable `return_value` now has the actual return value of the Cloud Function.

The method `easy_invoke` will attempt to infer the return value in the given Cloud Function result and return the return value as a Python native data type.

**Tips:** If an error occurs for a given Cloud Function runtime, an `InvokeError` exception is thrown. The above exceptions are defined in the `tencent.cloud.serverless.functions.errors` module.

#### Close product client
When the instantiated client is no longer in use, we should explicitly close it:
```python
function_client.close()
```

See the [examples source code](examples) for the complete demo code.

### Other Tencent Cloud Products
For Tencent Cloud products that do not yet provide a product client in the Tencent Cloud SDK, a universal client can be used.

#### Import Packages
As with the Serverless Cloud Function product, we need to import the packages we use:

```python
from tencent.cloud.core import errors
from tencent.cloud.core import client
from tencent.cloud.auth import credentials
```

#### Access Credentials
As with the Serverless Cloud Function product, we need to instantiate an access credential. For this paragraph, please refer to the Serverless Cloud Function product getting started demo.

#### Product Client
Since the Tencent Cloud product we need to use does not provide a product client, we need to instantiate a universal client.

Below we take Cloud Virtual Machine (CVM) products as an example:

```python
cvm_client = client.UniversalClient(
    product_id = 'cvm',     # Unique identifier of the product
    access_credentials = access_credentials    # Access credentials
)
```

#### Use Tencent Cloud API
Finally, we try to retrieve Zone information operated by a given data center campus, which will use the Tencent Cloud API called [DescribeZones](https://cloud.tencent.com/document/api/213/15707):

```python
action_result: dict = cvm_client.action(
    region_id = 'ap-shanghai',      # Unique identifier of the data center
    action_id = 'DescribeZones',    # Unique identifier of the Tencent Cloud API
    action_parameters = None,
    action_version = '2017-03-12'   # Version name of the Tencent Cloud API
)
```

**Tips:** If a given Tencent Cloud API encounters an error, an `ActionError` exception is thrown; if the given Tencent Cloud API response is not as expected, an `ActionResultError` exception is thrown. The above exceptions are defined in the `tencent.cloud.core.errors` module.

Print unique identifiers for all zones:

```python
for zone_info in action_result['ZoneSet']:
    print(zone_info['Zone'])
```

For more ways to use Tencent Cloud SDK for Python, see our online documentation. Thank you!

## License
The Tencent Cloud SDK for Python is open source using the MIT license, which means that your use is subject to the license, please [view](LICENSE) license details.

It is worth noting that the Tencent Cloud SDK for Python is using a number of open source dependency packages that are located within a package called `tencent-cloud-sdk-common`. Our use of these dependency packages is governed by the open source license issued with them, and details of the dependency packages can be found at [Common Component Package](https://github.com/nobody-night/tencent-cloud-sdk-python/tree/master/packages/tencent-cloud-sdk-common).

## Other
If you encounter any problems during use, you are welcome to navigate to the [Issues](https://github.com/nobody-night/tencent-cloud-sdk-python/issues) page to submit and we will be happy to assist you with the problem.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nobody-night/tencent-cloud-sdk-python",
    "name": "tencent-cloud-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "tencent-cloud sdk-python",
    "author": "MIEK",
    "author_email": "king@xiaoyy.org",
    "download_url": "https://files.pythonhosted.org/packages/47/21/012520af5e6aeca3d29204b866cd0830f2aac34895d27eab00188dd10c26/tencent-cloud-sdk-0.2.7.tar.gz",
    "platform": null,
    "description": "# Tencent Cloud SDK for Python\n\n[![license](https://img.shields.io/github/license/nobody-night/stopwatch-python)](LICENSE)\n[![pypi](https://img.shields.io/pypi/v/tencent-cloud-sdk)](https://pypi.org/project/tencent-cloud-sdk/)\n\nA simple, efficient and easy to use Tencent Cloud SDK implemented in Python.\n\nBy integrating and using the Tencent Cloud SDK for Python, you can achieve fast and secure access to the Tencent Cloud API in an object-oriented programming manner, without having to pay attention to implementation details.\n\n**Features:** Tencent Cloud SDK for Python supports full asynchronous programming.\n\nIt is important to note that you cannot use `asyncio.run` to call asynchronous entry functions. See the [asynchronous programming example code](examples/invoke_cloud_function_async.py) for details.\n\n## Navigation\n- [Homepage](https://github.com/nobody-night/tencent-cloud-sdk-python)\n- [Documentation](https://smallso.gitbook.io/tencent-cloud-sdk/)\n- [Release Notes](https://github.com/nobody-night/tencent-cloud-sdk-python/releases)\n- [License](LICENSE)\n\n## Installation\nWith the Python package manager, you can quickly install the Tencent Cloud SDK for Python.\n\n```bash\npip install tencent-cloud-sdk\n```\n\nIf you want to integrate only the products you need, you can take a subcontracted installation of the Tencent Cloud SDK for Python. First we need to install the base package:\n\n```bash\npip install tencent-cloud-sdk-auth\npip install tencent-cloud-sdk-core\n```\n\nThen install the packages for the required products, such as Serverless Cloud Function:\n\n```bash\npip install tencent-cloud-sdk-serverless-functions\n```\n\n**Tips:** Please note that your uninstallation method should be the same as the installation method, otherwise some packages may not be removed.\n\n## Getting Started\nWith the Tencent Cloud SDK for Python, you can use Tencent Cloud products with Python's object-oriented programming.\n\nCurrently Tencent Cloud SDK for Python supports programmatic use in synchronous and asynchronous ways. Asynchronous way can write applications with better performance. Below we will show you how to use the Tencent Cloud SDK for Python in multiple consecutive code snippets using synchronous programming.\n\n### Serverless Cloud Function\nFor example, Invoke has created a Serverless Cloud Function:\n\n#### Import Package\nFirst, we need to import the packages we use:\n\n```python\nfrom tencent.cloud.core import errors\nfrom tencent.cloud.auth import credentials\nfrom tencent.cloud.serverless import functions\n```\n\n#### Access Credentials\nNext, we need to instantiate an access credential so that Tencent Cloud can determine that you have the right to operate.\n\n```python\naccess_credentials = credentials.Credentials(\n    secret_id = 'AKIDF3sMOAU1pOgkmrKHchX6TZQ1Mo1C5qa7',\n    secret_key = 'b4JL8fwxkIgsKMXGi39yYt0ECxZw4wZf'\n)\n```\n\nThe `secret_id` and `secret_key` given in the sample code above are demo credentials. You need to go to the [Tencent Cloud Console](https://console.cloud.tencent.com/cam/capi) to obtain credentials for your account.\n\n##### Environmental Credentials\nThe best practice is to use environmental credentials. By default, the SDK will automatically search for environment variables named `TENCENTCLOUD_SECRETID` and `TENCENTCLOUD_SECRETKEY`. If you need to customize the name of an environment variable, you must explicitly initialize the `credentials.EnvironmentalCredentials` class.\n\n##### File Credentials\nAlternatively, you can use file credentials. By default, the SDK will automatically search for a credentials file named `credentials.json` in the `.`, `./.tencent` and `~/.tencent` directories. The credentials file contains 2 attributes, `secretId` and `secretKey`. If you need to customize the path to the credentials file, you must explicitly initialize the `credentials.FileCredentials` class.\n\nBy default, you do not need to explicitly initialize any credentials, and the relevant parameters should always be set to `None` or ignored.\n\nRemember, please prioritize the use of environmental credentials or file credentials over hard-coded credentials. For more details, please see `credentials.EnvironmentalCredentials` and `credentials.FileCredentials`. \n\n#### Product Client\nThen, we need to instantiate a product client for Serverless Cloud Function:\n\n```python\nfunction_client: functions.Client = functions.Client(\n    access_credentials = access_credentials\n)\n```\n\nThe parameter `credentials_context` is optional. If you use the Tencent Cloud SDK for Python in a Serverless Cloud Function container, this parameter can be ignored or set to `None`.\n\n#### Invoke Cloud Function\nFinally, we try to Invoke a Cloud Function and get the return value. Suppose we have a Cloud Function `hello` in the namespace `default` of the data center `ap-shanghai`:\n\n```python\nreturn_value: str = function_client.easy_invoke(\n    region_id = 'ap-shanghai',  # Unique identifier of the data center\n    namespace_name = 'default', # Name of the namespace\n    function_name = 'hello'     # Name of the Cloud Function\n)\n```\n\nThe local variable `return_value` now has the actual return value of the Cloud Function.\n\nThe method `easy_invoke` will attempt to infer the return value in the given Cloud Function result and return the return value as a Python native data type.\n\n**Tips:** If an error occurs for a given Cloud Function runtime, an `InvokeError` exception is thrown. The above exceptions are defined in the `tencent.cloud.serverless.functions.errors` module.\n\n#### Close product client\nWhen the instantiated client is no longer in use, we should explicitly close it:\n```python\nfunction_client.close()\n```\n\nSee the [examples source code](examples) for the complete demo code.\n\n### Other Tencent Cloud Products\nFor Tencent Cloud products that do not yet provide a product client in the Tencent Cloud SDK, a universal client can be used.\n\n#### Import Packages\nAs with the Serverless Cloud Function product, we need to import the packages we use:\n\n```python\nfrom tencent.cloud.core import errors\nfrom tencent.cloud.core import client\nfrom tencent.cloud.auth import credentials\n```\n\n#### Access Credentials\nAs with the Serverless Cloud Function product, we need to instantiate an access credential. For this paragraph, please refer to the Serverless Cloud Function product getting started demo.\n\n#### Product Client\nSince the Tencent Cloud product we need to use does not provide a product client, we need to instantiate a universal client.\n\nBelow we take Cloud Virtual Machine (CVM) products as an example:\n\n```python\ncvm_client = client.UniversalClient(\n    product_id = 'cvm',     # Unique identifier of the product\n    access_credentials = access_credentials    # Access credentials\n)\n```\n\n#### Use Tencent Cloud API\nFinally, we try to retrieve Zone information operated by a given data center campus, which will use the Tencent Cloud API called [DescribeZones](https://cloud.tencent.com/document/api/213/15707):\n\n```python\naction_result: dict = cvm_client.action(\n    region_id = 'ap-shanghai',      # Unique identifier of the data center\n    action_id = 'DescribeZones',    # Unique identifier of the Tencent Cloud API\n    action_parameters = None,\n    action_version = '2017-03-12'   # Version name of the Tencent Cloud API\n)\n```\n\n**Tips:** If a given Tencent Cloud API encounters an error, an `ActionError` exception is thrown; if the given Tencent Cloud API response is not as expected, an `ActionResultError` exception is thrown. The above exceptions are defined in the `tencent.cloud.core.errors` module.\n\nPrint unique identifiers for all zones:\n\n```python\nfor zone_info in action_result['ZoneSet']:\n    print(zone_info['Zone'])\n```\n\nFor more ways to use Tencent Cloud SDK for Python, see our online documentation. Thank you!\n\n## License\nThe Tencent Cloud SDK for Python is open source using the MIT license, which means that your use is subject to the license, please [view](LICENSE) license details.\n\nIt is worth noting that the Tencent Cloud SDK for Python is using a number of open source dependency packages that are located within a package called `tencent-cloud-sdk-common`. Our use of these dependency packages is governed by the open source license issued with them, and details of the dependency packages can be found at [Common Component Package](https://github.com/nobody-night/tencent-cloud-sdk-python/tree/master/packages/tencent-cloud-sdk-common).\n\n## Other\nIf you encounter any problems during use, you are welcome to navigate to the [Issues](https://github.com/nobody-night/tencent-cloud-sdk-python/issues) page to submit and we will be happy to assist you with the problem.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Tencent Cloud SDK for Python, which provides an easier-to-use abstract client and advanced features.",
    "version": "0.2.7",
    "split_keywords": [
        "tencent-cloud",
        "sdk-python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fed547af445ce1b8cfa328be856b3b4c757b1c4bfd4924429064ce7bb8dcfff",
                "md5": "a413dca294e0f0324eb415d9ba8174f0",
                "sha256": "7b659a019ac9c7a40924b3bcd6d9a001b67b4bfb9c0334f201e1e57268bf786a"
            },
            "downloads": -1,
            "filename": "tencent_cloud_sdk-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a413dca294e0f0324eb415d9ba8174f0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5042,
            "upload_time": "2023-01-16T19:24:33",
            "upload_time_iso_8601": "2023-01-16T19:24:33.148949Z",
            "url": "https://files.pythonhosted.org/packages/7f/ed/547af445ce1b8cfa328be856b3b4c757b1c4bfd4924429064ce7bb8dcfff/tencent_cloud_sdk-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4721012520af5e6aeca3d29204b866cd0830f2aac34895d27eab00188dd10c26",
                "md5": "b226566389233311588491ce35ea6852",
                "sha256": "a21ad3dac8b444afcce72378d4a915e1226cd3bfede97d0bc33dd612cd603da4"
            },
            "downloads": -1,
            "filename": "tencent-cloud-sdk-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "b226566389233311588491ce35ea6852",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5354,
            "upload_time": "2023-01-16T19:25:22",
            "upload_time_iso_8601": "2023-01-16T19:25:22.394137Z",
            "url": "https://files.pythonhosted.org/packages/47/21/012520af5e6aeca3d29204b866cd0830f2aac34895d27eab00188dd10c26/tencent-cloud-sdk-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 19:25:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nobody-night",
    "github_project": "tencent-cloud-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "tencent-cloud-sdk"
}
        
Elapsed time: 0.43980s