All Products
Search
Document Center

Tablestore:Delete a row

Last Updated:Aug 04, 2026

Use Tablestore SDK for Python to delete a row by primary key and optionally specify a delete condition or local transaction.

Prerequisites

Install the Tablestore SDK for Python and initialize a client.

Function description

Call delete_row to delete an entire row by primary key.

def delete_row(
    self,
    table_name,
    row=None,
    condition=None,
    return_type=None,
    transaction_id=None,
    **kwargs,
)

The following example deletes the row whose primary key is ("device", 1) from example_table.

primary_key = [("partition", "device"), ("id", 1)]
row = Row(primary_key)
condition = Condition(RowExistenceExpectation.EXPECT_EXIST)

consumed, return_row = client.delete_row(
    "example_table",
    row,
    condition,
)
print("Write CU: %s" % consumed.write)

Parameters

The delete_row method contains the following parameters.

Name

Type

Description

table_name (required)

str

The name of the table.

row (required)

Row

The primary key of the row to delete. Row.primary_key must contain all primary key columns. Their names, order, number, and types must match the primary key schema of the table.

condition (optional)

Condition

The delete condition. By default, row existence is not checked. For more information, see Use conditional updates.

return_type (optional)

ReturnType

The return type. RT_NONE, the default value, returns no data. RT_PK returns the primary key.

transaction_id (optional)

str

The local transaction ID. Specify this parameter only for deletes in a local transaction. For more information, see Use local transactions.

Response

delete_row returns the following values.

Field

Type

Description

consumed

CapacityUnit

The read and write CUs consumed by the operation.

return_row

Row

The returned row. If return_type is RT_PK, the primary key is returned. Otherwise, this value is None.