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

Teradata® Package for Python Function Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00.00.11
Published
August 2026
ft:locale
en-US
ft:lastEdition
2026-08-13
dita:id
TeradataPython_FxRef_Enterprise_2000
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, database=None, **kwargs)
DESCRIPTION:
    Creates a connection to the Teradata Vantage using the teradatasql + teradatasqlalchemy DBAPI and dialect
    combination.
    Users can create a connection by passing the connection parameters using any one of the following methods:
        1. Pass all required parameters (host, username, password) directly to the function.
        2. Set the connection parameters in a configuration file (.cfg or .env) and
           pass the configuration file.
        3. Set the connection parameters in environment variables and create_context() reads from
           environment variables.
 
    Alternatively, users can pass a SQLAlchemy engine object to the `tdsqlengine` parameter to override the default DBAPI
    and dialect combination.
 
    Function also enables user to set the authentication token which is required to access services running
    on Teradata Vantage.
 
    Note:
        1. teradataml requires that the user has certain permissions on the user's default database or the initial
           default database specified using the database argument, or the temporary database when specified using
           temp_database_name. These permissions allow the user to:
            a. Create tables and views to save results of teradataml analytic functions.
            b. Create views in the background for results of DataFrame APIs such as assign(),
               filter(), etc., whenever the result for these APIs are accessed using a print().
            c. Create view in the background on the query passed to the DataFrame.from_query() API.
 
           It is expected that the user has the correct permissions to create these objects in the database that
           will be used.
           The access to the views created may also require issuing additional GRANT SELECT ... WITH GRANT OPTION
           permission depending on which database is used and which object the view being created is based on.
 
        2. The temp_database_name and database parameters play a crucial role in determining which database
           is used by default to lookup for tables/views while creating teradataml DataFrame using 'DataFrame()'
           and 'DataFrame.from_table()' and which database is used to create all internal temporary objects.
           +------------------------------------------------------+---------------------------------------------+
           |                     Scenario                         |            teradataml behaviour             |
           +------------------------------------------------------+---------------------------------------------+
           | Both temp_database_name and database are provided    | Internal temporary objects are created in   |
           |                                                      | temp_database_name, and database table/view |
           |                                                      | lookup is done from database.               |
           +------------------------------------------------------+---------------------------------------------+
           | database is provided but temp_database_name is not   | Database table/view lookup and internal     |
           |                                                      | temporary objects are created in database.  |
           +------------------------------------------------------+---------------------------------------------+
           | temp_database_name is provided but database is not   | Internal temporary objects are created in   |
           |                                                      | temp_database_name, database table/view     |
           |                                                      | lookup from the users default database.     |
           +------------------------------------------------------+---------------------------------------------+
           | Neither temp_database_name nor database are provided | Database table/view lookup and internal     |
           |                                                      | temporary objects are created in users      |
           |                                                      | default database.                           |
           +------------------------------------------------------+---------------------------------------------+
 
        3. The function prioritizes parameters in the following order:
            1. Explicitly passed arguments (host, username, password).
            2. Environment variables (TD_HOST, TD_USERNAME, TD_PASSWORD, etc.).
               Note:
                   * The environment variables should start with 'TD_' and all must be in upper case.
                     Example:
                            os.environ['TD_HOST'] = 'tdhost'
                            os.environ['TD_USERNAME'] = 'tduser'
                            os.environ['TD_PASSWORD'] = 'tdpassword'
            3. A configuration file if provided (such as a .env file).
 
        4. Points to note when user sets authentication token with create_context():
            * User must have a privilege to login with a NULL password to use set_auth_token.
              Refer to GRANT LOGON section in Teradata Documentation for more details.
            * When "auth_mech" is not specified, arguments are used in the following combination
              to derive authentication mechanism.
                * If "base_url" and "client_id" are specified then token generation is done through OAuth on VCL platform.
                * If "base_url", "pat_token", "pem_file" are specified then token generation is done using PAT.
                * If "base_url", "username" and "password" are specified authentication token can be generated
                  via two mechanisms viz. basic authentication or OAuth password grant. In such cases,
                  if "auth_mech" is not explicitly provided, then basic authentication is given the priority.
                * If "base_url" and "auth_token" are specified then readily available token is used.
                * If only "base_url" is specified then token generation is done through OAuth device flow and
                  client id will be extracted internally from "base_url" considering system is VCL based.
            * Refresh token works for 'OAUTH' and 'KEYCLOAK' authentication mechanisms which are variants
              of OAuth 2.0. authentication flows.
            * Use the argument "kid" only when key used during the pem file generation is different
              from pem file name. For example, if you use the key as 'key1' while generating pem file
              and the name of the pem file is `key1(1).pem`, then pass value 'key1' to the argument "kid".
            * Refer to below table to choose the right combination of arguments for different
              authentication mechanisms and flows.
              Legend: [...] = Optional,  DC = DEVICE_CODE,  PW = PASSWORD grant
              Notes:
                   * DC (DEVICE_CODE) opens browser for authentication.
                   * PW (PASSWORD) requires idp_username and idp_password for direct login.
              +-------------+------------+-------------+------------------------------------+
              | Infra       | IDP        | auth_mech   | Required Args and [Optional Args]  |
              +=============+============+=============+====================================+
              | ANY         | -          | JWT         | base_url, auth_token               |
              +=============+============+=============+====================================+
              | ANY         | -          | BASIC       | base_url, username, password       |
              +=============+============+=============+====================================+
              | VCL         | -          | PAT         | base_url, pat_token, pem_file      |
              |             |            |             | [username, kid, expiration_time,   |
              |             |            |             |  validate_jwt, valid_from]         |
              +=============+============+=============+====================================+
              | VCL         | VCL_IN_    | OAUTH (DC)  | base_url, client_id                |
              |             | HOUSE      |             | (username is required but can be   |
              |             |            |             |  auto-derived from connection)     |
              |             |            |             | [oauth_scope]                      |
              +-------------+------------+-------------+------------------------------------+
              |             | VCL_IN_    | OAUTH (DC)  | base_url (client_id auto-derived   |
              |             | HOUSE      | auto-derive | from base_url)                     |
              |             |            |             | [oauth_scope]                      |
              +=============+============+=============+=====================================+
              | On-Prem     | KEYCLOAK   | OAUTH (DC)  | base_url, client_id,               |
              |             |            |             | idp_type='KEYCLOAK'                |
              |             |            |             | [oidc_issuer_url, oauth_scope,     |
              |             |            |             |  keycloak_realm]                   |
              +-------------+------------+-------------+------------------------------------|
              |             | KEYCLOAK   | OAUTH (PW)  | base_url, client_id,               |
              |             |            |             | idp_type='KEYCLOAK',               |
              |             |            |             | idp_username, idp_password         |
              |             |            |             | [oidc_issuer_url, oauth_scope,     |
              |             |            |             |  keycloak_realm]                   |
              +-------------+------------+-------------+------------------------------------+
              |             | KEYCLOAK   | KEYCLOAK    | base_url, auth_url, password       |
              |             |            | (legacy PW) | [rest_client, username]            |
              |             |            |             | (idp_username and idp_password are |
              |             |            |             |  required and derived from username|
              |             |            |             |  and password)                     |
              |             |            |             | Note: Use OAUTH instead            |
              +=============+============+=============+====================================+
              | VCE         | PING       | OAUTH (DC)  | base_url, client_id,               |
              |             |            |             | idp_type='PING',                   |
              |             |            |             | [oidc_issuer_url, oauth_scope]     |
              +=============+============+=============+====================================+
              | Any         | OAuth 2.0  | OAUTH (DC)  | base_url, client_id,               |
              |             | IDP        |             | oidc_issuer_url                    |
              |             |            |             | [oauth_scope]                      |
              +-------------+------------+-------------+------------------------------------+
              | Any         | OAuth 2.0  | OAUTH (PW)  | base_url, client_id,               |
              |             | IDP        |             | oidc_issuer_url,                   |
              |             |            |             | idp_username, idp_password         |
              |             |            |             | [oauth_scope]                      |
              +-------------+------------+-------------+------------------------------------+
 
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
        Note:
            * Encrypted passwords can also be passed to this argument, using Stored Password Protection feature.
              Examples section below demonstrates passing encrypted password to 'create_context'.
              More details on Stored Password Protection and how to generate key and encrypted password file
              can be found at https://pypi.org/project/teradatasql/#StoredPasswordProtection
            * Special characters used in the password are encoded by default.
 
    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: As supported by the teradata driver.
        Notes:
            1. teradataml expects the client environments are already setup with appropriate
               security mechanisms and are in working conditions.
            2. User must have a valid ticket-granting ticket in order to use KRB5 (Kerberos) logon mechanism.
            3. User must use logdata parameter when using 'JWT' as the logon mechanism.
            4. Browser Authentication is supported for Windows and macOS.
            For more information please refer Teradata Vantage™ - Advanced SQL Engine
            Security Administration at https://www.info.teradata.com/
        Types: str
 
    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
 
    database:
        Optional Argument.
        Specifies the initial database to use after logon, instead of the user's default database.
        Types: str
 
    kwargs:
        Specifies optional keyword arguments accepted by create_context().
        Below are the supported keyword arguments:
 
        Connection parameters for Teradata SQL Driver:
            Specifies the keyword-value pairs of connection parameters that are passed to Teradata SQL Driver for
            Python. Please refer to https://github.com/Teradata/python-driver#ConnectionParameters to get information
            on connection parameters of the driver.
            Note:
                * When type of a connection parameter is integer or boolean (eg: log, lob_support etc,.), pass
                  integer or boolean value, instead of quoted integer or quoted boolean as suggested in the
                  documentation. Please check the examples for usage.
                * "sql_timeout" represents "request_timeout" connection parameter.
 
        config_file:
            Specifies the name of the configuration file to read the connection parameters.
            Notes:
                * If user does not specify full path of file, then file look up is done at current working directory.
                * The content of the file must be in '.env' format.
                * Use parameters of create_context() as key in the configuration file.
                  Example:
                      host=tdhost
                      username=tduser
                      password=tdpassword
                      temp_database_name=tdtemp_database_name
                      logmech=tdlogmech
                      logdata=tdlogdata
                      database=tddatabase
                * For more information please refer examples section.
            Default Value : td_properties.cfg
            Types: str
 
        base_url:
            Specifies the endpoint URL for a given environment on Teradata Vantage.
            Types: str
 
        client_id:
            Specifies the id of the application that requests the access token from
            VantageCloud Lake.
            Types: str
 
        pat_token:
            Specifies the PAT token generated from VantageCloud Lake Console.
            Types: str
 
        pem_file:
            Specifies the path to private key file which is generated from VantageCloud Lake Console.
            Types: str
 
        auth_token:
            Optional Argument.
            Specifies the authentication token required to access services running
            on Teradata Vantage.
            Note:
                * Use this option only if user has got JWT token and wants to set
                  the same instead of generating it again.
            Types: str
 
        expiration_time:
            Optional Argument.
            Specifies the expiration time of the token in seconds. After expiry time, JWT
            token expires and UserEnv methods does not work, user should regenerate the token.
            Note:
                * This option is used only for PAT and not for OAuth.
            Default Value: 31536000
            Types: int
 
        kid:
            Optional Argument.
            Specifies the name of the key which is used while generating "pem_file".
            Note:
                * Use the argument "kid" only when key used during the pem file generation is different
                  from pem file name. For example, if you use the key as 'key1' while generating pem file
                  and the name of the pem file is `key1(1).pem`, then pass value 'key1' to the argument "kid".
            Types: str
 
        auth_url:
            Optional Argument.
            Specifies the token endpoint URL for a keycloak server.
            Types: str
 
        rest_client:
            Optional Argument.
            Specifies the client-id registered at keycloak IDP for given teradata site.
            Notes:
                * teradataml recommends to use "client_id" argument along
                  with "auth_mech" as 'OAUTH' and "idp_type" as 'KEYCLOAK'
                  for keycloak IDP paired with "oauth_grant_type".
                * This argument is kept for backward compatibility,
                  when "auth_mech" is 'KEYCLOAK'.
            Permitted values: "VECTORSTORE"
            Default value: "VECTORSTORE"
            Types: str
 
        auth_mech:
            Optional Argument.
            Specifies the mechanism to be used for generating authentication token.
            Notes:
                * User must use this argument if Basic authentication is to be used.
                * teradataml recommends to explicitly provide this argument to avoid ambiguity
                  in authentication mechanism derivation.
                * When "auth_mech" is provided, other arguments are used in the following
                  combination as per value of "auth_mech":
                  * OAUTH: Token generation is done through OAuth (device flow or password grant
                           based on "oauth_grant_type") using client id which can be specified by
                           user in "client_id" argument or can be derived internally from "base_url"
                           in case of VCL systems.
                   * PAT: Token generation is done using "pat_token" and "pem_file".
                   * BASIC: Authentication is done via Basic authentication mechanism
                            using user credentials passed in "username" and "password" arguments.
                   * JWT: Readily available token in "auth_token" argument is used.
                   * KEYCLOAK: Token generation is done via keycloak IDP. It's a variant of OAuth only.
                               This is kept for backward compatibility. teradataml recommends to use
                               "auth_mech" as 'OAUTH' with "idp_type" as 'KEYCLOAK' instead of using
                               'KEYCLOAK' as value for "auth_mech" argument when keycloak IDP is used.
            Permitted Values: "OAUTH", "PAT", "BASIC", "JWT", "KEYCLOAK".
            Types: str
 
        validate_jwt:
            Optional Argument.
            Specifies whether to validate generated JWT token or not.
            Note:
                * Applicable only when "auth_mech" is 'PAT'.
            Default value: True
            Types: boolean
 
        valid_from:
            Optional Argument.
            Specifies epoch seconds representing time from which JWT token will be valid.
            Note:
                * Applicable only when "auth_mech" is 'PAT'.
            Default value: 0
            Types: int
 
        oauth_grant_type:
            Optional Argument.
            Specifies the OAuth 2.0 grant type to use for authentication.
            Notes:
                * Determines the OAuth flow to be used.
                * If not specified, defaults to 'device_code' flow for OAuth.
                * Refresh tokens are automatically handled within 'device_code' and 'password' flows.
            Permitted Values: "PASSWORD", "DEVICE_CODE".
            Default Value: "DEVICE_CODE"
            Types: str
 
        idp_type:
            Required when "auth_mech" is 'OAUTH' and IDP is other than VCL internal provider.
            Specifies the Identity Provider (IDP) type for OAuth flows.
            Notes:
                * teradataml recommends explicitly providing this argument to avoid ambiguity in IDP derivation.
                * Determines which IDP configuration to use.
                * Different IDPs may have different endpoint structures.
            Permitted Values: "KEYCLOAK", "PING", "VCL_IN_HOUSE".
            Default Value: "VCL_IN_HOUSE"
            Types: str
 
        oidc_issuer_url:
            Optional Argument.
            Specifies the base URL of the Identity Provider which is further appended
            with ".well-known/openid-configuration" for OIDC endpoint discovery in OAuth
            flows.
            e.g.
                1. If the IDP is keycloak and its base URL is "https://aiop-abcd.td.teradata.com", then
                   the OIDC issuer URL will be "https://aiop-abcd.td.teradata.com/sso/realms/[realm_name]",
                   where IDP is hosted.
                2. If the IDP is Ping and its base URL is "https://tdicam1111dv11.teradata.com/", then
                   the OIDC issuer URL will be "https://tdicam1111dv11.teradata.com".
                3. If the IDP is VCL in-house and the base URL is "https://vectorstoreawssite.teradata.com", then
                   the OIDC issuer URL will be "https://vcl-idp.td.com/auth".
            Notes:
                * If not specified, it will be derived from "base_url" and "idp_type".
            Types: str
 
        idp_username:
            Optional Argument.
            Specifies the IDP username for OAuth password grant flow.
            Notes:
                * If not specified, defaults to the value of "username" parameter.
                * Use this when IDP username differs from database username.
            Types: str
 
        idp_password:
            Optional Argument.
            Specifies the IDP password for OAuth password grant flow.
            Notes:
                * If not specified, defaults to the value of "password" parameter.
                * Use this when IDP password differs from database password.
            Types: str
 
        keycloak_realm:
            Optional Argument.
            Specifies the Keycloak realm name when using Keycloak IDP.
            Notes:
                * Required when "idp_type" is 'KEYCLOAK' and realm is non-default.
                * Used to construct OIDC issuer URL when "oidc_issuer_url" is not provided.
            Default Value: "teradata"
            Types: str
 
        oauth_scope:
            Optional Argument.
            Specifies the OAuth 2.0 scope(s) to request during authentication.
            Scopes define the level of access and permissions granted by the access token.
            Multiple scopes should be space-separated (e.g., 'openid profile email').
            Notes:
                * Only applicable when using OAuth or Keycloak authentication mechanisms.
                * The 'openid' scope is required for OpenID Connect flows.
                * Different Identity Providers may support different scopes.
                * Follows OAuth 2.0 RFC 6749 specification for scope format.
            Default Value: "openid"
            Types: str
 
RETURNS:
    A Teradata sqlalchemy engine object.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    >>> from teradataml.context.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', logmech = 'KRB5')
 
    # Example 7: Creating context for Vantage with logmech as 'JWT'
    >>> td_context = create_context(host = 'tdhost', logmech = 'JWT', logdata = 'token=eyJpc...h8dA')
 
    # Example 8: Create context using encrypted password and key passed to 'password' parameter.
    #            The password should be specified in the format mentioned below:
    #            ENCRYPTED_PASSWORD(file:<PasswordEncryptionKeyFileName>, file:<EncryptedPasswordFileName>)
    #            The PasswordEncryptionKeyFileName specifies the name of a file that contains the password encryption key
    #            and associated information.
    #            The EncryptedPasswordFileName specifies the name of a file that contains the encrypted password and
    #            associated information.
    #            Each filename must be preceded by the 'file:' prefix. The PasswordEncryptionKeyFileName must be separated
    #            from the EncryptedPasswordFileName by a single comma.
    >>> encrypted_password = "ENCRYPTED_PASSWORD(file:PassKey.properties, file:EncPass.properties)"
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = encrypted_password)
 
    # Example 9: Create context using encrypted password in LDAP logon mechanism.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = encrypted_password,
    ...                             logmech = 'LDAP')
 
   # Example 10: Create context using hostname, username, password and database parameters, and connect to a
   # different initial database by setting the database parameter.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword', database =
    ...                            'database_name')
 
    # Example 11: Create context using already created sqlalchemy engine, and connect to a different initial
    # database by setting the database parameter.
    >>> from sqlalchemy import create_engine
    >>> sqlalchemy_engine = create_engine('teradatasql://'+ tduser +':' + tdpassword + '@'+tdhost +
    ...                                   '/?DATABASE=database_name')
    >>> td_context = create_context(tdsqlengine = sqlalchemy_engine)
 
    # Example 12: Create context for Vantage with logmech as 'LDAP', and connect to a different initial
    # database by setting the database parameter.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword', logmech = 'LDAP',
    ...                             database = 'database_name')
 
    # Example 13: Create context using 'tera' mode with log value set to 8 and lob_support disabled.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword', tmode = 'tera',
    ...                             log = 8, lob_support = False)
 
    # Example 14: Create context from config file with name 'td_properties.cfg'
    #             available under current working directory.
    #             td_properties.cfg content:
    #                 host=tdhost
    #                 username=tduser
    #                 password=tdpassword
    #                 temp_database_name=tdtemp_database_name
    #                 logmech=tdlogmech
    #                 logdata=tdlogdata
    #                 database=tddatabase
    >>> td_context = create_context()
 
    # Example 15: Create context using the file specified in user's home directory
    #             with name user_td_properties.cfg.
    #             user_td_properties.cfg content:
    #                 host=tdhost
    #                 username=tduser
    #                 password=tdpassword
    #                 temp_database_name=tdtemp_database_name
    #                 logmech=tdlogmech
    #                 logdata=tdlogdata
    #                 database=tddatabase
    >>> td_context = create_context(config_file = "user_td_properties.cfg")
 
    # Example 16: Create context using environment variables.
    #             Set these using os.environ and then run the example:
    #                  os.environ['TD_HOST'] = 'tdhost'
    #                  os.environ['TD_USERNAME'] = 'tduser'
    #                  os.environ['TD_PASSWORD'] = 'tdpassword'
    #                  os.environ['TD_TEMP_DATABASE_NAME'] = 'tdtemp_database_name'
    #                  os.environ['TD_LOGMECH'] = 'tdlogmech'
    #                  os.environ['TD_LOGDATA'] = 'tdlogdata'
    #                  os.environ['TD_DATABASE'] = 'tddatabase'
    >>> td_context = create_context()
 
    # Example 17: Create a context by providing username and password. Along with it,
    #             set authentication token by providing the pem file and pat token.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword',
    ...                             base_url = 'base_url', pat_token = 'pat_token', pem_file = 'pem_file')
 
    # Example 18: Create a context by providing username and password. Along with it,
    #             generate authentication token by providing the client id.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword',
    ...                             base_url = 'base_url', client_id = 'client_id')
 
    # Example 19: Create context and set authentication token by providing all the details in a config file.
    #             td_properties.cfg content:
    #                 host=tdhost
    #                 username=tduser
    #                 password=tdpassword
    #                 base_url=base_url
    #                 pat_token=pat_token
    #                 pem_file=pem_file
    >>> td_context = create_context()
 
    # Example 20: Create context and set authentication token by providing all the details in environment variables.
    #             Set these using os.environ and then run the example:
    #                  os.environ['TD_HOST'] = 'tdhost'
    #                  os.environ['TD_USERNAME'] = 'tduser'
    #                  os.environ['TD_PASSWORD'] = 'tdpassword'
    #                  os.environ['TD_BASE_URL'] = 'base_url'
    #                  os.environ['TD_PAT_TOKEN'] = 'pat_token'
    #                  os.environ['TD_PEM_FILE'] = 'pem_file'
    >>> td_context = create_context()
 
    # Example 21: Create context with sql_timeout set to 3.
    >>> td_context = create_context(host = 'tdhost', username = 'tduser', password = 'tdpassword', sql_timeout = 3)
 
    # Example 22: Create context and set authentication token via Basic authentication mechanism
    #             using username and password.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                auth_mech="BASIC")
 
    # Example 23: Create context and set authentication token by providing auth_mech argument.
    >>> import getpass
    >>> create_context(host="vcl_host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                auth_mech="OAuth")
 
    # Example 24: Create context and set authentication token by providing auth_url and
    #             rest_client arguments.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                auth_url=getpass.getpass("auth_url : "),
    ...                rest_client=getpass.getpass("rest_client : "))
 
    # Example 25: Create context and set the authentication token on system with KEYCLOAK IDP via
    #             OAuth password grant flow. Specify "base_url", "client_id", "auth_mech"
    #             as 'OAUTH', "idp_type" as 'KEYCLOAK', "oauth_grant_type" as 'PASSWORD',
    #             "idp_username" and "idp_password".
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                idp_type="KEYCLOAK",
    ...                oauth_grant_type="PASSWORD",
    ...                idp_username=getpass.getpass("idp_username : "),
    ...                idp_password=getpass.getpass("idp_password : "),
    ...                keycloak_realm="teradata")
 
    # Example 26: Create context and set the authentication token on a system with KEYCLOAK IDP via
    #             OAuth device code flow. Specify "base_url", "client_id", "auth_mech" as
    #             'OAUTH', "idp_type" as 'KEYCLOAK' and "oauth_grant_type" as 'DEVICE_CODE'.
    #             This will open a browser for authentication.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                idp_type="KEYCLOAK",
    ...                oauth_grant_type="DEVICE_CODE",
    ...                keycloak_realm="teradata")
 
    # Example 27: Create context and set the authentication token on a system with PING IDP via
    #             OAuth device code flow. Specify "base_url", "client_id", "auth_mech"
    #             as 'OAUTH', "idp_type" as 'PING' and "oauth_grant_type" as 'DEVICE_CODE'.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                idp_type="PING",
    ...                oauth_grant_type="DEVICE_CODE")
 
    # Example 28: Create context and set the authentication token via OAuth by explicitly
    #             specifying "oidc_issuer_url". This is useful when user
    #             wants to directly provide the OIDC issuer URL instead of
    #             deriving it from "idp_type". Here, OAuth device code flow
    #             is used as an example.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                oidc_issuer_url=getpass.getpass("oidc_issuer_url : "),
    ...                oauth_grant_type="DEVICE_CODE")
 
    # Example 29: Create context and set the authentication token via OAuth by explicitly
    #             specifying "oidc_issuer_url". This is useful when user
    #             wants to directly provide the OIDC issuer URL instead of
    #             deriving it from "idp_type". Here, OAuth password grant
    #             flow is used as an example.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                oidc_issuer_url="https://idp.example.com/sso/realms/teradata",
    ...                oauth_grant_type="PASSWORD",
    ...                idp_username=getpass.getpass("idp_username : "),
    ...                idp_password=getpass.getpass("idp_password : "))
 
    # Example 30: Create context and set the authentication token via OAuth with custom scope.
    #             Request additional permissions using "oauth_scope" parameter.
    >>> import getpass
    >>> create_context(host="host",
    ...                username=getpass.getpass("username : "),
    ...                password=getpass.getpass("password : "),
    ...                base_url=getpass.getpass("base_url : "),
    ...                client_id=getpass.getpass("client_id : "),
    ...                auth_mech="OAUTH",
    ...                idp_type="KEYCLOAK",
    ...                oauth_grant_type="PASSWORD",
    ...                idp_username=getpass.getpass("idp_username : "),
    ...                idp_password=getpass.getpass("idp_password : "),
    ...                oauth_scope="openid")