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 worldwide dedicated throughput, single-digit millisecond 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
Step 1. Log in to the 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 in your basic 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 the sample, 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, and run the following code.
md "C:\git-samples"
then, run the code.
cd "C:\git-samples"
Finally, run the code.
git clone https://github.com/Azure-Samples/storage-python-getting-started.git
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 understand this concept of Cosmos DB.