Skip to main content

Python SDK for TiDB Cloud

Project description

Python SDK for TiDB Cloud

Introduction

tidbcloudy is a Python package that provides a high-level interface to access TiDB Cloud. For more information about TiDB Cloud API, see TiDB Cloud API Documentation.

Installation

pip install tidbcloudy

Make sure that you have mysql client installed in your environment. For more information, see PyMySQL/mysqlclient.

Usage

List all resources in your organization

import tidbcloudy

api = tidbcloudy.TiDBCloud(public_key="public_key", private_key="private_key")
for project in api.iter_projects():
    print(project)
    for cluster in project.iter_clusters():
        print(cluster)
        for backup in cluster.iter_backups():
            print(backup)
    for restore in project.iter_restores():
        print(restore)

Create a cluster

import tidbcloudy
from tidbcloudy.specification import CreateClusterConfig

api = tidbcloudy.TiDBCloud(public_key="public_key", private_key="private_key")
project = api.get_project("project_id", update_from_server=True)

config = CreateClusterConfig()
config.set_name("cluster-name") \
    .set_cluster_type("cluster-type") \
    .set_cloud_provider("cloud-provider") \
    .set_region("region-code") \
    .set_port(4399) \
    .set_root_password("root_password") \
    .set_component("tidb", "8C16G", 1) \
    .set_component("tikv", "8C32G", 3, 500) \
    .add_current_ip_access()

cluster = project.create_cluster(config)
cluster.wait_for_ready()

Modify a cluster

import tidbcloudy
from tidbcloudy.specification import UpdateClusterConfig

api = tidbcloudy.TiDBCloud(public_key="public_key", private_key="private_key")
project = api.get_project("project_id", update_from_server=True)
cluster = project.get_cluster("cluster_id")
new_config = UpdateClusterConfig()
new_config.update_component("tiflash", node_quantity=1, node_size="8C64G", storage_size_gib=500)
cluster.update(new_config)

Create a backup

import tidbcloudy

api = tidbcloudy.TiDBCloud(public_key="public_key", private_key="private_key")
project = api.get_project("project_id", update_from_server=True)
cluster = project.get_cluster("cluster_id")
backup = cluster.create_backup(name="backup-1", description="created by tidbcloudy")
print(backup)

Create a restore

import tidbcloudy
from tidbcloudy.specification import CreateClusterConfig

api = tidbcloudy.TiDBCloud(public_key="public_key", private_key="private_key")
project = api.get_project("project_id", update_from_server=True)
cluster = project.get_cluster("cluster_id")

backup_config = CreateClusterConfig()
backup_config \
    .set_cluster_type("cluster-type") \
    .set_cloud_provider("cloud-provider") \
    .set_region("region-code") \
    .set_port(4399) \
    .set_root_password("root-password") \
    .set_component("tidb", "8C16G", 1) \
    .set_component("tikv", "8C32G", 3, 500) \
    .set_component("tiflash", "8C64G", 2, 500) \
    .add_current_ip_access()
restore = project.create_restore(backup_id="backup_id", name="restore-by-tidbcloudy", cluster_config=backup_config)
print(restore)

Enhancements comparing to original TiDB Cloud API

  • Iterate over resources instead of manual pagination
  • Connect to a TiDB cluster using the MySQL client
  • Get a Project using a Project ID
  • Configure your cluster with method chaining
  • Add your current IP address automatically
  • Wait for the cluster to be ready when creating/modifying a cluster
  • Case-insensitive when setting cluster type, cloud provider, and component name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tidbcloudy-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tidbcloudy-1.0.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file tidbcloudy-1.0.0.tar.gz.

File metadata

  • Download URL: tidbcloudy-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.9.13 Darwin/21.6.0

File hashes

Hashes for tidbcloudy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d6bf9daeba1eeb37c026bb35bc6987d8a38202ef47c06c3e7b64d583a6cd0f96
MD5 7601dc23fdb99bd4fb814adad7f65b56
BLAKE2b-256 3372cad3bf57aa4c9b912bfdb6e2ce77fa573e6b1e3e58c4298349e9d19cd6f1

See more details on using hashes here.

File details

Details for the file tidbcloudy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tidbcloudy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.9.13 Darwin/21.6.0

File hashes

Hashes for tidbcloudy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0963f2f4873dccc19adfc52889ac13adef01d9cfccbf628eb83719f645fde2e4
MD5 ee14c8a3412a62777362ee3f9a880161
BLAKE2b-256 afb1bb505f3bea723eb34b0d97cfea66a0b5e918dc8f52f9d11354c95a24d96b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page