fleche.storage
Storage subpackage public API.
This module re-exports the primary storage interfaces and implementations for backward compatibility with from fleche.storage import … imports.
Submodules
Exceptions
Common base class for all non-exit exceptions. |
|
Inappropriate argument value (of correct type). |
Classes
Abstract base class for defining storage mechanisms. |
|
Special storage for saving |
|
Implement a CallStorage from a generic Storage. |
|
Abstract base class for defining storage mechanisms. |
|
A concrete implementation of Storage that stores values in an in-memory dictionary. |
|
A concrete implementation of Storage that does not store anything. |
|
File-based storage backend using pickle. |
|
Store values as files on the filesystem using a serialization module. |
|
File-based storage backend using pickle. |
|
SQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand(). |
Package Contents
- exception fleche.storage.SaveError[source]
Bases:
ExceptionCommon base class for all non-exit exceptions.
- exception fleche.storage.AmbiguousDigestError[source]
Bases:
ValueErrorInappropriate argument value (of correct type).
- class fleche.storage.Storage[source]
Bases:
StorageBaseAbstract base class for defining storage mechanisms.
- save(value: Any, key: fleche.digest.Digest | None = None) fleche.digest.Digest[source]
- abstractmethod _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- load(key: fleche.digest.Digest | str) Any[source]
- abstractmethod _load(key: fleche.digest.Digest) Any[source]
- _contains(key: fleche.digest.Digest) bool[source]
- class fleche.storage.CallStorage[source]
Bases:
StorageBaseSpecial storage for saving
Callinstances.- save(call: fleche.call.Call) fleche.digest.Digest[source]
- abstractmethod _save(call: fleche.call.Call) fleche.digest.Digest[source]
- load(key: str) fleche.call.Call[source]
- abstractmethod _load(key: fleche.digest.Digest) fleche.call.Call[source]
- transform(func: Callable[[fleche.call.Call], fleche.call.Call] | None = None) None[source]
Applies a transformation function to all Call objects in the storage.
- query(template: fleche.call.Call) Iterable[fleche.call.Call][source]
Find cached calls that ‘match’ the template.
Returns all calls where the given arguments, results or metadata match exactly the stored ones. Values may be given either as they are or as
Digest.
- _contains(key: fleche.digest.Digest) bool[source]
- class fleche.storage.CallStorageAdapter[source]
Bases:
CallStorageImplement a CallStorage from a generic Storage.
- _save(call: fleche.call.Call) fleche.digest.Digest[source]
- _load(key: fleche.digest.Digest) fleche.call.Call[source]
- _contains(key: fleche.digest.Digest) bool[source]
- _evict(key: fleche.digest.Digest) None[source]
- list() Iterable[fleche.digest.Digest][source]
- class fleche.storage.DestructuringStorage[source]
Bases:
StorageAbstract base class for defining storage mechanisms.
- _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- _load(key: fleche.digest.Digest) Any[source]
- _contains(key: fleche.digest.Digest) bool[source]
- _evict(key: fleche.digest.Digest) None[source]
- list() Iterable[fleche.digest.Digest][source]
- class fleche.storage.Memory[source]
Bases:
fleche.storage.base.StorageA concrete implementation of Storage that stores values in an in-memory dictionary.
- storage: dict[fleche.digest.Digest, Any]
- _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- _load(key: fleche.digest.Digest) Any[source]
- _contains(key: fleche.digest.Digest) bool[source]
- list() Iterable[fleche.digest.Digest][source]
- _evict(key: fleche.digest.Digest) None[source]
- class fleche.storage.Void[source]
Bases:
fleche.storage.base.StorageA concrete implementation of Storage that does not store anything.
- _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- _load(key: fleche.digest.Digest) Any[source]
- list() Iterable[fleche.digest.Digest][source]
- _evict(key: fleche.digest.Digest) None[source]
- _contains(key: fleche.digest.Digest) bool[source]
- class fleche.storage.FileStorage[source]
Bases:
fleche.storage.base.StorageFile-based storage backend using pickle.
Stores objects on the filesystem.
- root: pathlib.Path
- lock_timeout: float = 1.0
- lock_wait_start: float = 0.001
- list() Iterable[fleche.digest.Digest][source]
- _evict(key: fleche.digest.Digest) None[source]
- save(value: Any, key: fleche.digest.Digest | None = None) fleche.digest.Digest[source]
- load(key: fleche.digest.Digest | str) Any[source]
- _contains(key: fleche.digest.Digest) bool[source]
- class fleche.storage.PickleFile[source]
Bases:
fleche.storage.file.FileStorageStore values as files on the filesystem using a serialization module.
- secret_key: list[bytes] = []
- serializer: Any
- compress: bool = False
- classmethod with_pickle(*args, **kwargs)[source]
Construct a PickleFile using the standard pickle module.
- classmethod with_cloudpickle(*args, **kwargs)[source]
Construct a PickleFile using the cloudpickle module.
- _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- _load(key: fleche.digest.Digest) Any[source]
- class fleche.storage.BagOfHoldingH5File[source]
Bases:
fleche.storage.file.FileStorageFile-based storage backend using pickle.
Stores objects on the filesystem.
- _save(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- class fleche.storage.Sql[source]
Bases:
fleche.storage.base.CallStorageSQLAlchemy-backed CallStorage with JSON metadata and DB-backed expand().
- url: str | None = None
- echo: bool = False
- engine: Any
- session: Any
- _save(call: fleche.call.Call) fleche.digest.Digest[source]
- _load(key: str) fleche.call.Call[source]
- _contains(key: fleche.digest.Digest) bool[source]
- list() Iterable[fleche.digest.Digest][source]
- expand(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Expands a short-hand digest to the full length one.
- _normalize_value(v: Any) str[source]
Return the stored form used in SQL for argument/result matching.
We must match the generic CallStorage.query semantics which compare digest(template_value) == digest(stored_call_value). In this backend, stored argument/result values are hex-digest strings, and digest(Digest(x)) == x. Therefore we should always compare Arg.value/CallModel.result to str(digest(template_value)).
- _build_call_conditions(template: fleche.call.Call) List[Any][source]
- query(template: fleche.call.Call) Iterable[fleche.call.Call][source]
Find cached calls matching a template using SQL-side filtering.
Semantics match CallStorage.query: - Fields set to None are wildcards. - Arguments and result are compared by digest(template_value) == digest(stored_value). - Metadata can be filtered by providing template.metadata as a mapping of
metadata name -> dict of key/value filters. An empty dict for a given name means “presence of that metadata name”. Filters with simple types (str, bool, int, float) are pushed down to SQL via JSON-extract expressions; other types (e.g., lists) or None values fall back to client-side checks after loading.
This method builds a SELECT over calls, joining the arguments table and metadata table as needed to reduce candidate rows, then loads the resulting calls and performs any remaining client-side validation.
- Parameters:
template – A Call used as a template. None-valued fields are wildcards.
- Yields:
Call – Matching calls including their decoded metadata.