Teradata Python Package Function Reference - create_context - Teradata Python Package - Look here for syntax, methods and examples for the functions included in the Teradata Python Package.

Teradata® Python Package Function Reference

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-07-17
lifecycle
previous
Product Category
Teradata Vantage
teradataml.context.context.create_context = create_context(host=None, username=None, password=None, tdsqlengine=None, temp_database_name=None, logmech=None, logdata=None)
DESCRIPTION:
    Creates a connection to the Teradata Vantage using the teradatasql + teradatasqlalchemy DBAPI and dialect combination.
    Users can pass all required parameters (host, username, password) for establishing a connection to Vantage,
    or pass a sqlalchemy engine to the tdsqlengine parameter to override the default DBAPI and dialect combination.
 
PARAMETERS:
    host:
        Optional Argument.
        Specifies the fully qualified domain name or IP address of the Teradata System.
        Types: str
    
    username:
        Optional Argument.
        Specifies the username for logging onto the Teradata Vantage.
        Types: str
    
    password:
        Optional Argument.
        Specifies the password required for the username.
        Types: str
        
    tdsqlengine:
        Optional Argument.
        Specifies Teradata Vantage sqlalchemy engine object that should be used to establish a Teradata Vantage connection.
        Types: str
        
    temp_database_name:
        Optional Argument.
        Specifies the temporary database name where temporary tables, views will be created.
        Types: str
        
    logmech:
        Optional Argument.
        Specifies the type of logon mechanism to establish a connection to Teradata Vantage. 
        Permitted Values: 'TD2', 'TDNEGO', 'LDAP', 'KRB5' & 'JWT'.
            TD2: 
                The Teradata 2 (TD2) mechanism provides authentication using a 
                Vantage username and password. This is the default logon mechanism
                using which the connection is established to Vantage.
            TDNEGO:
                A security mechanism that automatically determines the actual 
                mechanism required, based on policy, without user's involvement.
                The actual mechanism is determined by the TDGSS server configuration
                and by the security policy's mechanism restrictions.
            LDAP:
                A directory-based user logon to Vantage with a directory username
                and password and is authenticated by the directory.
            KRB5 (Kerberos):
                A directory-based user logon to Vantage with a domain username
                and password and is authenticated by Kerberos (KRB5 mechanism).
            JWT: 
                The JSON Web Token (JWT) authentication mechanism enables single 
                sign-on (SSO) to the Vantage after the user successfully authenticates
                to Teradata UDA User Service.
        Types: str
 
        Note:
            teradataml expects the client environments are already setup with appropriate
            security mechanisms and are in working conditions.
            For more information please refer Teradata Vantage™ NewSQL Engine 
            Security Administration Guide at https://www.info.teradata.com/
    
    logdata:
        Optional Argument.
        Specifies parameters to the LOGMECH command beyond those needed by the logon mechanism, such as 
        user ID, password and tokens (in case of JWT) to successfully authenticate the user.
        Types: str
 
RETURNS:
    A Teradata sqlalchemy engine object.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    >>> from teradataml.context import *
 
    >>> # Example 1: Create context using hostname, username and password
    >>> td_context = create_context(host = 'tdhost', username='tduser', password = 'tdpassword')
 
    >>> # Example 2: Create context using already created sqlalchemy engine
    >>> from sqlalchemy import create_engine
    >>> sqlalchemy_engine  = create_engine('teradatasql://'+ tduser +':' + tdpassword + '@'+tdhost)
    >>> td_context = create_context(tdsqlengine = sqlalchemy_engine)
 
    >>> # Example 3: Creating context for Vantage with default logmech 'TD2'
    >>> td_context = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', logmech='TD2')
 
    >>> # Example 4: Creating context for Vantage with logmech as 'TDNEGO'
    >>> td_context = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', logmech='TDNEGO')
 
    >>> # Example 5: Creating context for Vantage with logmech as 'LDAP'
    >>> td_context = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', logmech='LDAP')
 
    >>> # Example 6: Creating context for Vantage with logmech as 'KRB5'
    >>> td_context = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', logmech='KRB5')
 
    >>> # Example 7: Creating context for Vantage with logmech as 'JWT'
    >>> td_context = create_context(host = 'tdhost', logmech='JWT', logdata='token=eyJpc...h8dA')
 
    Note: User must use logdata parameter when using 'JWT' as logging mechanism.