DataContext¶
DataContext.fetch(...), fetch_many(...), and prefetch(...) are the
canonical public data-loading entry points for new code.
For the shortest happy path, build contexts with DataContext.from_adapters(...)
and load a table with DataContext.load(...).
If multiple adapters serve the same dataset, canonical loads must disambiguate
through default_sources or an explicit source= override. Alphaforge no
longer falls back to an arbitrary first-registered adapter for shared datasets.
DataContext.sources and fetch_panel(...) remain available as
backward-compatibility surfaces for legacy DataSource-backed loaders, but
they are no longer the preferred external loading contract.
alphaforge.data.context
¶
DataContext
dataclass
¶
Runtime wiring for data sources, calendars, and optional PIT access.
Parameters¶
sources : Mapping[str, DataSource]
Legacy data source mapping kept for backward compatibility and
raw-loader workflows.
calendars : Mapping[str, TradingCalendar]
Trading calendar lookup.
store : Store
Backing store for persistence.
adapters : dict[str, SourceAdapter] | None
Canonical public data-loading surface keyed by source_name
(e.g. "cftc").
default_sources : dict[str, str] | None
Maps dataset → default source_name for canonical adapter routing
(e.g. {"cot.tff": "cftc"}).
fetch(query: Query, *, source: Optional[str] = None, max_staleness: Optional[timedelta] = None) -> 'FetchResult'
¶
Canonical fetch path: resolve an adapter and delegate.
fetch_many(queries: list[Query], *, source: Optional[str] = None, max_staleness: Optional[timedelta] = None) -> list['FetchResult']
¶
Canonical batch fetch path, grouped by resolved adapter.
fetch_panel(source: str, q: Query) -> PanelFrame
¶
Legacy panel-building path for DataSource-backed loaders.
from_adapters(*adapters: 'SourceAdapter', calendars: Mapping[str, TradingCalendar] | None = None, store: Store | None = None, universe: Optional[Universe] = None, entity_meta: Optional[EntityMetadata] = None, default_sources: Optional[dict[str, str]] = None) -> 'DataContext'
classmethod
¶
Build a DataContext from adapters without manual mapping boilerplate.
load(dataset: str, *, columns: Sequence[str], start: Optional[pd.Timestamp | str] = None, end: Optional[pd.Timestamp | str] = None, entities: Optional[Sequence[str]] = None, asof: Optional[pd.Timestamp | str] = None, vintage: VintageMode = 'latest', vintage_id: Optional[str] = None, grid: Optional[str] = None, source: Optional[str] = None, max_staleness: Optional[timedelta] = None) -> 'FetchResult'
¶
Happy-path source load without explicit Query construction.
prefetch(dataset: str, *, source: Optional[str] = None, asof_range: tuple[date, date] | None = None) -> 'CacheManifest'
¶
Warm cache for a dataset via the resolved adapter.