Created
September 11, 2019 00:52
-
-
Save krapes/565d7b8fff6d796b8686aae07101b55a to your computer and use it in GitHub Desktop.
Retrieve data from BigTable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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