Teradata Python Module - How to assign username/password to Python variables

Tools & Utilities
AWT
Enthusiast

Teradata Python Module - How to assign username/password to Python variables

Hi there,

 

I am reading this -- https://developer.teradata.com/tools/reference/teradata-python-module

How do I assign the username and password to Python variables?

 

# Application Configuration
[CONFIG]
appName=MyTest1
version=2
logConsole=False
dataSourceName=TDPROD1
table=DBC.DBCInfo

# Default Data Source Configuration
[DEFAULT]
method=odbc
charset=UTF8

# Data Source Definition
[TDPROD1]
system=tdprod1
username=lasradm
password=MyPassW0rd!

 Assigning the python variables with the variables defined in the [TDPROD1] data source definition defined in udaexec.ini is possible or not? If yes, can you share a sample how it can be done?

 

Thanks


Accepted Solutions
AWT
Enthusiast

Re: Teradata Python Module - How to assign username/password to Python variables

Fred,

 

mytbl = udaExec.config["table"] is exactly what I am looking for.

 

Thanks

1 ACCEPTED SOLUTION
4 REPLIES
Teradata Employee

Re: Teradata Python Module - How to assign username/password to Python variables

You can use the config dictionary-like object to access values in the [Config] section, but not the data source section(s).

AWT
Enthusiast

Re: Teradata Python Module - How to assign username/password to Python variables

Fred,

 

Thanks for the quick response. My challenge is I am not quite sure how to assign the variables in [CONFIG] section to Python variables.

It seems the [CONFIG] variables are only valid within the udaExec.connect statement. If you could show one example how these [CONFIG] variabels can be passed on to Python variables, that would be appreciated.

 

For example, my sample code:

 

import re
import teradata

udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0", logConsole=False)
mysql="select transaction_mode from dbc.sessioninfov where sessionno=SESSION"
with udaExec.connect(method="${method}",sessionmode="${sesmode}",system="${system}",username="${username}", password="${password}") as session:
    for row in session.execute(re.sub('\s+',' ',mysql).strip(),queryTimeout=60,continueOnError=True):
        print(str(row)+'\n')

 

 

My sample udaexec.ini

+++++++++++++++++++++++++++++

[CONFIG]
appName=_Teradata2Hive_
version=2
logConsole=False
dataSourceName=TDEXPRESS141001
logDir=./tdpymodule/log
#workingDir=./tdpymodule/tempwork
table=dbc.columns
method=odbc
sesmode=Yes
system=tdexpress141001
username=lasradm
password=PassW0rd

 

 

Thanks

Highlighted
Teradata Employee

Re: Teradata Python Module - How to assign username/password to Python variables

Substitution using [Config] values is allowed in any SQL statement string as well as the connect method:

session.execute("select count(*) from ${table}")

 

Or you can access the values e.g. to set a variable:

mytbl = udaExec.config["table"]

AWT
Enthusiast

Re: Teradata Python Module - How to assign username/password to Python variables

Fred,

 

mytbl = udaExec.config["table"] is exactly what I am looking for.

 

Thanks