This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

Connect to Teradata database through Python

2795 views 0 comments last modified about 11 months ago Raymond

teradata python

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

Related pages

Useful DBC (Data Base Computer) System Views in Teradata

544 views   0 comments last modified about 7 months ago

This page summarize some of the commonly used views in Teradata. Conventions In all the views in the following sections, X views are also available though they only return rows that contain information on objects that the requesting database user owns, created, granted privilige on,...

View detail

Install Teradata Express 15.0.0.8 by Using VMware Player 6.0 in Windows

13054 views   23 comments last modified about 5 years ago

In this article, I am going to introduce how to install Teradata Express in virtual machines in Windows. Download software 1) Download VMware Player for Windows 32-bit and 64-bit from the following link (version 6.0): ...

View detail

Teradata Tutorials Summary - October 2017

308 views   0 comments last modified about 2 years ago

This post summarizes the tutorials I created in the past about Teradata. It is trying to help you gain the basic SQL skills with Teradata especially if you are a new beginner or you just move from SQL Server or Oracle. It also includes some guides about setting up your own Teradata server (latest Teradata Express version TDExpress16.10.00.03_Sles11_40GB.7z).

View detail

Setup Teradata in Microsoft Azure

325 views   0 comments last modified about 2 years ago

This page provides the steps to create a Teradata database in Microsoft cloud computing platform Azure.

View detail

Teradata SQL Tricks for SQL Server/Oracle Developers

991 views   0 comments last modified about 2 years ago

For many SQL Server or Oracle developers, you may encounter some inconveniences when writing SQL queries. For example, how to select from dummy table or local defined variables. This page summarize the equivalents in Teradata SQL.

View detail

Teradata Tutorial – DateTime Related Functions and Examples

1995 views   0 comments last modified about 2 years ago

This post summarize the common functions that are used when dealing with DateTime datatypes in Teradata.

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.