Yahoo Finance API (yfinance) Review
Yahoo Finance is the most widely used free source of financial data for Python developers. The yfinance library by Ran Aroussi wraps Yahoo Finance data into a clean Python interface. It provides historical OHLCV data, fundamental data, options chains, analyst recommendations, and more. While not an official API, it is the go-to choice for learning, prototyping, and personal projects.
Pricing
- ✓ Historical OHLCV data
- ✓ Fundamentals & financials
- ✓ Options chains
- ✓ Analyst data
- ✓ No API key needed
- ✓ Enhanced charts
- ✓ Research reports
- ✓ Portfolio tools
- ✓ No ads
- ✓ Does NOT improve API access
Pros
- + Completely free with no API key
- + Incredibly easy to use with yfinance
- + Covers most global markets
- + Includes fundamentals, options, and earnings data
- + Huge community and StackOverflow support
Cons
- - Unofficial API, can break without warning
- - Rate limited (too many requests get blocked)
- - Data quality is not guaranteed
- - No real-time streaming (delayed quotes)
- - Not suitable for production trading systems
Who Is It For?
yfinance is perfect for learning, personal projects, academic research, and prototyping. If you need reliable, real-time data for production trading, use a paid provider like Polygon.io or Interactive Brokers.
Code Example
import yfinance as yf
import pandas as pd
# Single stock
aapl = yf.Ticker("AAPL")
# Historical data
hist = aapl.history(period="1y")
print(hist.tail())
# Fundamental data
print(f"Market Cap: {aapl.info.get('marketCap', 'N/A')}")
print(f"P/E Ratio: {aapl.info.get('trailingPE', 'N/A')}")
print(f"Dividend Yield: {aapl.info.get('dividendYield', 'N/A')}")
# Financials
print(aapl.financials)
# Options chain
options = aapl.options # Available expiry dates
chain = aapl.option_chain(options[0])
print(f"Calls: {len(chain.calls)}, Puts: {len(chain.puts)}")
# Multiple stocks at once
data = yf.download(["AAPL", "MSFT", "GOOGL"], start="2023-01-01", end="2024-01-01")
print(data["Close"].tail())
# Analyst recommendations
print(aapl.recommendations.tail())Alternatives
Recommended Reading
Algorithmic Trading with Python →As an Amazon Associate we may earn from qualifying purchases.