Auth#
- class yfinance.Auth(session=None)#
Attributes
- user
Get the logged-in user’s details.
- Returns:
{'guid': ...}if logged in, orNoneif not.- Return type:
dict | None
Methods
- __init__(session=None)
- check_login() bool
Check whether the user is logged in to Yahoo Finance.
Note:
Falseduring 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:
Open your browser (e.g., Chrome, Firefox).
Log in to Yahoo Finance (https://finance.yahoo.com).
Open the browser’s Developer Tools: Press F12 or Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (Mac).
Go to the “Application” tab (Chrome) or “Storage” tab (Firefox).
In the “Cookies” section, select https://finance.yahoo.com.
Look for the cookies named T and Y.
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:
Trueif the cookies are valid (the account is logged in),Falseotherwise (also emitted as a warning). The cookies are stored regardless.Falsecan 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, orNonewhen not logged in.- Return type:
str | None
- check_login() bool#
Check whether the user is logged in to Yahoo Finance.
Note:
Falseduring 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:
Open your browser (e.g., Chrome, Firefox).
Log in to Yahoo Finance (https://finance.yahoo.com).
Open the browser’s Developer Tools: Press F12 or Ctrl + Shift + I (Windows/Linux) or Cmd + Option + I (Mac).
Go to the “Application” tab (Chrome) or “Storage” tab (Firefox).
In the “Cookies” section, select https://finance.yahoo.com.
Look for the cookies named T and Y.
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:
Trueif the cookies are valid (the account is logged in),Falseotherwise (also emitted as a warning). The cookies are stored regardless.Falsecan 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, orNonewhen not logged in.- Return type:
str | None