Skip to content

Latest commit

 

History

History
121 lines (74 loc) · 5.22 KB

create-table-python.md

File metadata and controls

121 lines (74 loc) · 5.22 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author
Quickstart: Table API with Python - Azure Cosmos DB | Microsoft Docs
This quickstart shows how to use the Azure Cosmos DB Table API to create an application with the Azure portal and Python
cosmos-db
mimig1
jhubbard
cosmos-db
na
python
quickstart
11/16/2017
mimig

Quickstart: Build a Table API app with Python and Azure Cosmos DB

This quickstart shows how to use Python and the Azure Cosmos DB Table API to build an app by cloning an example from GitHub. This quickstart also shows you how to create an Azure Cosmos DB account and how to use Data Explorer to create tables and entities in the web-based Azure portal.

Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. You can quickly create and query document, key/value, wide-column, and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Azure Cosmos DB.

Prerequisites

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE cosmos-db-emulator-docdb-api]

In addition:

  • If you don’t already have Visual Studio 2017 installed, you can download and use the free Visual Studio 2017 Community Edition. Make sure that you enable Azure development during the Visual Studio setup.
  • Python Tools for Visual Studio from GitHub. This tutorial uses Python Tools for VS 2015.
  • Python 2.7 from python.org

Create a database account

Important

You need to create a new Table API account to work with the generally available Table API SDKs. Table API accounts created during preview are not supported by the generally available SDKs.

[!INCLUDE cosmos-db-create-dbaccount-table]

Add a table

[!INCLUDE cosmos-db-create-table]

Add sample data

You can now add data to your new table using Data Explorer.

  1. In Data Explorer, expand sample-table, click Entities, and then click Add Entity.

    Create new entities in Data Explorer in the Azure portal

  2. Now add data to the PartitionKey value box and RowKey value boxes, and click Add Entity.

    Set the Partition Key and Row Key for a new entity

    You can now add more entities to your table, edit your entities, or query your data in Data Explorer. Data Explorer is also where you can scale your throughput and add stored procedures, user defined functions, and triggers to your table.

Clone the sample application

Now let's clone a Table app from github, set the connection string, and run it. You'll see how easy it is to work with data programmatically.

  1. Open a git terminal window, such as git bash, and use the cd command to change to a folder to install the sample app.

    cd "C:\git-samples"
  2. Run the following command to clone the sample repository. This command creates a copy of the sample app on your computer.

    git clone https://github.com/Azure-Samples/storage-python-getting-started.git
  3. Then open the solution file in Visual Studio.

Update your connection string

Now go back to the Azure portal to get your connection string information and copy it into the app. This enables your app to communicate with your hosted database.

  1. In the Azure portal, click Connection String.

    View and copy the CONNECTION STRING in the Connection String pane

  2. Copy the ACCOUNT NAME using the button on the right side.

  3. Open the config.py file, and paste the ACCOUNT NAME from the portal into the STORAGE_ACCOUNT_NAME value on line 19.

  4. Go back to the portal and copy the PRIMARY KEY.

  5. Paste the PRIMARY KEY from the portal into the STORAGE_ACCOUNT_KEY value on line 20.

  6. Save the config.py file.

Run the app

  1. In Visual Studio, right-click on the project in Solution Explorer, select the current Python environment, then right click.

  2. Select Install Python Package, then type in azure-storage-table

  3. Run F5 to run the application. Your app displays in your browser.

You can now go back to Data Explorer and see query, modify, and work with this new data.

Review SLAs in the Azure portal

[!INCLUDE cosmosdb-tutorial-review-slas]

Clean up resources

[!INCLUDE cosmosdb-delete-resource-group]

Next steps

In this quickstart, you've learned how to create an Azure Cosmos DB account, create a table using the Data Explorer, and run an app. Now you can query your data using the Table API.

[!div class="nextstepaction"] Import table data to the Table API