Feature: Add Multi-Ticker Info Retrieval API#2886
Conversation
- Add yfinance.multi.info() for parallel info fetching across multiple tickers - Add Tickers.info property and Tickers.get_info() method - Implement best-effort semantics with per-ticker error handling - Lock network fetch outside critical section for true parallel execution - Add comprehensive test coverage for threading and partial failures - Update reference docs with multi-ticker info usage examples
|
Many fetches of Some of the metadatas you listed are in |
Good to know. Would you like me to close this out then? |
|
I'm not decided because the code is fine. Are you willing to generalise it to more attributes e.g. calendar? So basically:
|
Don't accept it just because I've writing a few lines of halfway decent code! It only took a few hours to put together. Aside from the persistent caching offered through the cached version of the library, in-memory LRU caches on the Setting
Can do. Each attr would probably need its own Let me know if you'd like me to action anything in particular. Happy to burn a few more hours on this. |
Add Multi-Ticker Info Retrieval API
Summary
This PR adds the ability to download company info for multiple tickers in parallel, mirroring the ergonomics of
yf.download()for historical data. Users can now callyf.Tickers(["AAPL", "MSFT, "NVDA"]).infoto fetch info for all symbols concurrently. This enables the rapid collection of important metadata about the instruments (for example, quote currencies, exhanges).Motivation
Previously, retrieving info for multiple tickers required either:
.infoon individualTickerobjects (slow, serialized)yf.download()for historical data (different API, different return type)With this PR, metadata retrieval now works like historical downloads: specify multiple tickers, then efficiently retrieve metadata batch. With this implementation, metadata retrieval becomes faster by many orders of magnitude.
Changes
Core Implementation
yfinance/multi.py_InfoCtxcontext class for per-call thread-safe state (mirrors_DownloadCtx)info(tickers, threads=True, progress=False, session=None)function_info_impl()internal orchestrator with threaded worker support_info_one_threaded()and_info_one()worker functionsyfinance/tickers.pyTickers.infopropertyTickers.get_info(threads=True, progress=False)methoddict[symbol] -> dictkeyed by tickerTesting
tests/test_multi.pyTestInfoThreadSafety.test_multi_info_best_effort_partial_failure(): Validates one failing ticker doesn't block othersTestInfoThreadSafety.test_concurrent_multi_info_calls_keep_results_separate(): Ensures concurrent multi-info calls don't leak stateTestInfoThreadSafety.test_multi_info_threads_do_not_serialize_fetches(): Asserts threaded execution is truly paralleltests/test_ticker.pyTestTickersInfo.test_get_info_delegates_to_multi(): Validates Tickers.get_info() wiringTestTickersInfo.test_info_property_uses_get_info(): Validates info property delegationDocumentation
doc/source/reference/examples/tickers.py: Added short usage example showingtickers.infomulti-fetchdoc/source/reference/yfinance.ticker_tickers.rst: Added concise reference note onTickers.info/Tickers.get_info()return typeUsage