yfinance Library
Download market data from Yahoo Finance for stocks, forex, cryptocurrencies, and more. The easiest way to get historical and real-time financial data in Python.
Installation
What You Can Download
Stocks
US and international stocks from major exchanges
AAPL, MSFT, TSLAForex
Major and exotic currency pairs
EURUSD=X, GBPJPY=XCryptocurrencies
Bitcoin, Ethereum, and altcoins
BTC-USD, ETH-USDIndices
Market indices and ETFs
^GSPC, ^DJI, SPYCommodities
Gold, oil, and other commodities
GC=F, CL=FFundamentals
Company info, financials, dividends
P/E, Market Cap, EPSCode Examples
Download Stock Data
Get historical OHLCV data for any ticker
Download Forex Data
Get currency pair historical data
Download Cryptocurrency Data
Get Bitcoin, Ethereum, and other crypto data
Download Multiple Tickers
Batch download multiple symbols at once
Get Ticker Information
Access company info, financials, and fundamentals
Cache Data Locally
Save data to avoid repeated downloads
Get Real-Time Quotes
Access current price and market data
Complete Trading Strategy
Download data and backtest a strategy
Best Practices
Cache Data
Save downloaded data locally to avoid repeated API calls
Handle Missing Data
Always check for NaN values and handle missing data appropriately
Rate Limits
Yahoo Finance may rate limit excessive requests. Add delays between calls
Data Quality
Verify data quality, especially for less liquid symbols