Auth#

class yfinance.Auth(session=None)#

Attributes

user

Get the logged-in user’s details.

Returns:

{'guid': ...} if logged in, or None if not.

Return type:

dict | None

Methods

__init__(session=None)
check_login() bool

Check whether the user is logged in to Yahoo Finance.

Note: False during a transient error (e.g. Yahoo briefly unreachable) means “could not confirm” rather than “logged out” — the stored login cookies are kept and remain protected in that case.

set_login_cookies(cookie_t: str, cookie_y: str) bool

Set the login cookies and verify they are valid.

How to Obtain the Cookies:
  1. Open your browser (e.g., Chrome, Firefox).

  2. Log in to Yahoo Finance (https://finance.yahoo.com).

  3. Open the browser’s Developer Tools: Press F12 or Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (Mac).

  4. Go to the “Application” tab (Chrome) or “Storage” tab (Firefox).

  5. In the “Cookies” section, select https://finance.yahoo.com.

  6. Look for the cookies named T and Y.

  7. Copy the values of these cookies and pass them to this function.

Parameters:
  • cookie_t (str) – The value for the ‘T’ cookie.

  • cookie_y (str) – The value for the ‘Y’ cookie.

Returns:

True if the cookies are valid (the account is logged in), False otherwise (also emitted as a warning). The cookies are stored regardless. False can also mean Yahoo was transiently unreachable, so it is not treated as a hard error.

Return type:

bool

subscription_tier() str | None

Return the Yahoo Finance subscription tier of the logged-in account.

Read directly from the account’s tier id in subscriptionView (the value the account is billed against) rather than inferring it from the granted feature set, which Yahoo reshuffles between tiers.

Returns:

'gold', 'silver' or 'bronze' for a named subscription ('premium' for a subscribed tier with no marketed name), 'free' when logged in without a subscription, or None when not logged in.

Return type:

str | None

check_login() bool#

Check whether the user is logged in to Yahoo Finance.

Note: False during a transient error (e.g. Yahoo briefly unreachable) means “could not confirm” rather than “logged out” — the stored login cookies are kept and remain protected in that case.

set_login_cookies(cookie_t: str, cookie_y: str) bool#

Set the login cookies and verify they are valid.

How to Obtain the Cookies:
  1. Open your browser (e.g., Chrome, Firefox).

  2. Log in to Yahoo Finance (https://finance.yahoo.com).

  3. Open the browser’s Developer Tools: Press F12 or Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (Mac).

  4. Go to the “Application” tab (Chrome) or “Storage” tab (Firefox).

  5. In the “Cookies” section, select https://finance.yahoo.com.

  6. Look for the cookies named T and Y.

  7. Copy the values of these cookies and pass them to this function.

Parameters:
  • cookie_t (str) – The value for the ‘T’ cookie.

  • cookie_y (str) – The value for the ‘Y’ cookie.

Returns:

True if the cookies are valid (the account is logged in), False otherwise (also emitted as a warning). The cookies are stored regardless. False can also mean Yahoo was transiently unreachable, so it is not treated as a hard error.

Return type:

bool

subscription_tier() str | None#

Return the Yahoo Finance subscription tier of the logged-in account.

Read directly from the account’s tier id in subscriptionView (the value the account is billed against) rather than inferring it from the granted feature set, which Yahoo reshuffles between tiers.

Returns:

'gold', 'silver' or 'bronze' for a named subscription ('premium' for a subscribed tier with no marketed name), 'free' when logged in without a subscription, or None when not logged in.

Return type:

str | None