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 usespydelfini.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 ofAuthenticatedClient
, then use this method to load the token file in a new process.
- with_password(username, password)[source]¶
Log in using a username and password.
- Parameters:
- Raises:
LoginError – if the login could not be completed
- Returns:
a new Client that has been successfully logged in
- Return type:
- 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 thesession_id
attribute of the response. To activate the session, the user should visit/login/activate/<activation_code>
where<activation_code>
is the value ofactivation_code
in the response.- Parameters:
- Raises:
LoginError – if the session could not be verified
- Returns:
a new Client that has been successfully logged in
- Return type: