What does it do?
yfinance quietly pulls stock prices, dividends, earnings dates, and historical charts from the same data powering the Yahoo Finance website, and hands it to you as clean, ready-to-analyze tables. Instead of copy-pasting numbers off a webpage, someone curious about a company’s stock price over the last five years can get it in a single line of code. It covers stocks, ETFs, currencies, and some crypto pricing, plus company fundamentals like balance sheets. It’s become the default way hobbyists and students get real market data without paying anyone.
See it in action
This looks up Apple’s stock and prints its price history for the last six months along with its current market value.
import yfinance as yf
apple = yf.Ticker("AAPL")
history = apple.history(period="6mo")
print(history.tail())
print(apple.info["marketCap"])
Why would a non-developer care?
Access to historical financial data used to be gatekept behind expensive subscriptions aimed at institutions, not individuals. Tools like this are a big part of why an ordinary person with a laptop can now run the kind of stock analysis that used to require a finance job and a corporate data terminal.
Real-world examples
It’s the go-to starting point in nearly every learn-stock-analysis-with-Python tutorial and video, and it’s baked into countless personal finance dashboards, trading bots, and class projects. Because it relies on Yahoo’s public site rather than an official supported API, it periodically breaks when Yahoo changes something, a running joke about how much retail-trading code depends on this one unofficial pipeline.
Who uses it
Hobbyist investors, students, and researchers who want free historical market data without a commercial financial data subscription.
How it compares to alternatives
It’s the free, easy alternative to paid data providers like Bloomberg or Refinitiv, though pandas-datareader offers a similar free tier pulling from more varied sources, and unlike yfinance isn’t reverse-engineering a public website to work.
Fun fact
yfinance isn’t officially affiliated with or supported by Yahoo at all; it works by mimicking what your browser does when you visit the Yahoo Finance site, which is why it occasionally breaks overnight.