You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this quickstart, you create and manage an Azure Cosmos DB for NoSQL account from the Azure portal, and from Visual Studio Code with a Python app cloned from GitHub. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale capabilities.
29
-
30
-
## Prerequisites
31
-
32
-
- An Azure Cosmos DB Account. You options are:
33
-
* Within an Azure active subscription:
34
-
* [Create an Azure free Account](https://azure.microsoft.com/free) or use your existing subscription
35
-
* [Visual Studio Monthly Credits](https://azure.microsoft.com/pricing/member-offers/credit-for-visual-studio-subscribers)
36
-
* [Azure Cosmos DB Free Tier](../optimize-dev-test.md#azure-cosmos-db-free-tier)
37
-
* Without an Azure active subscription:
38
-
*[Try Azure Cosmos DB for free](../try-free.md), a tests environment that lasts for 30 days.
39
-
*[Azure Cosmos DB Emulator](https://aka.ms/cosmosdb-emulator)
40
-
-[Python 3.7+](https://www.python.org/downloads/), with the `python` executable in your `PATH`.
41
-
-[Visual Studio Code](https://code.visualstudio.com/).
42
-
- The [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python#overview).
43
-
-[Git](https://www.git-scm.com/downloads).
44
-
-[Azure Cosmos DB for NoSQL SDK for Python](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/cosmos/azure-cosmos)
45
-
46
-
## Important update on Python 2.x Support
47
-
48
-
New releases of this SDK won't support Python 2.x starting January 1st, 2022. Please check the [CHANGELOG](./sdk-python.md) for more information.
Now let's clone a API for NoSQL app from GitHub, set the connection string, and run it. This quickstart uses version 4 of the [Python SDK](https://pypi.org/project/azure-cosmos/#history).
69
-
70
-
1. Open a command prompt, create a new folder named git-samples, then close the command prompt.
71
-
72
-
```cmd
73
-
md git-samples
74
-
```
75
-
76
-
If you are using a bash prompt, you should instead use the following command:
77
-
78
-
```bash
79
-
mkdir "git-samples"
80
-
```
81
-
82
-
2. Open a git terminal window, such as git bash, and use the `cd` command to change to the new folder to install the sample app.
83
-
84
-
```bash
85
-
cd"git-samples"
86
-
```
87
-
88
-
3. Run the following command to clone the sample repository. This command creates a copy of the sample app on your computer.
Now go back to the Azure portal to get your connection string information and copy it into the app.
97
-
98
-
1. In your Azure Cosmos DB account in the [Azure portal](https://portal.azure.com/), select**Keys** from the left navigation. Use the copy buttons on the right side of the screen to copy the **URI** and **Primary Key** into the *cosmos_get_started.py* file in the next step.
99
-
100
-
:::image type="content" source="./media/quickstart-python/access-key-and-uri-in-keys-settings-in-the-azure-portal.png" alt-text="Get an access key and URI in the Keys settings in the Azure portal":::
101
-
102
-
2. In Visual Studio Code, open the *cosmos_get_started.py* file in*\git-samples\azure-cosmos-db-python-getting-started*.
103
-
104
-
3. Copy your **URI** value from the portal (using the copy button) and make it the value of the **endpoint** variable in*cosmos_get_started.py*.
4. Then copy your **PRIMARY KEY** value from the portal and make it the value of the **key**in*cosmos_get_started.py*. You've now updated your app with all the info it needs to communicate with Azure Cosmos DB.
109
-
110
-
`key = 'FILLME'`
29
+
Get started with the Azure Cosmos DB client library for Python to create databases, containers, and items within your account. Follow these steps to install the package and try out example code for basic tasks.
111
30
112
-
5. Save the *cosmos_get_started.py* file.
31
+
> [!NOTE]
32
+
> The [example code snippets](https://github.com/Azure-Samples/azure-cosmos-db-dotnet-quickstart) are available on GitHub as a .NET project.
This step is optional. Learn about the database resources created in code, or skip ahead to [Update your connection string](#update-your-connection-string).
117
-
118
-
The following snippets are all taken from the [cosmos_get_started.py](https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started/blob/main/cosmos_get_started.py) file.
119
-
120
-
* The CosmosClient is initialized. Make sure to update the "endpoint" and "key" values as described in the [Update your connection string](#update-your-connection-string) section.
* A new container is created, with 400 RU/s of [provisioned throughput](../request-units.md). We choose `lastName` as the [partition key](../partitioning-overview.md#choose-partitionkey), which allows us to do efficient queries that filter on this property.
* Some items are added to the container. Containers are a collection of items (JSON documents) that can have varied schema. The helper methods ```get_[name]_family_item``` return representations of a family that are stored in Azure Cosmos DB as JSON documents.
* A query is performed using SQL query syntax. Because we're using partition key values of ```lastName```in the WHERE clause, Azure Cosmos DB will efficiently route this query to the relevant partitions, improving performance.
1. In Visual Studio Code, select**View**>**Command Palette**.
147
-
148
-
2. At the prompt, enter **Python: Select Interpreter** and thenselectthe version of Python to use.
149
-
150
-
The Footer in Visual Studio Code is updated to indicate the interpreter selected.
151
-
152
-
3. Select **View**>**Integrated Terminal** to open the Visual Studio Code integrated terminal.
153
-
154
-
4. In the integrated terminal window, ensure you are in the *azure-cosmos-db-python-getting-started* folder. If not, run the following command to switch to the sample folder.
5. Run the following command to install the azure-cosmos package.
161
-
162
-
```python
163
-
pip install azure-cosmos aiohttp
164
-
```
165
-
166
-
If you get an error about access being denied when attempting to install azure-cosmos, you'll need to [run VS Code as an administrator](https://stackoverflow.com/questions/37700536/visual-studio-code-terminal-how-to-run-a-command-with-administrator-rights).
167
-
168
-
6. Run the following command to run the sample and create and store new documents in Azure Cosmos DB.
169
-
170
-
```python
171
-
python cosmos_get_started.py
172
-
```
173
-
174
-
7. To confirm the new items were created and saved, in the Azure portal, select **Data Explorer** > **AzureSampleFamilyDatabase** > **Items**. View the items that were created. For example, here is a sample JSON document for the Andersen family:
In this quickstart, you've learned how to create an Azure Cosmos DB account, create a container using the Data Explorer, and run a Python app in Visual Studio Code. You can now import additional data to your Azure Cosmos DB account.
36
+
## Prerequisites
217
37
218
-
Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster forcapacity planning.
219
-
*If all you know is the number of vcores and servers in your existing database cluster, read about [estimating request units using vCores or vCPUs](../convert-vcore-to-request-unit.md)
220
-
*If you know typical request rates for your current database workload, read about [estimating request units using Azure Cosmos DB capacity planner](estimate-ru-with-capacity-planner.md)
38
+
* An Azure account with an active subscription. [Create an account for free](https://aka.ms/trycosmosdb).
39
+
*[.NET 6.0 or later](https://dotnet.microsoft.com/download)
40
+
*[Azure Command-Line Interface (CLI)](/cli/azure/) or [Azure PowerShell](/powershell/azure/)
221
41
222
-
> [!div class="nextstepaction"]
223
-
> [Import data into Azure Cosmos DB for the API for NoSQL](../import-data.md)
0 commit comments