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
¶
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, sign_in=True, databases_readonly=None)
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 you work in (read-write); default TDFS4DS_TD_DATABASE, else
tdfs4ds.SCHEMA. When none of them gives a store, nothing is connected and a warning
says so: pass database=.
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.
sign_in : bool
When the platform gives no token and the one in the .env has expired, run the
platform's device-flow sign-in (%gen_token_using_device_flow): a link is shown, you
sign in, and the session continues with the new token. Only in a notebook or terminal
someone is watching; False never asks.
databases_readonly : list of str (or dict descriptors), or str, optional
Other feature stores to read, read-only, next to the one you work in (read federation;
writes still go to database only). A single name is a one-item list. None (default)
passes nothing to connect, so TDFS4DS_SCHEMA_READONLY of the .env still
applies; a list replaces that set; [] detaches every read-only store. The attached
stores are returned in report['read_only'].