proxystore.store.base¶
Store implementation.
ConnectorT
module-attribute
¶
Connector type variable.
StoreFactory ¶
StoreFactory(
key: ConnectorKeyT,
store_config: dict[str, Any],
*,
evict: bool = False,
deserializer: DeserializerT | None = None,
metrics: bool = False
) -> None
Bases: Generic[ConnectorT, T]
Factory that resolves an object from a store.
Adds support for asynchronously retrieving objects from a
Store
instance.
The factory takes the store_config
parameter that is
used to reinitialize the store if the factory is sent to a remote
process where the store has not already been initialized.
Parameters:
-
key
(
ConnectorKeyT
) –Key corresponding to object in store.
-
store_config
(
dict[str, Any]
) –Store configuration used to reinitialize the store if needed.
-
evict
(
bool
) –If True, evict the object from the store once
resolve()
is called. -
deserializer
(
DeserializerT | None
) –Optional callable used to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
metrics
(
bool
) –Enable recording operation metrics.
Source code in proxystore/store/base.py
get_store() ¶
Get store and reinitialize if necessary.
Raises:
-
ValueError
–If the type of the returned store does not match the expected store type passed to the factory constructor.
Source code in proxystore/store/base.py
resolve() ¶
Get object associated with key from store.
Raises:
-
ProxyResolveMissingKeyError
–If the key associated with this factory does not exist in the store.
Source code in proxystore/store/base.py
resolve_async() ¶
Asynchronously get object associated with key from store.
Store ¶
Store(
name: str,
connector: ConnectorT,
*,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
cache_size: int = 16,
metrics: bool = False
) -> None
Bases: Generic[ConnectorT]
Key-value store interface for proxies.
Tip
A Store
instance can be used as a
context manager which will automatically call
close()
on exit.
Parameters:
-
name
(
str
) –Name of the store instance.
-
connector
(
ConnectorT
) –Connector instance to use for object storage.
-
serializer
(
SerializerT | None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used. -
deserializer
(
DeserializerT | None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
cache_size
(
int
) –Size of LRU cache (in # of objects). If 0, the cache is disabled. The cache is local to the Python process.
-
metrics
(
bool
) –Enable recording operation metrics.
Raises:
-
ValueError
–If
cache_size
is less than zero.
Source code in proxystore/store/base.py
close() ¶
Close the connector associated with the store.
Warning
This method should only be called at the end of the program when the store will no longer be used, for example once all proxies have been resolved.
Source code in proxystore/store/base.py
config() ¶
Get the store configuration.
Returns:
Source code in proxystore/store/base.py
from_config()
classmethod
¶
Create a new store instance from a configuration.
Parameters:
Returns:
Source code in proxystore/store/base.py
evict() ¶
Evict the object associated with the key.
Parameters:
-
key
(
ConnectorKeyT
) –Key associated with object to evict.
Source code in proxystore/store/base.py
exists() ¶
Check if an object associated with the key exists.
Parameters:
-
key
(
ConnectorKeyT
) –Key potentially associated with stored object.
Returns:
-
bool
–If an object associated with the key exists.
Source code in proxystore/store/base.py
get() ¶
get(
key: ConnectorKeyT,
*,
deserializer: DeserializerT | None = None,
default: object | None = None
) -> Any | None
Get the object associated with the key.
Parameters:
-
key
(
ConnectorKeyT
) –Key associated with the object to retrieve.
-
deserializer
(
DeserializerT | None
) –Optionally override the default deserializer for the store instance.
-
default
(
object | None
) –An optional value to be returned if an object associated with the key does not exist.
Returns:
-
Any | None
–Object or
None
if the object does not exist.
Source code in proxystore/store/base.py
is_cached() ¶
Check if an object associated with the key is cached locally.
Parameters:
-
key
(
ConnectorKeyT
) –Key potentially associated with stored object.
Returns:
-
bool
–If the object is cached.
Source code in proxystore/store/base.py
proxy() ¶
proxy(
obj: T,
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> Proxy[T]
Create a proxy that will resolve to an object in the store.
Parameters:
-
obj
(
T
) –The object to place in store and return a proxy for.
-
evict
(
bool
) –If the proxy should evict the object once resolved.
-
serializer
(
SerializerT | None
) –Optionally override the default serializer for the store instance.
-
deserializer
(
DeserializerT | None
) –Optionally override the default deserializer for the store instance.
-
kwargs
(
Any
) –Additional keyword arguments to pass to
Connector.put()
.
Returns:
-
Proxy[T]
–A proxy of the object.
Source code in proxystore/store/base.py
proxy_batch() ¶
proxy_batch(
objs: Sequence[T],
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> list[Proxy[T]]
Create proxies that will resolve to an object in the store.
Parameters:
-
objs
(
Sequence[T]
) –The objects to place in store and return a proxies for.
-
evict
(
bool
) –If a proxy should evict its object once resolved.
-
serializer
(
SerializerT | None
) –Optionally override the default serializer for the store instance.
-
deserializer
(
DeserializerT | None
) –Optionally override the default deserializer for the store instance.
-
kwargs
(
Any
) –Additional keyword arguments to pass to
Connector.put_batch()
.
Returns:
Source code in proxystore/store/base.py
proxy_from_key() ¶
proxy_from_key(
key: ConnectorKeyT,
*,
evict: bool = False,
deserializer: DeserializerT | None = None
) -> Proxy[T]
Create a proxy that will resolve to an object already in the store.
Parameters:
-
key
(
ConnectorKeyT
) –The key associated with an object already in the store.
-
evict
(
bool
) –If the proxy should evict the object once resolved.
-
deserializer
(
DeserializerT | None
) –Optionally override the default deserializer for the store instance.
Returns:
-
Proxy[T]
–A proxy of the object.
Source code in proxystore/store/base.py
locked_proxy() ¶
locked_proxy(
obj: T,
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
**kwargs: Any
) -> ProxyLocker[T]
Proxy an object and return ProxyLocker
.
Parameters:
-
obj
(
T
) –The object to place in store and return a proxy for.
-
evict
(
bool
) –If the proxy should evict the object once resolved.
-
serializer
(
SerializerT | None
) –Optionally override the default serializer for the store instance.
-
deserializer
(
DeserializerT | None
) –Optionally override the default deserializer for the store instance.
-
kwargs
(
Any
) –Additional keyword arguments to pass to
Connector.put()
.
Returns:
-
ProxyLocker[T]
–A proxy wrapped in a
ProxyLocker
.
Source code in proxystore/store/base.py
put() ¶
Put an object in the store.
Parameters:
-
obj
(
Any
) –Object to put in the store.
-
serializer
(
SerializerT | None
) –Optionally override the default serializer for the store instance.
-
kwargs
(
Any
) –Additional keyword arguments to pass to
Connector.put()
.
Returns:
-
ConnectorKeyT
–A key which can be used to retrieve the object.
Raises:
-
TypeError
–If the output of
serializer
is not bytes.
Source code in proxystore/store/base.py
put_batch() ¶
put_batch(
objs: Sequence[Any],
*,
serializer: SerializerT | None = None,
**kwargs: Any
) -> list[ConnectorKeyT]
Put multiple objects in the store.
Parameters:
-
objs
(
Sequence[Any]
) –Sequence of objects to put in the store.
-
serializer
(
SerializerT | None
) –Optionally override the default serializer for the store instance.
-
kwargs
(
Any
) –Additional keyword arguments to pass to
Connector.put_batch()
.
Returns:
-
list[ConnectorKeyT]
–A list of keys which can be used to retrieve the objects.
Raises:
-
TypeError
–If the output of
serializer
is not bytes.