Skip to content

Instantly share code, notes, and snippets.

@moraisaugusto
Created June 24, 2019 07:54
Show Gist options
  • Save moraisaugusto/4f4e0f21b2fb1f53a5b16bbf9112bc03 to your computer and use it in GitHub Desktop.
Save moraisaugusto/4f4e0f21b2fb1f53a5b16bbf9112bc03 to your computer and use it in GitHub Desktop.
Create a Azure Tabular Table storage
#!/usr/bin/env python3
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
def execute():
"""docstring for execute"""
the_connection_string = "DefaultEndpointsProtocol=https;AccountName=MYACCOUNTNAME;AccountKey=ACCOUNTKEY;EndpointSuffix=core.windows.net"
table_service = TableService(endpoint_suffix="table.core.windows.net", connection_string=the_connection_string)
table_service.create_table('MyData')
task001 = {'PartitionKey': 'tasksSeattle', 'RowKey': '001', 'description' : 'Go grocery shopping', 'priority' : 400}
task002 = {'PartitionKey': 'tasksSeattle', 'RowKey': '002', 'description' : 'Clean the bathroom', 'priority' : 100}
task003 = {'PartitionKey': 'tasksSeattle', 'RowKey': '003', 'description' : 'Go out grocery shopping', 'priority' : 400}
task004 = {'PartitionKey': 'tasksSeattle', 'RowKey': '004', 'description' : 'Clean the kitcken', 'priority' : 100}
task005 = {'PartitionKey': 'tasksSeattle', 'RowKey': '005', 'description' : 'Go rest shopping', 'priority' : 400}
task006 = {'PartitionKey': 'tasksSeattle', 'RowKey': '006', 'description' : 'Go laundry shopping', 'priority' : 400}
task007 = {'PartitionKey': 'tasksSeattle', 'RowKey': '007', 'description' : 'Clean the room', 'priority' : 200}
task008 = {'PartitionKey': 'tasksSeattle', 'RowKey': '008', 'description' : 'Clean the kitchen', 'priority' : 100}
with table_service.batch('MyData') as batch:
batch.insert_entity(task001)
batch.insert_entity(task002)
batch.insert_entity(task003)
batch.insert_entity(task004)
batch.insert_entity(task005)
batch.insert_entity(task006)
batch.insert_entity(task007)
batch.insert_entity(task008)
if __name__ == '__main__':
execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment