StoresΒΆ
stores.baseΒΆ
- class hamilton.caching.stores.base.MetadataStoreΒΆ
- abstractmethod delete(cache_key: str) NoneΒΆ
Delete
data_versionkeyed bycache_key.
- abstractmethod delete_all() NoneΒΆ
Delete all stored metadata.
- abstractmethod exists(cache_key: str) boolΒΆ
boolean check if a
data_versionis found forcache_keyIf True,.get()should successfully retrieve thedata_version.
- abstractmethod get(cache_key: str, **kwargs) str | NoneΒΆ
Try to retrieve
data_versionkeyed bycache_key. If retrieval misses returnNone.
- get_last_run() AnyΒΆ
Return the metadata from the last started run.
- abstractmethod 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_keygives thenode_name,code_version, anddependencies_data_versions. Individual implementations may add more information or decode thecache_keybefore returning metadata.
- abstractmethod get_run_ids() Sequence[str]ΒΆ
Return a list of run ids, sorted from oldest to newest start time. A
run_idis registered when the metadata_store.initialize()is called.
- abstractmethod initialize(run_id: str) NoneΒΆ
Setup the metadata store and log the start of the run
- property last_run_id: strΒΆ
Return
- abstractmethod 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ΒΆ
- abstractmethod delete(data_version: str) NoneΒΆ
Delete
resultkeyed bydata_version.
- abstractmethod delete_all() NoneΒΆ
Delete all stored results.
- abstractmethod exists(data_version: str) boolΒΆ
boolean check if a
resultis found fordata_versionIf True,.get()should successfully retrieve theresult.
- abstractmethod get(data_version: str, **kwargs) Any | NoneΒΆ
Try to retrieve
resultkeyed bydata_version. If retrieval misses, returnNone.
- abstractmethod set(data_version: str, result: Any, **kwargs) NoneΒΆ
Store
resultkeyed 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
resultkeyed bydata_version.
- delete_all() NoneΒΆ
Delete all stored results.
- exists(data_version: str) boolΒΆ
boolean check if a
resultis found fordata_versionIf True,.get()should successfully retrieve theresult.
- get(data_version: str) Any | NoneΒΆ
Try to retrieve
resultkeyed bydata_version. If retrieval misses, returnNone.
- set(data_version: str, result: Any, saver_cls: DataSaver | None = None, loader_cls: DataLoader | None = None) NoneΒΆ
Store
resultkeyed 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_versionis found forcache_keyIf True,.get()should successfully retrieve thedata_version.
- get(cache_key: str) str | NoneΒΆ
Try to retrieve
data_versionkeyed 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_idis 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_versionforcache_key.
- delete_all() NoneΒΆ
Delete all stored metadata.
- exists(cache_key: str) boolΒΆ
Indicate if
cache_keyexists and it can retrieve adata_version.
- get(cache_key: str) str | NoneΒΆ
Retrieve the
data_versionforcache_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_idvalues 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_versionforcache_keyand associate it with therun_id.
- class hamilton.caching.stores.memory.InMemoryResultStore(persist_on_exit: bool = False)ΒΆ
- delete(data_version: str) NoneΒΆ
Delete
resultkeyed bydata_version.
- delete_all() NoneΒΆ
Delete all stored results.
- exists(data_version: str) boolΒΆ
boolean check if a
resultis found fordata_versionIf True,.get()should successfully retrieve theresult.
- get(data_version: str) Any | NoneΒΆ
Try to retrieve
resultkeyed 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
MetadataStoreinstance or a list ofdata_versionfor which results should be loaded in memory.- Parameters:
result_store β
ResultStoreinstance to load results from.metadata_store β
MetadataStoreinstance from which alldata_versionare 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
ResultStoreimplementation.- 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
resultkeyed bydata_version.