StoresΒΆ
stores.baseΒΆ
- class hamilton.caching.stores.base.MetadataStoreΒΆ
- abstract delete(cache_key: str) None ΒΆ
Delete
data_version
keyed bycache_key
.
- abstract delete_all() None ΒΆ
Delete all stored metadata.
- abstract exists(cache_key: str) bool ΒΆ
boolean check if a
data_version
is found forcache_key
If True,.get()
should successfully retrieve thedata_version
.
- abstract get(cache_key: str, **kwargs) str | None ΒΆ
Try to retrieve
data_version
keyed bycache_key
. If retrieval misses returnNone
.
- get_last_run() Any ΒΆ
Return the metadata from the last started run.
- abstract get_run(run_id: str) Sequence[dict] ΒΆ
Return a list of node metadata associated with a run.
For each node, the metadata should include
cache_key
(created or used) anddata_version
. These values allow to manually query the MetadataStore or ResultStore.Decoding the
cache_key
gives thenode_name
,code_version
, anddependencies_data_versions
. Individual implementations may add more information or decode thecache_key
before returning metadata.
- abstract get_run_ids() Sequence[str] ΒΆ
Return a list of run ids, sorted from oldest to newest start time. A
run_id
is registered when the metadata_store.initialize()
is called.
- abstract initialize(run_id: str) None ΒΆ
Setup the metadata store and log the start of the run
- property last_run_id: strΒΆ
Return
- abstract set(cache_key: str, data_version: str, **kwargs) Any | None ΒΆ
Store the mapping
cache_key -> data_version
. Can include other metadata (e.g., node name, run id, code version) depending on the implementation.
- property size: intΒΆ
Number of unique entries (i.e., cache_keys) in the metadata_store
- exception hamilton.caching.stores.base.ResultRetrievalErrorΒΆ
Raised by the SmartCacheAdapter when ResultStore.get() fails.
- class hamilton.caching.stores.base.ResultStoreΒΆ
- abstract delete(data_version: str) None ΒΆ
Delete
result
keyed bydata_version
.
- abstract delete_all() None ΒΆ
Delete all stored results.
- abstract exists(data_version: str) bool ΒΆ
boolean check if a
result
is found fordata_version
If True,.get()
should successfully retrieve theresult
.
- abstract get(data_version: str, **kwargs) Any | None ΒΆ
Try to retrieve
result
keyed bydata_version
. If retrieval misses, returnNone
.
- abstract set(data_version: str, result: Any, **kwargs) None ΒΆ
Store
result
keyed bydata_version
.
- hamilton.caching.stores.base.search_data_adapter_registry(name: str, type_: type) Tuple[Type[DataSaver], Type[DataLoader]] ΒΆ
Find pair of DataSaver and DataLoader registered with name and supporting type_
stores.fileΒΆ
- class hamilton.caching.stores.file.FileResultStore(path: str, create_dir: bool = True)ΒΆ
- delete(data_version: str) None ΒΆ
Delete
result
keyed bydata_version
.
- delete_all() None ΒΆ
Delete all stored results.
- exists(data_version: str) bool ΒΆ
boolean check if a
result
is found fordata_version
If True,.get()
should successfully retrieve theresult
.
- get(data_version: str) Any | None ΒΆ
Try to retrieve
result
keyed bydata_version
. If retrieval misses, returnNone
.
- set(data_version: str, result: Any, saver_cls: DataSaver | None = None, loader_cls: DataLoader | None = None) None ΒΆ
Store
result
keyed bydata_version
.
stores.sqliteΒΆ
- class hamilton.caching.stores.sqlite.SQLiteMetadataStore(path: str, connection_kwargs: dict | None = None)ΒΆ
- property connection: ConnectionΒΆ
Connection to the SQLite database.
- delete(cache_key: str) None ΒΆ
Delete metadata associated with
cache_key
.
- delete_all() None ΒΆ
Delete all existing tables from the database
- exists(cache_key: str) bool ΒΆ
boolean check if a
data_version
is found forcache_key
If True,.get()
should successfully retrieve thedata_version
.
- get(cache_key: str) str | None ΒΆ
Try to retrieve
data_version
keyed bycache_key
. If retrieval misses returnNone
.
- get_run(run_id: str) List[dict] ΒΆ
Return a list of node metadata associated with a run.
- Parameters:
run_id β ID of the run to retrieve
- Returns:
List of node metadata which includes
cache_key
,data_version
,node_name
, andcode_version
. The list can be empty if a run was initialized but no nodes were executed.- Raises:
IndexError β if the
run_id
is not found in metadata store.
- get_run_ids() List[str] ΒΆ
Return a list of run ids, sorted from oldest to newest start time.
- initialize(run_id) None ΒΆ
Call initialize when starting a run. This will create database tables if necessary.
- set(*, cache_key: str, data_version: str, run_id: str, node_name: str = None, code_version: str = None, **kwargs) None ΒΆ
Store the mapping
cache_key -> data_version
. Can include other metadata (e.g., node name, run id, code version) depending on the implementation.
stores.memoryΒΆ
- class hamilton.caching.stores.memory.InMemoryMetadataStoreΒΆ
- delete(cache_key: str) None ΒΆ
Delete the
data_version
forcache_key
.
- delete_all() None ΒΆ
Delete all stored metadata.
- exists(cache_key: str) bool ΒΆ
Indicate if
cache_key
exists and it can retrieve adata_version
.
- get(cache_key: str) str | None ΒΆ
Retrieve the
data_version
forcache_key
.
- get_run(run_id: str) List[Dict[str, str]] ΒΆ
Return a list of node metadata associated with a run.
- get_run_ids() List[str] ΒΆ
Return a list of all
run_id
values stored.
- initialize(run_id: str) None ΒΆ
Set up and log the beginning of the run.
- classmethod load_from(metadata_store: MetadataStore) InMemoryMetadataStore ΒΆ
Load in-memory metadata from another MetadataStore instance.
- Parameters:
metadata_store β MetadataStore instance to load from.
- Returns:
InMemoryMetadataStore copy of the
metadata_store
.
from hamilton import driver from hamilton.caching.stores.sqlite import SQLiteMetadataStore from hamilton.caching.stores.memory import InMemoryMetadataStore import my_dataflow sqlite_metadata_store = SQLiteMetadataStore(path="./.hamilton_cache") in_memory_metadata_store = InMemoryMetadataStore.load_from(sqlite_metadata_store) # create the Driver with the in-memory metadata store dr = ( driver.Builder() .with_modules(my_dataflow) .with_cache(metadata_store=in_memory_metadata_store) .build() )
- persist_to(metadata_store: MetadataStore | None = None) None ΒΆ
Persist in-memory metadata using another MetadataStore implementation.
- Parameters:
metadata_store β MetadataStore implementation to use for persistence. If None, a SQLiteMetadataStore is created with the default path β./.hamilton_cacheβ.
from hamilton import driver from hamilton.caching.stores.sqlite import SQLiteMetadataStore from hamilton.caching.stores.memory import InMemoryMetadataStore import my_dataflow dr = ( driver.Builder() .with_modules(my_dataflow) .with_cache(metadata_store=InMemoryMetadataStore()) .build() ) # execute the Driver several time. This will populate the in-memory metadata store dr.execute(...) # persist to disk in-memory metadata dr.cache.metadata_store.persist_to(SQLiteMetadataStore(path="./.hamilton_cache"))
- set(cache_key: str, data_version: str, run_id: str, **kwargs) Any | None ΒΆ
Set the
data_version
forcache_key
and associate it with therun_id
.
- class hamilton.caching.stores.memory.InMemoryResultStore(persist_on_exit: bool = False)ΒΆ
- delete(data_version: str) None ΒΆ
Delete
result
keyed bydata_version
.
- delete_all() None ΒΆ
Delete all stored results.
- exists(data_version: str) bool ΒΆ
boolean check if a
result
is found fordata_version
If True,.get()
should successfully retrieve theresult
.
- get(data_version: str) Any | None ΒΆ
Try to retrieve
result
keyed bydata_version
. If retrieval misses, returnNone
.
- classmethod load_from(result_store: ResultStore, metadata_store: MetadataStore | None = None, data_versions: Sequence[str] | None = None) InMemoryResultStore ΒΆ
Load in-memory results from another ResultStore instance.
Since result stores do not store an index of their keys, you must provide a
MetadataStore
instance or a list ofdata_version
for which results should be loaded in memory.- Parameters:
result_store β
ResultStore
instance to load results from.metadata_store β
MetadataStore
instance from which alldata_version
are retrieved.
- Returns:
InMemoryResultStore copy of the
result_store
.
from hamilton import driver from hamilton.caching.stores.sqlite import SQLiteMetadataStore from hamilton.caching.stores.memory import InMemoryMetadataStore import my_dataflow sqlite_metadata_store = SQLiteMetadataStore(path="./.hamilton_cache") in_memory_metadata_store = InMemoryMetadataStore.load_from(sqlite_metadata_store) # create the Driver with the in-memory metadata store dr = ( driver.Builder() .with_modules(my_dataflow) .with_cache(metadata_store=in_memory_metadata_store) .build() )
- persist_to(result_store: ResultStore | None = None) None ΒΆ
Persist in-memory results using another
ResultStore
implementation.- Parameters:
result_store β ResultStore implementation to use for persistence. If None, a FileResultStore is created with the default path β./.hamilton_cacheβ.
- set(data_version: str, result: Any, **kwargs) None ΒΆ
Store
result
keyed bydata_version
.