Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Last active February 9, 2020 20:22
Show Gist options
  • Save rchardptrsn/03c8e3c9ce271495dc2c7337f1775e68 to your computer and use it in GitHub Desktop.
Save rchardptrsn/03c8e3c9ce271495dc2c7337f1775e68 to your computer and use it in GitHub Desktop.
# Create a collection of items in a Container
# Items are the individual rows/records of your dataset
# https://docs.microsoft.com/en-us/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient?view=azure-python#createcontainer-database-link--collection--options-none-
database_link = 'dbs/' + 'HDIdatabase'
container_definition = {'id': 'HDIcontainer',
'partitionKey':
{
'paths': ['/country'],
'kind': documents.PartitionKind.Hash
}
}
try:
container = client.CreateContainer(database_link=database_link,
collection=container_definition,
options={'offerThroughput': 400})
except errors.HTTPFailure as e:
if e.status_code == http_constants.StatusCodes.CONFLICT:
container = client.ReadContainer("dbs/" + database['id'] + "/colls/" + container_definition['id'])
else:
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment