This python project creates a very simple three-tiered ToDo web app backend using Cosmos DB as the database and FastAPI as the python web framework to expose API endpoints for performing CRUD operations.
This project demonstrates the use of the Cosmos DB python SDK with FastAPI . It covers the following aspects:
- Create Azure Cosmos DB Resource in Azure Portal
- Setup the dev environment and install requisite client-side libraries
- Store Cosmos DB Resource connection credentials on our server
- Connect to Cosmos DB Resource through python client
- Define ToDoItem data model
- Create the required database and container to store ToDo Items
- Setup for API implementation
- Write functions to interact with the database
- Expose the API endpoints with FastAPI
- Test the endpoints
- Python 3.6+
Install the required libraries
- pip install fastapi
- pip install fastapi uvicorn
- pip install python-dotenv
- pip install aiohttp
- pip install azure-cosmos
- git clone [repository clone url]
- cd [repository name]
Test out the API endpoints:
- cd [repository name]
- uvicorn main:app –reload
- In your browser, go to http://localhost:8000/docs
- Learn more about Azure Cosmos DB SQL API - https://docs.microsoft.com/en-us/azure/cosmos-db/sql/