Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. from google.cloud import bigtable
  2. from google.cloud.bigtable import column_family
  3. from google.cloud.bigtable import row_filters
  4.  
  5.  
  6. client = bigtable.Client(project=project_id, admin=True)
  7. instance = client.instance(instance_id)
  8. table = instance.table(table_id)
  9.  
  10. def streamToDict(partial):
  11. def dc(byte):
  12. return byte.decode("utf-8")
  13. newDict = {}
  14. for row in partial:
  15. newDict[dc(row.row_key)] = {}
  16. for col in row.cells.keys():
  17. newDict[dc(row.row_key)][col] = {}
  18. for key in row.cells[col].keys():
  19. newDict[dc(row.row_key)][col][dc(key)] = dc(row.cells[col][key][0].value)
  20. return newDict
  21.  
  22.  
  23. partial = table.read_rows(limit=3)
  24. response = streamToDict(partial)
  25. for key in response.keys():
  26. print(response[key])
  27. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement