Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Using the CData ODBC Driver for AlloyDB in PyCharm
Connect to AlloyDB as an ODBC data source in PyCharm using the CData ODBC Driver for AlloyDB.
The CData ODBC Drivers can be used in any environment that supports loading an ODBC Driver. In this tutorial we will explore using the CData ODBC Driver for AlloyDB from within PyCharm. Included are steps for adding the CData ODBC Driver as a data source, as well as basic PyCharm code to query the data source and display results.
To begin, this tutorial will assume that you have already installed the CData ODBC Driver for AlloyDB as well as PyCharm.
Add Pyodbc to the Project
Follow the steps below to add the pyodbc module to your project.
- Click File -> Settings to open the project settings window.
- Click Project Interpreter from the Project: YourProjectName menu.
- To add pyodbc, click the + button and enter pyodbc.
- Click Install Package to install pyodbc.

Connect to AlloyDB
You can now connect with an ODBC connection string or a DSN. See the Getting Started section in the CData driver documentation for a guide to creating a DSN on your OS.
The following connection properties are usually required in order to connect to AlloyDB.
- Server: The host name or IP of the server hosting the AlloyDB database.
- User: The user which will be used to authenticate with the AlloyDB server.
- Password: The password which will be used to authenticate with the AlloyDB server.
You can also optionally set the following:
- Database: The database to connect to when connecting to the AlloyDB Server. If this is not set, the user's default database will be used.
- Port: The port of the server hosting the AlloyDB database. This property is set to 5432 by default.
Authenticating with Standard Authentication
Standard authentication (using the user/password combination supplied earlier) is the default form of authentication.
No further action is required to leverage Standard Authentication to connect.
Authenticating with pg_hba.conf Auth Schemes
There are additional methods of authentication available which must be enabled in the pg_hba.conf file on the AlloyDB server.
Find instructions about authentication setup on the AlloyDB Server here.
Authenticating with MD5 Authentication
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to md5.
Authenticating with SASL Authentication
This authentication method must be enabled by setting the auth-method in the pg_hba.conf file to scram-sha-256.
Authenticating with Kerberos
The authentication with Kerberos is initiated by AlloyDB Server when the ∏ is trying to connect to it. You should set up Kerberos on the AlloyDB Server to activate this authentication method. Once you have Kerberos authentication set up on the AlloyDB Server, see the Kerberos section of the help documentation for details on how to authenticate with Kerberos.
Below is the syntax for a DSN:
[CData AlloyDB Source]
Driver = CData ODBC Driver for AlloyDB
Description = My Description
User = alloydb
Password = admin
Database = alloydb
Server = 127.0.0.1
Port = 5432
Execute SQL to AlloyDB
Instantiate a Cursor and use the execute method of the Cursor class to execute any SQL statement.
import pyodbc
cnxn = pyodbc.connect('DRIVER={CData ODBC Driver for AlloyDB};User = alloydb;Password = admin;Database = alloydb;Server = 127.0.0.1;Port = 5432')
cursor = cnxn.cursor()
cursor.execute("SELECT ShipName, ShipCity FROM Orders WHERE ShipCountry = 'USA'")
rows = cursor.fetchall()
for row in rows:
print(row.ShipName, row.ShipCity)
After connecting to AlloyDB in PyCharm using the CData ODBC Driver, you will be able to build Python apps with access to AlloyDB data as if it were a standard database. If you have any questions, comments, or feedback regarding this tutorial, please contact us at support@cdata.com.