fleche.config
Configuration system for fleche.
Example cache.toml:
[default] cache = “mycache” metadata = [“Runtime”, “CallInfo”]
[mycache] values.type = “Memory” calls.type = “Memory”
[transient] values.type = “CloudpickleFile” values.root = “.fleche/values” calls.type = “CloudpickleFile” calls.root = “.fleche/calls”
[global] values.type = “BagOfHoldingH5File” values.root = “~/.fleche/values” calls.type = “CloudpickleFile” calls.root = “~/.fleche/calls”
Attributes
Functions
|
|
|
|
Load the default metadata from the configuration file. |
|
|
Construct a |
|
Deprecated: use |
|
Convert a Storage or CallStorage instance to a config dict. |
|
Construct a |
|
Convert a |
|
|
|
Load a cache from the configuration file. |
Module Contents
- fleche.config._live_caches: dict[str, fleche.caches.Cache][source]
- fleche.config.load_default_metadata()[source]
Load the default metadata from the configuration file.
- fleche.config.storage_from_config(d: dict[str, Any]) fleche.storage.Storage[source]
Construct a
Storagefrom a config dict.The dict must contain a
"type"key (case-sensitive) and any additional parameters required by that storage backend. The input dict is not mutated.Supported types:
"Memory","Void","DestructuringStorage","PickleFile","CloudpickleFile","DillFile","BagOfHoldingH5File","Sql".
- fleche.config._get_storage(config: dict[str, Any]) fleche.storage.Storage[source]
Deprecated: use
storage_from_config()instead.
- fleche.config.storage_to_config(s: fleche.storage.Storage | fleche.storage.CallStorage) dict[str, Any][source]
Convert a Storage or CallStorage instance to a config dict.
The returned dict contains a
"type"key and any additional parameters needed to reconstruct the storage viastorage_from_config().DestructuringStorageis handled as a first-class case, producing a nested"storage"entry for its inner backend.Accepts both
Storageand bareCallStorageinstances (e.g.Sql), sinceSqlimplementsCallStoragedirectly without going throughCallStorageAdapter.
- fleche.config.cache_from_config(d: dict[str, Any] | list[dict[str, Any]]) fleche.caches.BaseCache[source]
Construct a
BaseCachefrom a config dict or list.The cache type is determined implicitly from the shape of the input:
A list of dicts is treated as a
CacheStack, with each element processed recursively.A dict containing a
max_sizekey creates aSizeLimitedCache.A dict containing
read_only: truewraps the resulting cache in aReadOnlyCache.Otherwise a plain
Cacheis created.
The
valuesstorage is always wrapped in aDestructuringStorageif it is not already one. The input dict is not mutated.Examples:
# Plain cache with in-memory storage cache_from_config({ "values": {"type": "Memory"}, "calls": {"type": "Memory"}, }) # Size-limited cache — presence of max_size selects SizeLimitedCache cache_from_config({ "values": {"type": "Memory"}, "calls": {"type": "Memory"}, "max_size": 100, }) # Read-only cache — read_only: true wraps the cache in ReadOnlyCache cache_from_config({ "values": {"type": "Memory"}, "calls": {"type": "Memory"}, "read_only": True, }) # CacheStack — a list of dicts is implicitly treated as a stack cache_from_config([ {"values": {"type": "Memory"}, "calls": {"type": "Memory"}}, {"values": {"type": "Void"}, "calls": {"type": "Void"}}, ])
- fleche.config.cache_to_config(c: fleche.caches.BaseCache) dict[str, Any] | list[dict[str, Any]][source]
Convert a
BaseCacheto a config dict or list.This is the inverse of
cache_from_config(). The output can be round-tripped back viacache_from_config(cache_to_config(cache)).Cache→ dict with"values"and"calls"SizeLimitedCache→ same dict plus"max_size"ReadOnlyCachewrapping aCacheorSizeLimitedCache→ inner cache dict with"read_only": TrueCacheStack→ list of dicts
valuesis serialised as-is (aDestructuringStoragewrapper is preserved in the output).callsunwraps theCallStorageAdapter.- Raises:
ValueError – for unsupported cache types or unsupported
ReadOnlyCacheinner types.
- fleche.config._create_cache(cache_config: dict[str, Any]) fleche.caches.Cache[source]
- fleche.config.load_cache_config(name: str | None = None) fleche.caches.Cache[source]
Load a cache from the configuration file.
If name is None, the default cache is loaded. The names ‘memory’ and ‘void’ are special-cased to return a transient in-memory cache and a no-op cache respectively.
Note: The Tags metadata cannot be configured from the config file.