A Python financial data library with automatic multi-source failover.
xFinance wraps Yahoo Finance's API with the same interface you already know, but falls back transparently to Stooq, SEC EDGAR, ECB, Binance, and CoinGecko when Yahoo is rate-limited or unavailable. No code changes, no API keys needed.
import xfinance as xf
t = xf.Ticker("AAPL")
print(t.history(period="1y"))
print(t.info)
print(t.income_stmt)
# Concurrent multi-symbol download
df = xf.download(["AAPL", "MSFT", "GOOGL"], period="1y")
print(df["Close"])pip install xfinanceRequires Python 3.10+. Dependencies: httpx, pandas, pydantic, pybreaker, tenacity.
Sources are tried in priority order. If a source doesn't support the requested data type, or returns an error, the next one is tried automatically.
| Source | Prices | Info | Forex | Crypto | Fundamentals | Options |
|---|---|---|---|---|---|---|
| Yahoo Finance | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Stooq | ✓ | — | ✓ | — | — | — |
| SEC EDGAR | — | ✓ | — | — | ✓ | — |
| ECB Frankfurter | — | — | ✓ | — | — | — |
| Binance | ✓ | ✓ | — | ✓ | — | — |
| CoinGecko | ✓ | ✓ | — | ✓ | — | — |
All sources are public or free-tier — no API keys required.
Circuit breaker: After 5 consecutive failures, a source is skipped for 60 seconds.
All properties are lazy — fetched on first access, cached for 5 minutes.
Properties:
history(period="1mo", interval="1d", start=None, end=None, **kwargs)— OHLCV DataFrame (UTC index)dividends,splits,actions— historical corporate actionsinfo— company metadata dict (200+ fields)income_stmt,balance_sheet,cashflow— annual financial statementsincome_stmt_quarterly,balance_sheet_quarterly,cashflow_quarterlyoption_chain(expiry_date)— NamedTuple withcallsandputsDataFramesoptions— available expiry datescalendar,earnings_datesrecommendations,analyst_price_targetsinstitutional_holders,major_holders,insider_transactionssustainability,newsfast_info— quick access wrapper (t.fast_info.market_cap,t.fast_info["marketCap"])
Methods:
sec_financials(concept, taxonomy)— audited XBRL data from SEC EDGARget_shares_full()— historical share count from 10-K/10-Q filings
tickers = xf.Tickers(["AAPL", "MSFT", "GOOGL"])
tickers.history(period="6mo") # dict of per-ticker DataFrames
tickers.download(period="6mo") # concurrent, single MultiIndex DataFrameConcurrent multi-symbol download, yfinance-compatible signature.
| Parameter | Default | Description |
|---|---|---|
symbols |
— | list of ticker symbols |
period / interval / start / end |
— | date range |
group_by |
"price" |
"price" or "ticker" column ordering |
auto_adjust |
True |
adjust OHLC for splits and dividends |
actions |
True |
include Dividends/Stock Splits columns |
keepna |
False |
keep all-NaN rows |
na_fill |
None |
None, "ffill", "bfill", or scalar |
repair |
False |
fix 100× unit errors and split-unadjusted bars |
rounding |
False |
round prices to 2 decimal places |
Returns a MultiIndex DataFrame with DatetimeIndex (UTC).
Custom sources can be added via Python entry points. Implement the DataSource protocol (see src/xfinance/sources/base.py) and register in pyproject.toml:
[project.entry-points."xfinance.sources"]
mysource = "my_source:MySource"The router discovers and uses registered sources automatically.
Users are responsible for complying with each provider's ToS:
- Yahoo Finance: Unofficial API. Personal research only; do not redistribute data.
- Stooq: Free historical data. Respect fair-use guidelines.
- SEC EDGAR: U.S. government data, public domain.
- ECB / Frankfurter: Public data.
- Binance: Commercial redistribution requires enterprise agreement.
- CoinGecko: Free tier: 30 req/min. Commercial redistribution requires enterprise agreement.
Apache 2.0