Module pyfx.internal.session

Handling a session with the Pricefx platform.

A session is used to manager persistent authentication with the platform.

Functions

def pfx_session(auth: PfxAuthMethod, session: Optional[requests.sessions.Session] = None) ‑> PfxSession

Default PfxSession constructor.

Args

auth
the authentication method to be used
def pfx_session_from_token(token: str, session: Optional[requests.sessions.Session] = None) ‑> PfxSession

Default PfxSession constructor using a static token.

Args

token
the token to use
def pfx_session_from_token_file(token_file_path: str, session: Optional[requests.sessions.Session] = None) ‑> PfxSession

Default PfxSession constructor using a token file as auth method.

Args

token_file_path
the token file path
def pfx_session_from_user_pass(instance: str, partition: str, user: str, passwd_provider: Callable[[], str], protocol: str = 'https') ‑> PfxSession

Default PfxSession constructor using a user password authentication method.

Args

instance
the base address of the instance
partition
the partition name
user
the user account
passwd_provider
a way to retrieve the user password

Classes

class PasswordProviderCommand (command: str)

A platform provider getting the password from an external command.

Get the password by running a command and using its output.

class PasswordProviderLinuxSecretStore (instance: str, partition: str, account: str)

A platform provider baked by Linux secretstore service.

Get the password from Linux secret storage.

Args

instance
the instance to connect to
partition
the partition to connect to
account
the "account" key for the password
class PasswordProviderPrompt (prompt: str)

A platform provider prompting user for password.

Get the password by prompting on stdin.

Args

prompt
the message to display when prompting for the password
class PfxAuthMethod

Formal interface of a PfxAuthMethod.

Ancestors

  • abc.ABC

Subclasses

Methods

def after_response(self, session: requests.sessions.Session, response: requests.models.Response) ‑> None

Method called after each response.

The AuthMethod can then alter the session to register credentials properly

:param session: the session object :param response: the response obtained from the request

def before_request(self, session: requests.sessions.Session) ‑> None

Method called before each request.

The AuthMethod can then alter the session to register credentials properly

:param session: the session object

class PfxAuthStaticToken (token: str)

A PfxAuthHandler using a static token.

Ancestors

Methods

def after_response(self, session: requests.sessions.Session, response: requests.models.Response) ‑> None
def before_request(self, session: requests.sessions.Session) ‑> None
class PfxAuthTokenFile (token_file_path: str)

A PfxAuthHandler that uses a token stored in a file.

The token file is updated by re-reading the file before each request.

Ancestors

Methods

def after_response(self, session: requests.sessions.Session, response: requests.models.Response) ‑> None
def before_request(self, session: requests.sessions.Session) ‑> None
class PfxAuthUserPass (instance: str, partition: str, user: str, passwd_provider: Callable[[], str], protocol: str = 'https')

A PfxSession that authenticate using user/pass on first connexion.

After authenticating the user, the session switch to the provided JWT token.

Create a new session by authenticating with a user/pass.

Password cannot be provided directly, it must be given by the passwd_provider.

Args

instance
the base address of the instance
partition
the partition name
user
the user account
passwd_provider
a way to retrieve the user password

Ancestors

Methods

def after_response(self, session: requests.sessions.Session, response: requests.models.Response) ‑> None
def before_request(self, session: requests.sessions.Session) ‑> None
class PfxSession

Formal interface of a PfxSession.

Ancestors

  • abc.ABC

Subclasses

Methods

def get(self, url: str, **kwargs: Any) ‑> requests.models.Response

See requests.Session.get.

def post(self, url: str, **kwargs: Any) ‑> requests.models.Response

See requests.Session.post.

class RetryPfxSession (wrapped: PfxSession, retry_predicate: Optional[Callable[[requests.exceptions.RequestException], bool]] = None, retry_delays: Optional[List[int]] = None)

Session that retries requests a given number of time before failing.

Args

wrapped
the used PfxSession to execute the requests
retry_predicate
a predicate which define a request should be retried when the given RequestException happens
retry_delays
the sequence of delays in seconds to apply between each trial. The first value is the first delay to wait before the second retry. The next value will be waited after a second failure and so on. Consequently, the number of retry done before aborting is equal to the size of this list (excluding the initial request).

Ancestors

Inherited members

class SimplePfxSession (auth: PfxAuthMethod, session: Optional[requests.sessions.Session] = None)

Specialized Session to handle Pfx specificities.

By default it raises an error for client error or server error responses.

Constructor of SimplePfxSession.

:param auth: handler used to setup the session for authentication purpose. :param session: the requests Session to use, if not set a new one will be created.

Ancestors

Inherited members