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

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:

https://pypi.python.org/pypi/teradata

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

python setup.py 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,
transactionMode="Teradata")
for row in session.execute('select getqueryband();'):
print(row)
for row in session.execute('select top 10 tablename, tablekind from dbc.tables;'):
print(row)
session.close()
input('Type <Enter> to exit...')

Details about the sample code

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

https://developer.teradata.com/tools/reference/teradata-python-module#ConnectParametrs

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:

image

image

Setup your own Teradata virtual machine

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

Install Teradata Express 15.0.0.8 by Using VMware Player 6.0 in Windows

Sample code result

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

image


info Last modified by Administrator at 7 months ago copyright This page is subject to Site terms.

More from Kontext

local_offer teradata local_offer SQL

visibility 12
thumb_up 0
access_time 14 days ago

The following code snippets show how to use round numbers to hundreds or thousands in Teradata.  warning Alert - The following code snippets are used to round to the smallest hundreds or thousands that is equal or greater than the i...

open_in_new Code snippets

local_offer teradata local_offer SQL

visibility 23
thumb_up 0
access_time 14 days ago

In article   Teradata SQL...

open_in_new Code snippets

local_offer teradata local_offer SQL

visibility 12
thumb_up 0
access_time 14 days ago

This page shows you how to use LIKE

open_in_new Code snippets

local_offer teradata local_offer SQL

visibility 11
thumb_up 0
access_time 14 days ago

This page shows how to trim or remove leading or/and trailing zeros using Teradata SQL.

open_in_new Code snippets

comment Comments (5)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

R
Raymondarrow_drop_down

Hi,

Your comment is not relevant to the content on this page. Is that a suggestion you want to make for Kontext website?

For any suggestions please post it at https://kontext.tech/forum/kontext-project 

format_quote

person pavan access_time 18 days ago
Re: Connect to Teradata database through Python

By default, links will appear as follows in all browsers:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is underlined and red
  • https://www.google.com/
reply Reply
P
pavanarrow_drop_down

By default, links will appear as follows in all browsers:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is underlined and red
  • https://www.google.com/
reply Reply
R
Raymondarrow_drop_down

Hi, is your issue resolved?  If not, please paste your detailed error messages here. 

format_quote

person U-zq6ze96t4mhbvsp2 access_time 2 years ago
Re: Connect to Teradata database through Python

thx a lot for this tutorial. But I have a problem to ensure the connection of python (installed into windows) to Teradata (installed into VMWare in the same computer).

What shoul I do?

reply Reply
R
Raymondarrow_drop_down

Hi,

Did you setup the ODBC data source successfully?

If you are encountering connection issues from your windows host to the VM, you can check my following post to ensure the connection is well established:

Connect to Teradata Virtual Machine Guest from Windows Host

format_quote

person U-zq6ze96t4mhbvsp2 access_time 2 years ago
Re: Connect to Teradata database through Python

thx a lot for this tutorial. But I have a problem to ensure the connection of python (installed into windows) to Teradata (installed into VMWare in the same computer).

What shoul I do?

reply Reply
A
Anonymousarrow_drop_down

thx a lot for this tutorial. But I have a problem to ensure the connection of python (installed into windows) to Teradata (installed into VMWare in the same computer).

What shoul I do?

reply Reply

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward