Cosmos DB Python Scripting

This project includes several python scripts that can be used to interact with an Azure Cosmos DB Database Container.

This project was started from the azure python quickstart tutorial.

The python scripts use the Azure Python Cosmos SDK.

Working with Cosmos DB python function calls are based on examples in the Azure python SDK repo.

In the data folder there is a CSV file of electronic vehicle information retrieved freely from catalog.data.gov.

If you want to play with the scripts in this project, first you must create an Azure Cosmos DB account and database with a container. I recommend following the steps in the "setting up" step of the Azure Cosmos DB Quickstart Tutorial.

Before working with the scripts in this project, please also create a .env file in the project root with the following values:

COSMOS_ENDPOINT=""
COSMOS_KEY=""
DATABASE_ID=""
CONTAINER_ID=""

In the "scripts" folder there are the following scripts that work with a Cosmos DB container:

  • data_load.py loads values from the ELECTRONIC_VEHICLE_POPULATION_DATA.csv file
  • data_query.py queries values from the Electronic Vehicles data with a specific VIN (first 10 digits only)
  • data_delete.py deletes values from the Electronic Vehicles data with a specific VIN (first 10 digits only)
  • data_update.py updates values from the Electronic Vehicles data for a specicifc VIN (first 10 digits only)

When fininished working with the data, I recommend deleting the database and container unless you wanted to do more with the sample values.