API Documentation¶
Please note that the API is currently under development and things may change rapidly!
Core Interface¶
-
class
yahoofinance.interfaces.IYahooData(locale)[source]¶ This is the base interface.
Each class in this library inherits implements this interface.
This class is NOT instantiable.
Parameters: locale – a yahoofinance.Localeconstant to determine which domain to query from.
Historical Data¶
-
class
yahoofinance.HistoricalPrices(instrument, start_date, end_date, date_format_string='%Y-%m-%d', event='history', frequency='1d', locale='')[source]¶ Retrieves historical data from Yahoo Finance.
Parameters: - instrument – The a stock instrument code to query.
- start_date – The start date for the query (inclusive).
- end_date – The end date for the query (inclusive).
- date_format_string – If start_date or end_date is not a
DateTimeobject, the object passed in (string) will be parsed to the format string. Default: %Y-%m-%d. - event – A DataEvent constant to determine what event to query for. Default: DataEvent.HISTORICAL_PRICES.
- frequency – A DataFrequency constant to determine the interval between records. Default: DataFrequency.DAILY.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: HistoricalPricesobjectReturn type: HistoricalPrices
E.g. https://finance.yahoo.com/quote/AAPL/history
Usage:
>>> from yahoofinance import HistoricalPrices >>> req = HistoricalPrices('AAPL') Object<HistoricalPrices>
-
to_csv(path=None, sep=', ', data_format='raw', csv_dialect='excel')[source]¶ Generates a CSV file.
Parameters: - path – The path to a file location. If it is None, this method returns the CSV as a string.
- sep – The separator between elements in the new line. NOT USED
- data_format – A
DataFormatconstant to determine how the data is exported. NOT USED - csv_dialect – The dialect to write the CSV file. See Python in-built
csv.
Returns: None or
stringReturn type: None or string
-
to_dfs(data_format='raw')[source]¶ Generates a dictionary containing
pandas.DataFrame.Parameters: data_format – A DataFormatconstant to determine how the data is exported. NOT USEDReturns: pandas.DataFrameReturn type: pandas.DataFrame Dictionary keys
Historical Prices
Note: All of the below classes below are experimental and results may vary significantly as they data is scraped from the website. Use at your own risk!
Balance Sheet¶
-
class
yahoofinance.BalanceSheet(stock, locale='')[source]¶ Retrieves annual balance sheet information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: BalanceSheetobjectReturn type: BalanceSheet
E.g. https://finance.yahoo.com/quote/AAPL/balance-sheet
Usage:
>>> from yahoofinance import BalanceSheet >>> req = BalanceSheet('AAPL') Object<BalanceSheet>
-
to_csv(path=None, sep=', ', data_format='raw', csv_dialect='excel')[source]¶ Generates a CSV file.
Parameters: - path – The path to a file location. If it is None, this method returns the CSV as a string.
- sep – The separator between elements in the new line.
- data_format – A
DataFormatconstant to determine how the data is exported. - csv_dialect – The dialect to write the CSV file. See Python in-built
csv.
Returns: None or
stringReturn type: None or string
-
to_dfs(data_format='raw')[source]¶ Generates a dictionary containing
pandas.DataFrame.Parameters: data_format – A DataFormatconstant to determine how the data is exported.Returns: pandas.DataFrameReturn type: pandas.DataFrame Dictionary keys
Cash Flow Overall Operating activities Investment activities Financing activities Changes in Cash
-
class
yahoofinance.BalanceSheetQuarterly(stock, locale='')[source]¶ Retrieves quarterly balance sheet information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: BalanceSheetQuarterlyobjectReturn type: BalanceSheetQuarterly
E.g. https://finance.yahoo.com/quote/AAPL/balance-sheet
Usage:
>>> from yahoofinance import BalanceSheetQuarterly >>> req = BalanceSheetQuarterly('AAPL') Object<BalanceSheetQuarterly>
Cash Flow¶
-
class
yahoofinance.CashFlow(stock, locale='')[source]¶ Retrieves annual cash flow information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: CashFlowobjectReturn type: CashFlow
E.g. https://finance.yahoo.com/quote/AAPL/cash-flow
Usage:
>>> from yahoofinance import CashFlow >>> req = CashFlow('AAPL') Object<CashFlow>
-
to_csv(path=None, sep=', ', data_format='raw', csv_dialect='excel')[source]¶ Generates a CSV file.
Parameters: - path – The path to a file location. If it is None, this method returns the CSV as a string.
- sep – The separator between elements in the new line.
- data_format – A
DataFormatconstant to determine how the data is exported. - csv_dialect – The dialect to write the CSV file. See Python in-built
csv.
Returns: None or
stringReturn type: None or string
-
to_dfs(data_format='raw')[source]¶ Generates a dictionary containing
pandas.DataFrame.Parameters: data_format – A DataFormatconstant to determine how the data is exported.Returns: pandas.DataFrameReturn type: pandas.DataFrame Dictionary keys
Cash Flow Overall Operating activities Investment activities Financing activities Changes in Cash
-
class
yahoofinance.CashFlowQuarterly(stock, locale='')[source]¶ Retrieves quarterly cash flow information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: CashFlowQuarterlyobjectReturn type: CashFlowQuarterly
E.g. https://finance.yahoo.com/quote/AAPL/cash-flow
Usage:
>>> from yahoofinance import CashFlowQuarterly >>> req = CashFlowQuarterly('AAPL') Object<CashFlowQuarterly>
Income Statement¶
-
class
yahoofinance.IncomeStatement(stock, locale='')[source]¶ Retrieves annual balance sheet information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: IncomeStatementobjectReturn type: IncomeStatement
E.g. https://finance.yahoo.com/quote/AAPL/financials
Usage:
>>> from yahoofinance import IncomeStatement >>> req = IncomeStatement('AAPL') Object<IncomeStatement>
-
to_csv(path=None, sep=', ', data_format='raw', csv_dialect='excel')[source]¶ Generates a CSV file.
Parameters: - path – The path to a file location. If it is None, this method returns the CSV as a string.
- sep – The separator between elements in the new line.
- data_format – A
DataFormatconstant to determine how the data is exported. - csv_dialect – The dialect to write the CSV file. See Python in-built
csv.
Returns: None or
stringReturn type: None or string
-
to_dfs(data_format='raw')[source]¶ Generates a dictionary containing
pandas.DataFrame.Parameters: data_format – A DataFormatconstant to determine how the data is exported.Returns: pandas.DataFrameReturn type: pandas.DataFrame Dictionary keys
Cash Flow Overall Operating activities Investment activities Financing activities Changes in Cash
-
class
yahoofinance.IncomeStatementQuarterly(stock, locale='')[source]¶ Retrieves quarterly balance sheet information from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The a stock code to query.
- locale – A Locale constant to determine which domain to query from. Default: Locale.US.
Returns: IncomeStatementQuarterlyobjectReturn type: IncomeStatementQuarterly
E.g. https://finance.yahoo.com/quote/AAPL/financials
Usage:
>>> from yahoofinance import IncomeStatementQuarterly >>> req = IncomeStatementQuarterly('AAPL') Object<IncomeStatementQuarterly>
Asset Profile¶
-
class
yahoofinance.AssetProfile(stock, locale='')[source]¶ Retrieves the asset profile from Yahoo Finance.
EXPERIMENTAL
Parameters: - stock – The stock ticker
- locale – A Local constant to determine which domain to query from. Default: Locale.US.
Returns: AssetProfileobjectReturn type: AssetProfile
E.g. https://finance.yahoo.com/quote/AAPL/profile
Usage:
>>> from yahoofinance import AssetProfile >>> req = AssetProfile('AAPL') Object<AssetProfile>
-
to_csv(path, sep=', ', data_format='raw', csv_dialect='excel')[source]¶ Generates a CSV file.
Parameters: - path – The path to a file location. If it is None, this method returns the CSV as a string.
- sep – The separator between elements in the new line. NOT USED
- data_format – A
DataFormatconstant to determine how the data is exported. NOT USED - csv_dialect – The dialect to write the CSV file. See Python in-built
csv.
Returns: None or
stringReturn type: None or string
Additional Config¶
-
class
yahoofinance.Locale[source]¶ Provides locale information to any
IYahooDataimplementations.- By using your local domain, it may speed up queries by a miniscule amount or bypass
- certain country domain filters and restrictions.
-
AU= 'au'¶ Uses the Australian domain. E.g. https://au.finance.yahoo.com/quote/AAPL/
-
CA= 'ca'¶ Uses the Canadian domain. E.g. https://ca.finance.yahoo.com/quote/AAPL/
-
US= ''¶ Uses the United States domain. E.g. https://finance.yahoo.com/quote/AAPL/
-
class
yahoofinance.DataEvent[source]¶ Provides data event information for
HistoricalData.Yahoo provides 3 different types of historical data sets.
-
class
yahoofinance.DataFrequency[source]¶ Provides data frequency information for
HistoricalData.Yahoo provides data at 3 different time granuarities.
-
DAILY= '1d'¶ Retrieve data at daily intervals.
-
MONTHLY= '1mo'¶ Retrieve data at montly intervals.
-
WEEKLY= '1wk'¶ Retrieve data at weekly intervals.
-