This topic describes how to query information of a table using Tablestore SDK for Python.
Prerequisites
A client is initialized. For more information, see Initialize a Tablestore client.
Method Description
def describe_table(self, table_name)Sample code
The following sample code demonstrates how to query information of the test_table table.
try:
response = client.describe_table('test_table')
# Obtain the table schema.
table_meta = response.table_meta
print("* Table name: %s" % table_meta.table_name)
print("* Primary key information")
for primary_key in table_meta.schema_of_primary_key:
print(primary_key)
print("* Predefined column information")
for defined_column in table_meta.defined_columns:
print(defined_column)
# Obtain the table configuration.
table_options = response.table_options
print("* Table configuration")
print("Max versions: %s" % table_options.max_version)
print("Time to live: %s" % table_options.time_to_live)
print("Max version offset: %s" % table_options.max_time_deviation)
print("Update allowed: %s" % table_options.allow_update)
# Obtain the table encryption settings.
sse_details = response.sse_details
print("* Table encryption configuration")
print("Table encryption enabled: %s" % sse_details.enable)
if sse_details.enable:
if sse_details.key_type == SSEKeyType.SSE_KMS_SERVICE:
print("Encryption method: KMS encryption")
else:
print("Encryption method: BYOK encryption")
# Obtain the reserved read/write throughput of the table.
reserved_throughput_details = response.reserved_throughput_details
print("* Reserved read/write throughput")
print("Reserved read throughput: %s" % reserved_throughput_details.capacity_unit.read)
print("Reserved write throughput: %s" % reserved_throughput_details.capacity_unit.write)
# Obtain secondary index information.
for index_meta in response.secondary_indexes:
print("* Secondary index name: %s" % index_meta.index_name)
print("Primary key columns: %s" % index_meta.primary_key_names)
print("Predefined columns: %s" % index_meta.defined_column_names)
print("Secondary index type: %s" % SecondaryIndexType(index_meta.index_type).name)
except Exception as e:
print("describe table failed. %s" % e)