yfinance is a free, open-source Python library for retrieving financial data from Yahoo Finance. It loads market information into Python data structures, making it a practical starting point for experimenting with fundamental and technical analysis. section 3.0 section 3.4
Use yfinance to collect and inspect several kinds of investment data:
- Create a Ticker object with a stock symbol such as MSFT, AAPL, RR.L, or ALV.DE. section 3.4
- Retrieve income statements, balance sheets, cash-flow statements, quarterly statements, and company information. section 3.4.1
- Read financial ratios and corporate attributes such as current price, sector, industry, current ratio, and quick ratio. section 3.4.1
- Combine collected statements to calculate measures such as return on assets, return on equity, profit margin, asset turnover, and debt-to-equity. section 3.4.1
import yfinance as yf
microsoft = yf.Ticker('MSFT')
microsoft.income_stmt
microsoft.balance_sheet
microsoft.cash_flow
The basic workflow creates a Ticker object and exposes accounting statements as DataFrames, which can then be indexed by reporting date and metric. section 3.4.1
Comparing company ratios
A helper function can loop over tickers such as WMT, MO, NVDA, and CRM, collect selected attributes from each Ticker.info dictionary, and return one Pandas DataFrame with a row per company. section 3.4.1
Treat yfinance as an exploratory tool rather than a guaranteed production data service. It wraps Yahoo’s internal API and uses web-scraping frameworks; Yahoo does not maintain the library, so platform changes or anti-scraping measures could break it without warning. Check ticker conventions across exchanges, monitor library updates, and consider paid providers when reliability, quotas, or service guarantees matter. section 3.4.3 section 3.5 section 3.6

