yfinance

1.2.0 · active · verified Sun Apr 05

yfinance is a popular open-source Python library designed to access and retrieve financial market data from Yahoo! Finance. It simplifies fetching historical prices, financial statements, dividends, splits, and other relevant information for stocks, indices, and securities. The library is actively maintained with frequent updates, enabling users to efficiently perform financial analyses and gain insights.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to download historical stock data for a given ticker symbol and how to access fundamental information about a company using the Ticker object.

import yfinance as yf
import pandas as pd

# Download historical data for a single ticker (e.g., Apple)
ticker_symbol = "AAPL"
data = yf.download(ticker_symbol, start="2023-01-01", end="2023-12-31")

print(f"Downloaded {len(data)} rows for {ticker_symbol}:")
print(data.head())

# Access information about a ticker
ticker = yf.Ticker(ticker_symbol)
info = ticker.info
print(f"\nMarket Cap for {ticker_symbol}: {info.get('marketCap')}")

view raw JSON →