Connect to Teradata database through Python

visibility 20,288 comment 5 access_time 2 years ago languageEnglish timeline Stats
timeline Stats
Page index 12.78

Teradata published an official Python module which can be used in DevOps projects. More details can be found at the following GitHub site:

Install Teradata module

If pip is installed, you can directly install this module through the following command:

pip install Teradata

If not, you can download the package in the following URL:

After downloading, unzip the package and then use command prompt to navigate to the directory that contains file and then run the following command to install:

python install

Sample Code

"""Test teradata driver"""
import teradata
import sys
udaExec = teradata.UdaExec(
appName="HelloWorld", version="1.0", logConsole=False)
session = udaExec.connect(method="odbc", dsn="td16vm",
username="dbc", password="dbc", autocommit=True,
for row in session.execute('select getqueryband();'):
for row in session.execute('select top 10 tablename, tablekind from dbc.tables;'):
input('Type <Enter> to exit...')

Details about the sample code

When connecting to Teradata, the following parameters can be configured:

In the sample code, transaction mode is set as Teradata; auto commit is set as True (transactions will be committed automatically); connecting method is ODBC (the other options is REST), DSN is using td16vm which was setup using the following parameters in my computer:



Setup your own Teradata virtual machine

If you have no Teradata instance, you can setup one following this post:

Install Teradata Express by Using VMware Player 6.0 in Windows

Sample code result

The following screenshot shows the running result in my IDE (Visual Studio Code):


info Last modified by Administrator 2 years ago copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
Load XML File into BigQuery
visibility 1,850
thumb_up 0
access_time 2 years ago
Load XML File into BigQuery
Convert List to Spark Data Frame in Python / Spark
visibility 11,067
thumb_up 0
access_time 2 years ago
Pandas DataFrame Plot - Pie Chart
visibility 39,799
thumb_up 8
access_time 2 years ago
Pandas DataFrame Plot - Pie Chart