Skip to content

Instantly share code, notes, and snippets.

@krapes
Created September 11, 2019 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krapes/565d7b8fff6d796b8686aae07101b55a to your computer and use it in GitHub Desktop.
Save krapes/565d7b8fff6d796b8686aae07101b55a to your computer and use it in GitHub Desktop.
Retrieve data from BigTable
from google.cloud import bigtable
from google.cloud.bigtable import column_family
from google.cloud.bigtable import row_filters
client = bigtable.Client(project=project_id, admin=True)
instance = client.instance(instance_id)
table = instance.table(table_id)
def streamToDict(partial):
def dc(byte):
return byte.decode("utf-8")
newDict = {}
for row in partial:
newDict[dc(row.row_key)] = {}
for col in row.cells.keys():
newDict[dc(row.row_key)][col] = {}
for key in row.cells[col].keys():
newDict[dc(row.row_key)][col][dc(key)] = dc(row.cells[col][key][0].value)
return newDict
partial = table.read_rows(limit=3)
response = streamToDict(partial)
for key in response.keys():
print(response[key])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment