Login

class pydelfini.delfini_core.login.Login(client)[source]

Bases: object

Mid-level login routines.

Users wanting to log in to a Delfini instance will typically use pydelfini.login(). The functions in this class are most useful if you are working on a specialized Delfini client that predominantly uses pydelfini.delfini_core, or if you are working with workflows that do not support interactive login.

Typical usage:

from pydelfini.delfini_core import Client, Login

# get an unauthenticated client
client = Client(base_url='https://delfini.bioteam.net/api/v1')

# log in with password
auth_client = Login(client).with_password(username, password)

# or with session ID
auth_client = Login(client).with_session_id(session_id)
Parameters:

client (Client)

from_token_file(filename)[source]

Log in using a session ID saved in a token file.

This is typically used to make CLI interactions smoother, since the session has a short lifespan. However, if you need to share a session among multiple processes or otherwise want to persist a session between invocations, you can use to_token_file() to save the session token from an instance of AuthenticatedClient, then use this method to load the token file in a new process.

Parameters:

filename (str | bytes | PathLike[str] | PathLike[bytes]) – path to token file

Raises:

LoginError – if the session could not be verified

Returns:

a new Client that has been successfully logged in

Return type:

AuthenticatedClient

with_password(username, password)[source]

Log in using a username and password.

Parameters:
  • username (str) – the user’s username

  • password (str) – the user’s password

Raises:

LoginError – if the login could not be completed

Returns:

a new Client that has been successfully logged in

Return type:

AuthenticatedClient

with_session_id(session_id, wait=False)[source]

Log in using an existing session ID.

You can get a session ID token by calling api.auth.auth_new_session and using the session_id attribute of the response. To activate the session, the user should visit /login/activate/<activation_code> where <activation_code> is the value of activation_code in the response.

Parameters:
  • session_id (str) – an active session ID

  • wait (bool) – if True, wait for the session to be activated

Raises:

LoginError – if the session could not be verified

Returns:

a new Client that has been successfully logged in

Return type:

AuthenticatedClient