Microsoft Dev Blogs

Getting Started with Azure Cosmos DB Using the Python SDK

thumbnail

Table of Contents

  • Key Concepts
  • Prerequisites
  • Series Overview
    • 5-Minute Setup Guide
    • Creating and Reading Documents
    • Updating and Deleting Items
    • Cross-partition queries
  • Wrap-Up
  • Leave a review
  • About Azure Cosmos DB

Key Concepts

Before diving into the code and videos, here are some terms you need to know:

  • Azure Cosmos DB Account
  • Database
  • Partition Key

Prerequisites

Make sure you have the following setup before following along:

  • Azure Cosmos DB account using the NoSQL API
  • One database (e.g., BookRecommendationsDB)
  • One container (e.g., books) with /category as the partition key
  • Azure CLI installed and logged in
  • Azure Identity
  • Python 3.11 or higher
  • Required Python packages installed
  • Copy .env file with your configuration
  • Clone the series GitHub repository

Series Overview

Each video in the series focuses on a key aspect of using Cosmos DB with Python. Below is a quick summary, but make sure to watch the videos for the full walkthroughs and code demos!

  1. 5-Minute Setup Guide: Authenticate with Azure using Azure Identity and connect to your Azure Cosmos DB account.

  2. Creating and Reading Documents: Creating new items with nested objects and arrays, and reading all items from a container.

  3. Updating and Deleting Items: Learn when to use upsert, update an existing document using replace_item, and delete items by their ID and partition key.

  4. Cross-partition queries: Perform cross-partition queries to retrieve data.

Wrap-Up

This series is designed to help you get up and running quickly with Azure Cosmos DB using Python – from setting up your environment to writing real-world queries that bring your data to life. Go watch the videos, follow along with the code, and experiment with your own data.

Leave a review

Tell us about your Azure Cosmos DB experience! Leave a review on PeerSpot and we’ll gift you $50.

About Azure Cosmos DB

Azure Cosmos DB is a fully managed and serverless NoSQL and vector database for modern app development, including AI applications. Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on X, YouTube, and LinkedIn.