Skip to content

tdfs4ds.session

tdfs4ds.session

One call to start a notebook on a feature store (0.3.5.17).

On Teradata AI Studio every notebook used to begin with the same block::

%gen_token
os.environ["TDFS4DS_VECTOR_STORE_AUTH_AUTH_TOKEN"] = user_token
os.environ["TDFS4DS_MCP_SERVER_HEADERS"] = '{"Authorization": "Bearer %s"}' % user_token
tdfs4ds.load_config(dotenv_path="../.env")
tdml.create_context(host=..., logmech="JWT", logdata="token=" + user_token)
tdfs4ds.connect(database=...)

because the .env written by generate_ai_studio_env(auth='jwt') holds a token that expires about two hours after it was minted. :func:open_session does the same from the pieces the package already has: it loads the .env, takes a current token (the one given, else the platform's own, the way %gen_token gets it) and puts it wherever the file uses a token (session_token.apply_token), opens the teradataml context from the TDFS4DS_TD_* settings (reconnect_teradata) and connects to the store.

With a password .env nothing token-related happens: it is load_config + a password logon + connect. tdfs4ds still reads no unprefixed variable: the platform module does.

find_env_file

find_env_file(start=None)

The nearest .env: the current folder (or start), then each parent up to the root, then ~/.tdfs4ds/.env (what load_dotenv() with find_dotenv would pick, plus the tdfs4ds home file). None when there is none.

open_session

open_session(env_file=None, *, database=None, token=None, connect=True, refresh=True)

Load the .env, log on, and connect to the feature store. Returns a short report.

Parameters

env_file : str, optional The .env to load. None (default) = the nearest one: the current folder, then each parent folder, then ~/.tdfs4ds/.env (:func:find_env_file); the file used is logged and returned in the report. False = load none (keep the session's settings). database : str, optional The store to connect to; default TDFS4DS_TD_DATABASE, else tdfs4ds.SCHEMA. token : str, optional A database token (%gen_token's user_token). Default: the platform's current token when the .env logs on with a token (AI Studio), else nothing. connect : bool False stops after the logon (for setup() on a new store). refresh : bool Renew the token in the background (every 15 minutes) when the platform provides one, so a long session keeps working; the open database session itself is not affected by the token's expiry.