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
Copy file name to clipboardExpand all lines: articles/postgresql/connectivity/connect-python.md
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: This quickstart provides several Python code samples you can use to
4
4
author: gkasar
5
5
ms.author: gkasar
6
6
ms.reviewer: maghan
7
-
ms.date: 08/27/2025
7
+
ms.date: 04/07/2026
8
8
ms.service: azure-database-postgresql
9
9
ms.subservice: connectivity
10
10
ms.topic: quickstart
@@ -14,7 +14,7 @@ ms.custom:
14
14
- devx-track-python
15
15
- passwordless-python
16
16
- sfi-ropc-blocked
17
-
ms.devlang: python
17
+
ms.devlang: "python"
18
18
---
19
19
20
20
# Quickstart: Use Python to connect and query data in Azure Database for PostgreSQL
@@ -65,7 +65,7 @@ python3 -m venv .venv
65
65
source .venv/bin/activate
66
66
```
67
67
68
-
> [!NOTE]
68
+
> [!NOTE]
69
69
> Ensure the virtual environment is activated before you run any `python -m pip instalL...` commands; using `python -m pip` (not a bare `pip`) ensures packages install into the same interpreter/venv you use to run the examples.
70
70
71
71
---
@@ -152,40 +152,40 @@ Optional: create a `requirements.txt` with these entries and install with `pytho
152
152
153
153
1. Get database connection information.
154
154
155
-
1. In the [Azure portal](https://portal.azure.com/), search for and select your Azure Database for PostgreSQL flexible server instance name.
156
-
1. On the server's **Overview** page, copy the fully qualified **Server name**. The fully qualified **Server name** is always of the form *\<my-server-name>.postgres.database.azure.com*.
157
-
1. On the left menu, under **Security**, select **Authentication**. Make sure your account is listed under **Microsoft Entra Admins**. If it isn't, complete the steps in [Configure Microsoft Entra integration on the server (passwordless only)](#configure-microsoft-entra-integration-on-the-server-passwordless-only).
155
+
1. In the [Azure portal](https://portal.azure.com/), search for and select your Azure Database for PostgreSQL flexible server instance name.
156
+
1. On the server's **Overview** page, copy the fully qualified **Server name**. The fully qualified **Server name** is always of the form *\<my-server-name>.postgres.database.azure.com*.
157
+
1. On the left menu, under **Security**, select **Authentication**. Make sure your account is listed under **Microsoft Entra Admins**. If it isn't, complete the steps in [Configure Microsoft Entra integration on the server (passwordless only)](#configure-microsoft-entra-integration-on-the-server-passwordless-only).
158
158
159
159
1. Set environment variables for the connection URI elements:
160
160
161
-
### [Windows](#tab/cmd)
162
-
163
-
```cmd
164
-
set DBHOST=<server-name>
165
-
set DBNAME=<database-name>
166
-
set DBUSER=<username>
167
-
set SSLMODE=require
168
-
```
169
-
170
-
### [macOS/Linux](#tab/bash)
171
-
172
-
```bash
173
-
export DBHOST=<server-name>
174
-
export DBNAME=<database-name>
175
-
export DBUSER=<username>
176
-
export SSLMODE=require
177
-
```
178
-
179
-
Replace the following placeholder values in the commands:
180
-
181
-
- `<server-name>` with the value you copied from the Azure portal.
182
-
- `<username>` with your Azure user name; for example: `john@contoso.com`.
183
-
- `<database-name>` with the name of your Azure Database for PostgreSQL flexible server database. A default database named *postgres* was automatically created when you created your server. You can use that database or create a new database by using SQL commands.
161
+
### [Windows](#tab/cmd)
162
+
163
+
```cmd
164
+
set DBHOST=<server-name>
165
+
set DBNAME=<database-name>
166
+
set DBUSER=<username>
167
+
set SSLMODE=require
168
+
```
169
+
170
+
### [macOS/Linux](#tab/bash)
171
+
172
+
```bash
173
+
export DBHOST=<server-name>
174
+
export DBNAME=<database-name>
175
+
export DBUSER=<username>
176
+
export SSLMODE=require
177
+
```
178
+
179
+
Replace the following placeholder values in the commands:
180
+
181
+
-`<server-name>` with the value you copied from the Azure portal.
182
+
-`<username>` with your Azure user name; for example: `john@contoso.com`.
183
+
-`<database-name>` with the name of your Azure Database for PostgreSQL flexible server database. A default database named *postgres* was automatically created when you created your server. You can use that database or create a new database by using SQL commands.
184
184
185
185
1. Sign in to Azure on your workstation. You can sign in using the Azure CLI, Azure PowerShell, or Azure Developer CLI.
186
186
187
-
The authentication code uses [`DefaultAzureCredential`](/python/api/azure-identity/azure.identity.defaultazurecredential) to authenticate with Microsoft Entra ID and get a token that authorizes you to perform operations on your server instance. `DefaultAzureCredential` supports a chain of authentication credential types. Among the credentials supported are credentials that you're signed in to developer tools with like the Azure CLI, Azure PowerShell, or Azure Developer CLI.
188
-
187
+
The authentication code uses [`DefaultAzureCredential`](/python/api/azure-identity/azure.identity.defaultazurecredential) to authenticate with Microsoft Entra ID and get a token that authorizes you to perform operations on your server instance. `DefaultAzureCredential` supports a chain of authentication credential types. Among the credentials supported are credentials that you're signed in to developer tools with like the Azure CLI, Azure PowerShell, or Azure Developer CLI.
188
+
189
189
#### [Password](#tab/password)
190
190
191
191
1. Copy the following code into an editor and save it in a file named *get_conn.py*.
0 commit comments