Skip to main content

Migrate from yfinance

yfin is designed so most yfinance-shaped Python code can keep the same call patterns. The usual migration is changing the import and, for services or agents, declaring a contact identity.

Minimal Migration

Before:

import yfinance as yf

ticker = yf.Ticker("AAPL")
history = ticker.history(period="5d", interval="1d")

After:

import yfin as yf

ticker = yf.Ticker("AAPL", contact="you@example.com")
history = ticker.history(period="5d", interval="1d")

For larger codebases, keep the alias as yf and replace the package import:

- import yfinance as yf
+ import yfin as yf

You can also set identity once for a process:

export YFIN_CONTACT=you@example.com

Compatibility Map

Use this table to migrate common yfinance calls. The right column shows what to change when moving to yfin.

Existing yfinance usageyfin usageMigration notes
import yfinance as yfimport yfin as yfKeep the yf alias so most existing code does not change.
yf.Ticker("AAPL")yf.Ticker("AAPL")Optionally pass contact="you@example.com" or set YFIN_CONTACT.
ticker.history(period="1mo", interval="1d")Same callSupports period, start, end, interval, prepost, actions, auto_adjust, back_adjust, keepna, and rounding.
yf.download(["AAPL", "MSFT"], period="5d")Same callWorks for one ticker or many tickers.
ticker.fast_infoSame propertyReturns a dict-like fast quote snapshot.
ticker.infoSame propertyReturns a dict suitable for existing ticker.info[...] access patterns.
ticker.history_metadataSame propertyReturns chart metadata for the ticker.
ticker.optionsSame propertyReturns available option expiration dates.
ticker.option_chain()Same callAccepts an optional expiration date, same as yfinance-style usage.
ticker.dividendsSame propertyReturns a pandas Series.
ticker.splitsSame propertyReturns a pandas Series.
ticker.actionsSame propertyReturns dividends, splits, and capital gains where Yahoo returns them.
ticker.capital_gainsSame propertyReturns a pandas Series where Yahoo returns fund capital gains.
ticker.financials, ticker.income_stmtSame propertiesReturns pandas DataFrames.
ticker.balance_sheetSame propertyReturns a pandas DataFrame.
ticker.cash_flowSame propertyReturns a pandas DataFrame.
ticker.quarterly_income_stmtSame propertyQuarterly financial statement access keeps the yfinance-shaped property name.
ticker.ttm_income_stmt, ticker.ttm_cash_flowSame propertiesTrailing-twelve-month statement access keeps the yfinance-shaped property names.
ticker.earnings, ticker.earnings_datesSame properties/callsget_earnings_dates(limit=..., offset=...) is also available.
ticker.recommendationsSame propertyReturns analyst recommendation trend data as a DataFrame.
ticker.upgrades_downgradesSame propertyReturns analyst upgrade/downgrade history as a DataFrame.
ticker.analyst_price_targetsSame propertyReturns target price fields in a dict.
ticker.major_holdersSame propertyReturns holder data as a DataFrame.
ticker.institutional_holdersSame propertyReturns holder data as a DataFrame.
ticker.mutualfund_holdersSame propertyReturns holder data as a DataFrame.
ticker.insider_transactionsSame propertyReturns insider transaction data as a DataFrame.
ticker.calendarSame propertyReturns earnings and calendar event data as a dict.
ticker.sec_filingsSame propertyReturns SEC filing metadata as a dict.
ticker.sustainabilitySame propertyReturns ESG/sustainability data where Yahoo returns it.
ticker.shares, ticker.shares_fullSame properties/callsget_shares_full(start=..., end=...) is also available.
ticker.funds_data.top_holdingsSame property pathFund overview, operations, holdings, ratings, and sector weightings keep the yfinance-shaped access pattern.
ticker.newsSame propertyReturns a list of article dictionaries.
yf.WebSocket(...), yf.AsyncWebSocket(...)Same constructorsSubscribe to symbols using the same high-level shape.

Migration Checklist

  1. Install yfin:
pip install yfin
  1. Replace the import:
import yfin as yf
  1. Add a contact identity for scripts, services, notebooks, and agents:
export YFIN_CONTACT=you@example.com
  1. Run your existing yfinance tests or notebook cells.

  2. If you hit rate limits, check Rate Limits and use an API key when your workload needs higher limits.

Useful yfin Additions

These are not required for migration, but they are useful once existing code is running on yfin.

Use the low-level hosted API client:

import yfin

client = yfin.Client(contact="you@example.com")
print(client.quote(["AAPL", "MSFT"]))
print(client.history("NVDA", range="5d", interval="1h"))

Access an advanced endpoint by catalog ID:

import yfin as yf

ticker = yf.Ticker("AAPL")
payload = ticker.raw("v7.quote", symbols="AAPL,MSFT")

Browse REST endpoints in the API Reference.

What Changes

  • yfin uses the hosted api.yfin.dev API, so the same market-data surface is available from Python, REST, TypeScript, JavaScript, and AI tools.
  • Public usage works without signup, but services should declare YFIN_CONTACT or pass contact=.
  • Existing yfinance-shaped calls are the migration target. Code that imports private yfinance modules should use yfin's public SDK or REST API instead.