A Python financial data library that delivers yfinance's simplicity with better reliability. Automatic multi-source failover—when Yahoo Finance is rate-limited or unavailable, data transparently falls back to Stooq, SEC, ECB, Binance, or CoinGecko. No code changes. No API keys needed.
yfinance relies on a single source: Yahoo Finance. When Yahoo hits its ~950 request per session limit, or when Yahoo's API breaks (which happens frequently), users get rate limit errors or empty DataFrames with no fallback.
xFinance solves this with automatic multi-source failover. If Yahoo is throttled, data silently falls back to Stooq. If that fails, it tries SEC, ECB, Binance, CoinGecko. Same API. Same data structure. No code changes.
xFinance implements a pluggable DataSourceRouter that tries sources in priority order. Each source is wrapped in a circuit breaker: after 5 consecutive failures, that source is "open" for 60 seconds. Further requests skip it without wasting HTTP calls. Transient errors trigger exponential backoff with up to 4 retries.
xFinance queries sources in priority order. Each supports a different mix of data types. Yahoo Finance covers everything (but is rate-limited). Stooq covers equities and forex cheaply. SEC provides audited fundamentals. ECB covers forex. Binance and CoinGecko cover crypto.
Use xFinance exactly like yfinance. Same method names. Same return types (pandas DataFrames). Same lazy evaluation and caching. Drop-in replacement: change import yfinance to import xfinance.
Concurrent downloads are 50× faster than sequential. Circuit breaker and cache reduce API pressure. No API keys needed—all sources are public or free-tier.
| Feature | yfinance | xFinance | Benefit |
|---|---|---|---|
| Rate Limit Handling | Crashes (SourceRateLimitError) | Automatic fallback | ✓ Works every time |
| Failover Sources | None (1 source) | 5 alternatives + plugin arch | ✓ Resilient |
| Multi-Symbol Speed | Sequential (~10s for 100 tickers) | Concurrent (~0.2s for 100 tickers) | ✓ 50× faster |
| Caching | None | Per-instance, 5-min TTL | ✓ Instant repeats |
| API Keys Required | No (unofficial) | No (all public/free) | ✓ Zero setup |
| Error Transparency | Silent failures (empty DataFrame) | Rich exceptions + source provenance | ✓ Debuggable |
Without xFinance, if Yahoo hits rate limits, you get an error and no data. With xFinance, it silently falls back to Stooq, then ECB, until one succeeds. Same code. No retry logic needed.
Add your own data source with a simple plugin. Implement the DataSource protocol (<100 lines), register in pyproject.toml, and the router automatically discovers and uses it. No xFinance code changes needed.
Install via pip. Requires Python 3.10+. Dependencies: httpx, pandas, pydantic, pybreaker, tenacity.
No API keys needed. All sources are public or free-tier. Users are responsible for complying with each provider's Terms of Service: use yfinance-based data for personal research only; respect rate limits and fair-use guidelines. Full documentation and examples available at xfinance.readthedocs.io.