pyrh.models.sessionmanager.SessionManager

class pyrh.models.sessionmanager.SessionManager(username, password, mfa='', challenge_type='sms', headers=None, proxies=None, **kwargs)

Manage connectivity with Robinhood API.

This class manages logging in and multi-factor authentication. Optionally, it can automatically authenticate for automation systems

Example

>>> sm = SessionManager(username="USERNAME", password="PASSWORD")
>>> sm.login()  # xdoctest: +SKIP
>>> sm.logout()  # xdoctest: +SKIP

Example

>>> sm = SessionManager(username="USERNAME", password="PASSWORD", mfa="16DIGITQRCODE")

If you want to bypass manual MFA authentication, you can supply your 16-digit QR code from Robinhood as a parameter as shown.

Parameters:
  • username (str) – The username to login to Robinhood

  • password (str) – The password to login to Robinhood

  • mfa (Optional[str]) – The 16 character QR code used to authenticate MFA automatically

  • challenge_type (Optional[str]) – Either sms or email (only if not using mfa)

  • headers (Optional[CaseInsensitiveDict]) – Any optional header dict modifications for the session

  • proxies (Optional[Dict[str, str]]) – Any optional proxy dict modification for the session

  • **kwargs (Any) – Any other passed parameters as converted to instance attributes

session

A requests session instance

expires_at

The time the oauth token will expire at, default is 1970-01-01 00:00:00

certs

The path to the desired certs to check against

device_token

A random guid representing the current device

access_token

An oauth2 token to connect to the Robinhood API

refresh_token

An oauth2 refresh token to refresh the access_token when required

__init__(username, password, mfa='', challenge_type='sms', headers=None, proxies=None, **kwargs)

Methods

__init__(username, password[, mfa, ...])

get(url[, params, headers, raise_errors, ...])

Run a wrapped session HTTP GET request.

login([force_refresh])

Login to the session.

logout()

Logout from the session.

post(url[, data, headers, raise_errors, ...])

Run a wrapped session HTTP POST request.

Attributes

authenticated

Check if the session is authenticated.

login_set

Check if login info is properly configured.

token_expired

Check if the issued auth token has expired.