Azure Cosmos DB
Azure Cosmos DB is Microsoft’s globally distributed multi-model database service.
Table API
Azure Cosmos DB provides Table API for applications that use Azure Table storage and need premium capabilities such as wordwide dedicated throughput, single-digit millisecodn latency, high availability, automatic secondary indexing and global distribution.
The Table API client SDKs are available for .NET, .NET Core, Java, Python, and Node.js.
Prerequisites
- Azure Subscription
- Python 3.7
Build a Table API with Python and Azure Cosmos DB
Step 1
Login to Azure portal here(portral.azure.com)
Step 2
Create a Database account
Click Create a resource -> Databases -> Azure Cosmos DB.
Step 3
You can fill your basis Details
Click Review+create
After Creating ,
Step 4
Add a Table
Select Data Explorer -> New Table.
Type throughput is - 400
Click Ok.
Step 5
Data Explorer displays the new database and table
Step 6
Add a Sample Data
In Data Explorer, expand sample-table, select Entities, and then select Add Entity.
Step 7
Now add data to the PartitionKey value box and RowKey value box, and select Add Entity.
Step 8
Clone the sample application from Github
Open the Command Prompt ,run the following code
then, run the code
Then, open the source file in visual studio.
Step 9
Update the Connection String
In the azure portal -> Select Connection String
- Copy the ACCOUNT NAME.
- Open the config.py file, and paste the ACCOUNT NAME from the portal into the STORAGE_ACCOUNT_NAME value on line 19.
- Go back to the portal and copy the PRIMARY KEY.
- Paste the PRIMARY KEY from the portal into the STORAGE_ACCOUNT_KEY value on line 20.
- Save the config.py file.
Step 10
Run the app
- In Visual Studio, right-click on the project in Solution Explorer, select the current Python environment, then right click.
- Select Install Python Package, then enter azure-storage-table
- Run F5 to run the application. Your app displays in your browser.
Conclusion
That's all. We learned about how to use Python and Azure Cosmos DB Table API to build an app by cloning an example from Github. I hope you understood this concept of Cosmos DB.