Skip to content

Commit bb709cf

Browse files
authored
Merge pull request #13 from jongio/readmeupdates
Readme updates to include CLI, SDK, and Troubleshooting
2 parents f156406 + 868c10a commit bb709cf

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

README.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,56 @@ urlFragment: azure-cosmos-db-python-getting-started
1212
# Developing a Python app using Azure Cosmos DB
1313
Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. One of the supported APIs is the SQL API, which provides a JSON document model with SQL querying and JavaScript procedural logic. This sample shows you how to use the Azure Cosmos DB with the SQL API to store and access data from a Python application.
1414

15+
> You will find a detailed Quickstart here: [Build a Python application using an Azure Cosmos DB SQL API account](https://docs.microsoft.com/azure/cosmos-db/create-sql-api-python)
16+
1517
## Running this sample
1618

1719
* Before you can run this sample, you must have the following prerequisites:
20+
* [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) or [Azure Cloud Shell](https://shell.azure.com) - Install if you want to execute commands via the CLI instead of the Azure portal.
21+
* [Azure Cosmos DB Account](https://docs.microsoft.com/azure/cosmos-db/) using the Azure portal or the Azure CLI.
22+
* Create with [Azure portal](https://portal.azure.com) and select 'Core (SQL) API'.
23+
* Create with [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) with this command: `az cosmosdb create --name <account-name> --resource-group <resource-group-name>`. Note that the default API is Core (SQL) when creating a Cosmos DB account with the CLI.
1824
* [Visual Studio Code](https://code.visualstudio.com/)
1925
* [Python extention for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python#overview)
20-
* [Python 3.6](https://www.python.org/downloads/) with \<install location\>\Python36 and \<install location>\Python36\Scripts added to your PATH.
26+
* [Python 3.6+](https://www.python.org/downloads/) with \<install location\>\Python36 and \<install location>\Python36\Scripts added to your PATH.
27+
* [Azure Cosmos DB Python SDK](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cosmos/azure-cosmos) - Install with this command: `pip install --pre azure-cosmos`
2128

22-
* Then, clone this repository using:
29+
* Clone this repository using:
2330
`git clone https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started.git`
2431

25-
* Next, substitute the endpoint and primary key in `cosmos_get_started.py` with your Cosmos DB account's values.
32+
* Open `cosmos_get_started.py` and substitute the `endpoint` (URI) and primary master `key` values with your Cosmos DB account's values from the Azure portal or via the Azure CLI with the following commands:
33+
* Endpoint: `az cosmosdb show --name <account-name> --resource-group <resource-group-name>`
34+
* Key: `az cosmosdb keys list --name <account-name> --resource-group <resource-group-name>`
35+
36+
* In Visual Studio Code, select **View** > **Integrated terminal** to open the Visual Studio Code integrated terminal.
37+
38+
* In the terminal, run `python cosmos_get_started.py`, which will output the following text:
39+
40+
```Read item with id Andersen_38c64955-fce7-4ae8-8d52-b51979f0952b. Operation consumed 1 request units
41+
Read item with id Smith_d457f895-3756-49cd-a629-e7708d7ed252. Operation consumed 1 request units
42+
Read item with id Johnson_3bd2aa16-742f-4aed-9a95-3adc548a94e3. Operation consumed 1 request units
43+
Read item with id Wakefield_c73aa98d-7104-4b01-a3da-4946081575ff. Operation consumed 1 request units
44+
Query returned 2 items. Operation consumed 3.09 request units
45+
```
2646
27-
* In Visual Studio Code, select **View** > **Integrated terminal** to open the visual Studio Code integrated terminal.
47+
* If you see the following error, then ensure you have installed the Azure Cosmos DB SDK properly with the `--pre` flag. See prerequisites section above for details.
2848
29-
* In the terminal, run ```python cosmos_get_started.py.```
49+
```
50+
Traceback (most recent call last):
51+
File "cosmos_get_started.py", line 1, in <module>
52+
from azure.cosmos import exceptions, CosmosClient, PartitionKey
53+
ImportError: cannot import name 'exceptions' from 'azure.cosmos' (...\lib\site-packages\azure\cosmos\__init__.py)
54+
```
55+
56+
* You can view the items that this sample created by navigating to the [Azure Cosmos DB Data Explorer](https://cosmos.azure.com/) and selecting the AzureSampleFamilyDatabase:
57+
58+
!['Azure Cosmos DB Data Explorer](assets/dataexplorer.png)
3059
3160
## About the code
3261
The code included in this sample is intended to get you quickly started with a Python application that connects to Azure Cosmos DB with the SQL API.
3362
3463
## More information
35-
64+
- [Quickstart: Build a Python application using an Azure Cosmos DB SQL API account](https://docs.microsoft.com/azure/cosmos-db/create-sql-api-python)
3665
- [Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/introduction)
3766
- [Azure Cosmos DB: SQL API introduction](https://docs.microsoft.com/azure/cosmos-db/sql-api-introduction)
3867
- [Azure Cosmos DB Python SDK Reference](https://docs.microsoft.com/azure/cosmos-db/sql-api-sdk-python)

assets/dataexplorer.png

74.2 KB
Loading

0 commit comments

Comments
 (0)