Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 3.11 KB

readme.md

File metadata and controls

77 lines (55 loc) · 3.11 KB

Azure Cosmos DB for NoSQL client library samples for Python

Getting started

This repo has a prebuilt development environment making it easy to get started.

Pull the repo

Open the repo in a development container using either Visual Studio Code or GitHub Codespaces.

Run the app

Configure your Azure Cosmos DB credentials as environment variables.

export COSMOS_ENDPOINT="<cosmos-account-URI>"
export COSMOS_KEY="<cosmos-account-PRIMARY-KEY>"

💡 TIP: If you don't have an Azure Cosmos DB account, create a free account.

Run the quickstart sample app using the azure-cosmos package from PyPI.

pip install azure-cosmos
python 001-quickstart/app.py

The application should output a single JSON object.

{
  "id": "70b63682-b93a-4c77-aad2-65501347265f",
  "categoryId": "61dba35b-4f02-45c5-b648-c6badc0cbd79",
  "categoryName": "gear-surf-surfboards",
  "name": "Yamba Surfboard",
  "quantity": 12,
  "sale": false,
  "_rid": "yzN6AIfJxe0BAAAAAAAAAA==",
  "_self": "dbs/yzN6AA==/colls/yzN6AIfJxe0=/docs/yzN6AIfJxe0BAAAAAAAAAA==/",
  "_etag": "\"2a00ccd4-0000-0200-0000-63650e420000\"",
  "_attachments": "attachments/",
  "_ts": 16457527130
}

💡 TIP: The fields assigned by Azure Cosmos DB (ex. id) will vary from this sample output.

Validate any changes you make

If you change the code, run the linter and code formatter.

pip install flake8
flake8 --verbose 001-quickstart/app.py
pip install black
black --verbose 001-quickstart/app.py

Samples

This project contains multiple samples used in Azure Cosmos DB for NoSQL documentation.

Sample Documentation
001-quickstart Quickstart: Azure Cosmos DB for NoSQL client library for Python
002-quickstart-async Quickstart: Azure Cosmos DB for NoSQL client library for Python
[003-how-to] Get started with Azure Cosmos DB for NoSQL using Python
[004-create-db] Create a database in Azure Cosmos DB for NoSQL using Python
[005-create-container] Create a container in Azure Cosmos DB for NoSQL using Python