What is yfinance python

Last updated: April 1, 2026

Quick Answer: yfinance is a free, open-source Python library that provides a simple interface for downloading financial market data from Yahoo Finance. Created by developer Ran Aroussi and first published on PyPI in 2017, it allows users to retrieve historical stock prices, real-time quotes, dividends, financial statements, and options data with just a few lines of Python code. As of 2024, the yfinance GitHub repository has over 12,000 stars and is downloaded millions of times per month, making it one of the most widely used financial data libraries in the Python ecosystem. No API key or paid subscription is required.

Key Facts

Overview: What Is yfinance and Why Was It Created?

yfinance is a widely adopted, open-source Python library that acts as a wrapper around Yahoo Finance's financial data endpoints, enabling developers, traders, data scientists, and researchers to download market data quickly and programmatically. The library was created by Ran Aroussi (GitHub username: @ranaroussi) and was first made available through the Python Package Index (PyPI) in 2017.

The origin story of yfinance is rooted in a practical problem. Yahoo Finance had long provided a free, unofficial API that developers relied upon to access stock prices and financial data. When Yahoo restructured its finance infrastructure around 2017 and effectively deprecated its older data endpoints, the popular yahoo-finance Python library broke entirely, leaving thousands of developers without a reliable free data source. Ran Aroussi built yfinance as a direct response to this disruption, reverse-engineering Yahoo Finance's updated data delivery mechanisms and packaging the solution as an open-source library for the community.

At its technical core, yfinance works by making HTTP requests to Yahoo Finance's web endpoints and parsing the returned JSON and HTML data into Python-native data structures — primarily Pandas DataFrames. This design choice was deliberate: Pandas is the foundational data manipulation library in the Python data science ecosystem, meaning that data retrieved through yfinance is immediately compatible with NumPy, Matplotlib, scikit-learn, statsmodels, and virtually every other Python analytical tool without additional transformation.

One of yfinance's most important characteristics is its zero-cost, zero-friction access model. Unlike institutional-grade data providers such as Bloomberg Terminal (which can cost upward of $25,000 per year per user) or Refinitiv Eikon, yfinance requires no subscription, no API key, and no account registration. This accessibility has made it an essential tool for individual investors, university students, academic researchers, independent quantitative analysts, and anyone learning financial data analysis in Python.

The library covers an impressive breadth of financial instruments, including equities, ETFs, mutual funds, indices, currencies (Forex pairs), futures, bonds, and cryptocurrencies listed on exchanges in over 60 countries. Major exchanges supported include the NYSE, NASDAQ, London Stock Exchange (LSE), Tokyo Stock Exchange (TSE), Euronext, Hong Kong Stock Exchange, and many others.

Key Features, Functions, and How to Use yfinance

yfinance provides two primary interfaces for data retrieval: the Ticker class and the download() function. Each serves a distinct use case, and together they cover the vast majority of financial data needs for individual and research-oriented applications.

The Ticker class is the core object-oriented interface of yfinance. By instantiating a Ticker object for a given stock symbol — for example, yf.Ticker('AAPL') for Apple Inc. — users gain access to a rich set of attributes and methods that return comprehensive financial data. These include:

The download() function is optimized for batch retrieval of historical price data across multiple tickers simultaneously. A single function call such as yf.download(['AAPL', 'MSFT', 'GOOG'], start='2015-01-01', end='2024-01-01') returns a multi-level Pandas DataFrame containing daily OHLCV data for all three companies across the full specified date range. This batch capability is particularly valuable for portfolio analysis, multi-asset backtesting, and sector-level comparative studies.

yfinance supports multiple time intervals for historical data retrieval, including 1 minute, 2 minutes, 5 minutes, 15 minutes, 30 minutes, 60 minutes, 90 minutes, 1 day, 5 days, 1 week, 1 month, and 3 months. This flexibility accommodates use cases ranging from high-frequency intraday technical analysis to multi-decade fundamental research. It is important to note that intraday intervals (anything finer than 1 day) are subject to a data availability window of approximately 60 days from the current date, a limitation imposed by Yahoo Finance's own data retention policies rather than yfinance itself.

The library's integration with Pandas means users can immediately apply the full power of Python's data science stack to downloaded data. Common downstream workflows include calculating moving averages and technical indicators using libraries like TA-Lib or Pandas-TA, creating interactive charts with Plotly or Bokeh, building portfolio optimization models using PyPortfolioOpt, or training machine learning models using scikit-learn or TensorFlow on financial time series data.

Common Misconceptions About yfinance

Perhaps the most important misconception to correct is that yfinance represents an official Yahoo Finance API. It does not. Yahoo Finance discontinued its official public API in 2017, and no formal replacement has been provided. yfinance is an entirely community-built, unofficial tool that accesses Yahoo Finance's data by wrapping web endpoints not officially designated for programmatic access. This distinction has real practical consequences: Yahoo Finance can — and occasionally does — modify its data delivery infrastructure without warning, which can temporarily break yfinance's functionality until the library's maintainers push an update. This has happened multiple times in the library's history, leading to brief periods where yfinance users experienced errors or data gaps.

A second significant misconception is that yfinance provides true real-time market data suitable for live algorithmic trading systems. The data available through Yahoo Finance's free tier — and therefore through yfinance — is generally subject to a 15-minute delay on most major exchanges during market hours. This delay is standard for free consumer-facing financial data and is clearly distinct from the millisecond-latency feeds used by professional trading firms. Developers building live trading systems should use purpose-built brokerage APIs such as Alpaca, Interactive Brokers TWS API, or TD Ameritrade's API for execution-quality data.

A third misconception is that yfinance data is invariably accurate and complete for all instruments. While the library's coverage of large-cap US equities is generally reliable, users have documented instances of data gaps, incorrect split or dividend adjustments, and missing records — particularly for smaller-capitalization stocks, foreign-listed securities, and historical records from before the 1990s. For production-grade financial applications where data accuracy is critical, yfinance data should be cross-validated against authoritative sources such as CRSP, Bloomberg, or Compustat.

Practical Considerations, Best Practices, and Use Cases

For developers and analysts using yfinance in practical applications, several best practices help avoid common pitfalls. First, regarding rate limiting and request throttling: because yfinance makes HTTP requests to Yahoo Finance's servers, sending a very large volume of requests in rapid succession can result in temporary IP-based throttling or connection refusals. For projects that require downloading data for hundreds or thousands of tickers, it is advisable to introduce deliberate delays between request batches and to implement retry logic with exponential backoff.

Second, local data caching is strongly recommended for any project that requires repeated access to the same historical data. Downloading the same three years of daily Apple price data ten times is wasteful when the same data can be saved once to a CSV or Parquet file and reloaded instantly from disk. This practice dramatically reduces latency, eliminates redundant network traffic, and insulates the application from temporary Yahoo Finance connectivity issues.

Third, users should be aware of the adjusted vs. unadjusted price distinction. yfinance offers both raw (unadjusted) closing prices and adjusted closing prices that account for stock splits and dividends. Using unadjusted prices in total-return calculations introduces systematic errors — for example, Apple's 4-for-1 stock split in August 2020 would make pre-split prices appear four times higher than post-split prices without adjustment. For any analysis involving portfolio returns or performance attribution, always use adjusted closing prices.

Common real-world applications built using yfinance include stock screening tools that filter equities by fundamental metrics like P/E ratio and earnings growth, quantitative backtesting frameworks that evaluate trading strategy performance on historical data, portfolio dashboards that track real-time portfolio value and performance attribution, academic research projects studying market efficiency, volatility dynamics, or factor investing, and machine learning models that attempt to predict stock price movements using historical OHLCV features.

For those new to Python financial data analysis, yfinance represents an ideal starting point. Its installation is a single pip command, its API is intuitive and well-documented, and its GitHub repository — with over 12,000 stars and an active community of contributors — provides extensive examples, issue tracking, and ongoing maintenance. Whether the goal is understanding how to import financial data into a Jupyter notebook for the first time or building a sophisticated quantitative research platform, yfinance provides a reliable, accessible, and powerful foundation.

Related Questions

How do I install yfinance in Python?

yfinance can be installed using pip with the command "pip install yfinance" in your terminal or command prompt. It is also available via conda with "conda install -c conda-forge yfinance" for users in conda environments. The library requires Python 3.6 or higher and has dependencies including Pandas, NumPy, requests, and lxml, which pip installs automatically. No API key, Yahoo Finance account, or paid subscription is needed — the library is ready to use immediately after installation.

How do I download historical stock data with yfinance?

To download historical stock data, import yfinance and use the download() function: "import yfinance as yf; data = yf.download('AAPL', start='2020-01-01', end='2024-01-01')" returns Apple's daily OHLCV data as a Pandas DataFrame for the specified date range. You can specify intervals such as '1m', '5m', '1h', '1d', '1wk', or '1mo' to control data granularity, and download multiple tickers simultaneously by passing a Python list of ticker symbols. Note that intraday intervals are limited to the past 60 days due to Yahoo Finance's data retention policy.

What financial data can yfinance retrieve?

yfinance provides access to historical OHLCV price data going back 20+ years for major stocks, real-time quotes with approximately a 15-minute delay, dividends and stock split history, annual and quarterly income statements, balance sheets, and cash flow statements, analyst recommendations, institutional ownership data, options chain data with implied volatility and open interest, and ESG sustainability scores. It covers thousands of instruments including stocks, ETFs, mutual funds, currencies, futures, and cryptocurrencies across exchanges in over 60 countries.

Is yfinance free to use and what are its limitations?

Yes, yfinance is completely free and is licensed under the Apache License 2.0, permitting both personal and commercial use. However, it relies on Yahoo Finance's unofficial web endpoints rather than a paid API, so data typically carries a 15-minute delay during market hours and does not meet the latency standards required for live algorithmic trading. Additionally, Yahoo Finance can change its data structure without notice, occasionally causing temporary library breakages, and data quality for small-cap or international securities can be inconsistent compared to paid institutional data providers.

What are the best alternatives to yfinance for Python?

Popular alternatives to yfinance include Alpaca's market data API (which offers free-tier real-time US equity data and is better suited for live trading), Quandl/Nasdaq Data Link (which provides curated economic and financial datasets with academic licensing), pandas-datareader (which supports FRED Federal Reserve data, Stooq, and World Bank), and Alpha Vantage (which offers free and paid tiers with global equity and cryptocurrency coverage). For institutional-grade needs, Bloomberg's Python API (blpapi) and Refinitiv Eikon provide premium data with guaranteed quality and service levels, though subscriptions typically cost thousands of dollars annually.

Sources

  1. yfinance GitHub Repository - Ran Aroussi Apache License 2.0
  2. yfinance on PyPI - Python Package Index Apache License 2.0
  3. Yahoo Finance - Primary Data Source All rights reserved
  4. Yahoo! Finance - Wikipedia CC BY-SA 4.0