atoti.Session.connect#

classmethod Session.connect(url, *, authentication=None, certificate_authority=None)#

Connect to an existing session.

Here is a breakdown of the Live Extension capabilities available on the returned session:

Note

Data and data model changes made from a connected session are not persisted on the target session. They will be lost if the target session is restarted.

Parameters:
  • url (str) – The base URL of the target session. The endpoint f"{url}/versions/rest" is expected to exist.

  • authentication (Authenticate | ClientCertificate | None) – The method used to authenticate against the target session.

  • certificate_authority (Path | None) – Path to the custom certificate authority file to use to verify the HTTPS connection. Required when the target session has been configured with an SSL certificate that is not signed by some trusted public certificate authority.

Return type:

Session

Example

>>> session_config = tt.SessionConfig(security=tt.SecurityConfig())
>>> secure_session = tt.Session.start(session_config)
>>> _ = secure_session.create_table("Example", types={"Id": "String"})
>>> secure_session.security.basic_authentication.credentials.update(
...     {"user": "passwd", "admin": "passwd"}
... )
>>> secure_session.security.individual_roles.update(
...     {"user": {"ROLE_USER"}, "admin": {"ROLE_USER", "ROLE_ADMIN"}}
... )
>>> admin_session = tt.Session.connect(
...     secure_session.url,
...     authentication=tt.BasicAuthentication("admin", "passwd"),
... )
>>> table = admin_session.tables["Example"]
>>> table += ("foo",)
>>> table.head()
    Id
0  foo

Live Extension requires the connected session to be granted ROLE_ADMIN:

>>> user_session = tt.Session.connect(
...     secure_session.url,
...     authentication=tt.BasicAuthentication("user", "passwd"),
... )
>>> list(user_session.tables)  
Traceback (most recent call last):
    ...
atoti._live_extension_unavailable_error.LiveExtensionUnavailableError: Live extension is not available ...

Live Extension requires the target session to be secure:

>>> unsecure_session = tt.Session.start()
>>> _ = unsecure_session.create_table("Example", types={"Id": "String"})
>>> connected_session = tt.Session.connect(unsecure_session.url)
>>> list(connected_session.tables)  
Traceback (most recent call last):
    ...
atoti._live_extension_unavailable_error.LiveExtensionUnavailableError: Live extension is not available ...

See also

start()