Use the Python SDK to write a single row of data to a Tablestore data table.
Prerequisites
Method
put_row(self, table_name, row, condition=None, return_type=None, transaction_id=None)Examples
The following example writes a row with the primary key value row1 to the test_table table.
try:
# Construct the primary key and attribute columns.
primary_key = [('id', 'row1')]
attribute_columns = []
# Construct the row to write.
row = Row(primary_key, attribute_columns)
# Call the put_row method to write the row.
consumed, return_row = client.put_row('test_table', row)
print('* Read CU Cost: %s' % consumed.read)
print('* Write CU Cost: %s' % consumed.write)
except Exception as e:
print("Put row failed with error: %s" % e)To add an attribute column:
attribute_columns = [('col1','val1')]To specify a data version, assign a version to each attribute column.
attribute_columns = [('col1','val1', int(time.time() * 1000))]