Write and read a Bigtable cell
Write a cell and read its bytes back; Bigtable organizes wide-column data around efficient row-key access.
Create a test instance and table, write a cell, verify its bytes, and clean up.
SDK dependencies
Run in a new example directory
python3 -m venv .venv
source .venv/bin/activate
python -m pip install google-cloud-bigtable Save as hello.py
import os
from uuid import uuid4
from google.cloud import bigtable
assert os.environ['BIGTABLE_EMULATOR_HOST']
client = bigtable.Client(project=os.environ['GOOGLE_CLOUD_PROJECT'], admin=True)
instance = client.instance('guide-' + uuid4().hex[:12])
instance.create(clusters=[instance.cluster('local', location_id='us-central1-a', serve_nodes=1)]).result(timeout=60)
try:
table = instance.table('messages')
table.create(column_families={'cf': None})
row = table.direct_row(b'row-1')
row.set_cell('cf', b'message', b'hello')
row.commit()
message = table.read_row(b'row-1').cells['cf'][b'message'][0].value
assert message == b'hello'
print(message.decode())
table.delete()
finally:
instance.delete()
client.close() Run the example
python hello.py Verify the result
The command completes successfully and prints the expected output shown below.
Expected output
hello