set_context | Teradata Python Package - set_context - Teradata VantageCloud Lake

Lake - Analyze Your Data with ClearScape Analytics™

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2026-02-20
dita:mapPath
tcl1683670667798.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
tcl1683670667798

The set_context function specifies a Vantage sqlalchemy engine as current context.

  • When overwriting an existing context associated with a Vantage connection, most of the operations on any teradataml DataFrames created before will not work.
  • Running the set_context() triggers garbage collection in teradataml. For more details of Garbage Collection,see Garbage Collection in teradataml.

Example

The following example creates two contexts using different host, then sets the context to the first one.

>>> from teradataml.context.context import *
>>> from teradataml.dataframe.dataframe import DataFrame
Create a connection:
>>> td_connection1 = create_context(host = "myhostname", username="myusername", password = "mypassword")
Overwrite the existing connection with new connection using 'create_context()':
>>> td_connection2 = create_context(host = "myhostname2", username="myusername2", password = "mypassword2")
302: UserWarning: [Teradata][teradataml](TDML_2002) Overwriting an existing context associated with Teradata connection. Most of the operations on any teradataml DataFrames created before this will not work.
  warnings.warn(Messages.get_message(MessageCodes.OVERWRITE_CONTEXT))
Get the engine currently associated with the context:
>>> get_context()
Engine(teradatasql://myusername2:***@myhostname2)
Overwrite the existing context, by passing a sqlalchemy engine object as input to 'set_context()', thereby creating a new context:
>>> set_context(tdsqlengine = td_connection1)
302: UserWarning: [Teradata][teradataml](TDML_2002) Overwriting an existing context associated with Teradata connection. Most of the operations on any teradataml DataFrames created before this will not work.
  warnings.warn(Messages.get_message(MessageCodes.OVERWRITE_CONTEXT))
>>> get_context()
Engine(teradatasql://myusername:***@myhostname)