Azure DocumentDB Python SDK (Legacy)

2.3.5 · abandoned · verified Thu Apr 16

This is the legacy Python SDK for Azure DocumentDB, which was rebranded to Azure Cosmos DB. This `pydocumentdb` package is no longer maintained and has been superseded by the `azure-cosmos` package. Users should migrate to `azure-cosmos` for current development. The last stable version released under this name was 2.3.5.

Common errors

Warnings

Install

Imports

Quickstart

Shows how to initialize the legacy DocumentDB client. This code is for the `pydocumentdb` package, which is no longer maintained. Users are strongly advised to migrate to `azure-cosmos` for any new development or existing applications connecting to Azure Cosmos DB.

import os
from pydocumentdb.document_client import DocumentClient

# These environment variables would be for an *old* DocumentDB account.
# Modern Azure Cosmos DB accounts use the azure-cosmos SDK.
HOST = os.environ.get("DOCUMENTDB_HOST", "https://your-old-documentdb-account.documents.azure.com:443/")
MASTER_KEY = os.environ.get("DOCUMENTDB_MASTER_KEY", "YOUR_OLD_MASTER_KEY")

if not HOST or not MASTER_KEY or HOST == "https://your-old-documentdb-account.documents.azure.com:443/":
    print("Warning: Skipping DocumentDB client init. Please set DOCUMENTDB_HOST and DOCUMENTDB_MASTER_KEY for an *old* DocumentDB account.")
else:
    try:
        client = DocumentClient(HOST, {'masterKey': MASTER_KEY})
        print(f"Successfully initialized legacy DocumentDB client for host: {HOST}")
        # Example: Read databases (requires an active old DocumentDB account)
        # databases = list(client.ReadDatabases())
        # print(f"Found {len(databases)} databases.")
    except Exception as e:
        print(f"Error initializing legacy DocumentDB client: {e}")

view raw JSON →