π§° 1. yfinance
β Yahoo Finance API Wrapper
Fetch historical market data, live prices, and financials.
π§ͺ Example
import yfinance as yf
ticker = yf.Ticker("AAPL" )
data = ticker.history(start= "2022-01-01" , end= "2023-01-01" )
print (data[['Open' , 'Close' ]].head())
β
You Get:
Historical prices
Live market data
Dividend and split history
Financials and balance sheets
import yfinance as yf
ticker = yf.Ticker("AAPL" )
data = ticker.history(start= "2022-01-01" , end= "2023-01-01" )
print (data[['Open' , 'Close' ]].head())
Open Close
Date
2022-01-03 00:00:00-05:00 174.771775 178.879883
2022-01-04 00:00:00-05:00 179.489269 176.609650
2022-01-05 00:00:00-05:00 176.521166 171.911819
2022-01-06 00:00:00-05:00 169.730012 169.042053
2022-01-07 00:00:00-05:00 169.916741 169.209122
π§° 2. pandas_datareader
β Interface to Many Financial Sources
Access data from Yahoo, Alpha Vantage, FRED, IEX Cloud, and more.
π¦ Install
pip install pandas_datareader
π§ͺ Example
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2022 , 1 , 1 )
end = datetime.datetime(2023 , 1 , 1 )
df = web.DataReader("AAPL" , "yahoo" , start, end)
print (df.head())
β
You Get:
Price data from multiple sources
Economic indicators from FRED
World Bank, OECD, etc.
π§° 3. alpha_vantage
β Real-Time Stock & Crypto Data
Requires a free API key .
π¦ Install
pip install alpha_vantage
π§ͺ Example
from alpha_vantage.timeseries import TimeSeries
ts = TimeSeries(key= 'YOUR_API_KEY' , output_format= 'pandas' )
data, meta = ts.get_daily(symbol= 'MSFT' , outputsize= 'compact' )
print (data.head())
β
You Get:
Time series (daily, intraday)
Technical indicators
Forex, crypto, and ETF support
π§° 4. investpy
(Discontinued β Use Forks)
Used for international stocks, ETFs, indices. Forks like investpy-reborn
may work.
π¦ Install
pip install investpy-reborn
π§ͺ Example
import investpy
df = investpy.get_stock_historical_data(stock= 'AAPL' ,
country= 'united states' ,
from_date= '01/01/2022' ,
to_date= '01/01/2023' )
print (df.head())
β
You Get:
Global markets
Historical and real-time data
ETF, fund, and commodity prices
π§° 5. yahoo_fin
β Financials, Options, and News
More detailed financials and news than yfinance
.
π§ͺ Example
from yahoo_fin import stock_info as si
price = si.get_live_price("AAPL" )
print (f"Apple Live Price: { price} " )
financials = si.get_income_statement("AAPL" )
print (financials)
β
You Get:
Live price, historical data
Balance sheet, income statements
Earnings calendar & news
π§° 6. finnhub-python
β Real-Time Stock & News API
Requires free API key .
π¦ Install
pip install finnhub-python
π§ͺ Example
import finnhub
client = finnhub.Client(api_key= "YOUR_API_KEY" )
quote = client.quote("AAPL" )
print (quote)
β
You Get:
Real-time quotes
News and earnings
Social sentiment (Reddit, Twitter)
π 7. ccxt
β Crypto Exchange Data
If youβre also into crypto, this is a must.
π§ͺ Example
import ccxt
exchange = ccxt.binance()
ticker = exchange.fetch_ticker('BTC/USDT' )
print (ticker['last' ])
β
You Get:
Live crypto prices
Order books
Exchange-specific APIs
π§ Comparison Table
yfinance
Yahoo Finance
Historical prices, financials
β No
pandas_datareader
Yahoo, FRED, IEX
Stocks, macro data
β οΈ Some sources
alpha_vantage
Alpha Vantage
Time series, indicators
β
Yes
investpy
Investing.com
Global stocks, ETFs
β No
yahoo_fin
Yahoo Finance
Financials, earnings, options
β No
finnhub
Finnhub.io
Real-time data, news, sentiment
β
Yes
ccxt
Crypto exchanges
Live crypto, orders
β οΈ Varies
Back to top