proxystore.store¶
The ProxyStore Store
interface.
Store ¶
Store(
name: str,
connector: ConnectorT,
*,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
cache_size: int = 16,
metrics: bool = False
)
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
, default:None
) –Optional callable which serializes the object. If
None
, the default serializer (serialize()
) will be used. -
deserializer
(DeserializerT | None
, default:None
) –Optional callable used by the factory to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used. -
cache_size
(int
, default:16
) –Size of LRU cache (in # of objects). If 0, the cache is disabled. The cache is local to the Python process.
-
metrics
(bool
, default:False
) –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.
Parameters:
-
args
(Any
, default:()
) –Positional arguments to pass to
Connector.close()
. -
kwargs
(Any
, default:{}
) –Keyword arguments to pass to
Connector.close()
.
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
future() ¶
future(
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
polling_interval: float = 1,
polling_timeout: float | None = None
) -> ProxyFuture[T]
Create a future to an object.
Example
from proxystore.connectors.file import FileConnector
from proxystore.store import Store
from proxystore.store.future import ProxyFuture
def remote_foo(future: ProxyFuture) -> None:
# Computation that generates a result value needed by
# the remote_bar function.
future.set_result(...)
def remote_bar(data: Any) -> None:
# Function uses data, which is a proxy, as normal, blocking
# until the remote_foo function has called set_result.
...
with Store('future-example', FileConnector(...)) as store:
future = store.future()
# The invoke_remove function invokes a provided function
# on a remote process. For example, this could be a serverless
# function execution.
foo_result_future = invoke_remote(remote_foo, future)
bar_result_future = invoke_remote(remote_bar, future.proxy())
foo_result_future.result()
bar_result_future.result()
Warning
This method only works if the connector
is of type
DeferrableConnector
.
Warning
This method and the
ProxyFuture.proxy()
are experimental features and may change in future releases.
Parameters:
-
evict
(bool
, default:False
) –If a proxy returned by
ProxyFuture.proxy()
should evict the object once resolved. -
serializer
(SerializerT | None
, default:None
) –Optionally override the default serializer for the store instance.
-
deserializer
(DeserializerT | None
, default:None
) –Optionally override the default deserializer for the store instance.
-
polling_interval
(float
, default:1
) –Seconds to sleep between polling the store for the object when getting the result of the future.
-
polling_timeout
(float | None
, default:None
) –Optional maximum number of seconds to poll for when getting the result of the future.
Returns:
-
ProxyFuture[T]
–Future which can be used to get the result object at a later time or create a proxy which will resolve to the result of the future.
Raises:
-
NotImplementedError
–If the
connector
is not of typeDeferrableConnector
.
Source code in proxystore/store/base.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
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
, default:None
) –Optionally override the default deserializer for the store instance.
-
default
(object | None
, default: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 | NonProxiableT,
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
skip_nonproxiable: bool = False,
**kwargs: Any
) -> Proxy[T] | NonProxiableT
Create a proxy that will resolve to an object in the store.
Parameters:
-
obj
(T | NonProxiableT
) –The object to place in store and return a proxy for.
-
evict
(bool
, default:False
) –If the proxy should evict the object once resolved.
-
serializer
(SerializerT | None
, default:None
) –Optionally override the default serializer for the store instance.
-
deserializer
(DeserializerT | None
, default:None
) –Optionally override the default deserializer for the store instance.
-
skip_nonproxiable
(bool
, default:False
) –Return non-proxiable types (e.g., built-in constants like
bool
orNone
) rather than raising aNonProxiableTypeError
. -
kwargs
(Any
, default:{}
) –Additional keyword arguments to pass to
Connector.put()
.
Returns:
-
Proxy[T] | NonProxiableT
–A proxy of the object unless
obj
is a non-proxiable typeskip_nonproxiable is True
in which caseobj
is returned directly.
Raises:
-
NonProxiableTypeError
–If
obj
is a non-proxiable type. This behavior can be overridden by settingskip_nonproxiable=True
.
Source code in proxystore/store/base.py
proxy_batch() ¶
proxy_batch(
objs: Sequence[T | NonProxiableT],
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
skip_nonproxiable: bool = False,
**kwargs: Any
) -> list[Proxy[T] | NonProxiableT]
Create proxies that will resolve to an object in the store.
Parameters:
-
objs
(Sequence[T | NonProxiableT]
) –The objects to place in store and return a proxies for.
-
evict
(bool
, default:False
) –If a proxy should evict its object once resolved.
-
serializer
(SerializerT | None
, default:None
) –Optionally override the default serializer for the store instance.
-
deserializer
(DeserializerT | None
, default:None
) –Optionally override the default deserializer for the store instance.
-
skip_nonproxiable
(bool
, default:False
) –Return non-proxiable types (e.g., built-in constants like
bool
orNone
) rather than raising aNonProxiableTypeError
. -
kwargs
(Any
, default:{}
) –Additional keyword arguments to pass to
Connector.put_batch()
.
Returns:
-
list[Proxy[T] | NonProxiableT]
–A list of proxies of each object or the object itself if said object is not proxiable and
skip_nonproxiable is True
.
Raises:
-
NonProxiableTypeError
–If
obj
is a non-proxiable type. This behavior can be overridden by settingskip_nonproxiable=True
.
Source code in proxystore/store/base.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
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
, default:False
) –If the proxy should evict the object once resolved.
-
deserializer
(DeserializerT | None
, default: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 | NonProxiableT,
*,
evict: bool = False,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
skip_nonproxiable: bool = True,
**kwargs: Any
) -> ProxyLocker[T] | NonProxiableT
Proxy an object and return ProxyLocker
.
Parameters:
-
obj
(T | NonProxiableT
) –The object to place in store and return a proxy for.
-
evict
(bool
, default:False
) –If the proxy should evict the object once resolved.
-
serializer
(SerializerT | None
, default:None
) –Optionally override the default serializer for the store instance.
-
deserializer
(DeserializerT | None
, default:None
) –Optionally override the default deserializer for the store instance.
-
skip_nonproxiable
(bool
, default:True
) –Return non-proxiable types (e.g., built-in constants like
bool
orNone
) rather than raising aNonProxiableTypeError
. -
kwargs
(Any
, default:{}
) –Additional keyword arguments to pass to
Connector.put()
.
Returns:
-
ProxyLocker[T] | NonProxiableT
–A proxy wrapped in a
ProxyLocker
unlessobj
is a non-proxiable typeskip_nonproxiable is True
in which caseobj
is returned directly.
Raises:
-
NonProxiableTypeError
–If
obj
is a non-proxiable type. This behavior can be overridden by settingskip_nonproxiable=True
.
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
, default:None
) –Optionally override the default serializer for the store instance.
-
kwargs
(Any
, default:{}
) –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
, default:None
) –Optionally override the default serializer for the store instance.
-
kwargs
(Any
, default:{}
) –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.
Source code in proxystore/store/base.py
StoreFactory ¶
StoreFactory(
key: ConnectorKeyT,
store_config: dict[str, Any],
*,
evict: bool = False,
deserializer: DeserializerT | None = 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
, default:False
) –If True, evict the object from the store once
resolve()
is called. -
deserializer
(DeserializerT | None
, default:None
) –Optional callable used to deserialize the byte string. If
None
, the default deserializer (deserialize()
) will be used.
Source code in proxystore/store/factory.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/factory.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/factory.py
resolve_async() ¶
Asynchronously get object associated with key from store.
get_store() ¶
Get the backend store with name.
Parameters:
Returns:
-
Store[Any] | None
–Store
if a store matching the name or belonging to the proxy exists. If the store does not exist, returnsNone
.
Raises:
-
ProxyStoreFactoryError
–If the value is a proxy but does not contain a factory of type
StoreFactory
.
Source code in proxystore/store/__init__.py
register_store() ¶
Register the store instance to the global registry.
Note
Global means globally accessible within the Python process.
Tip
Use the store_registration
context manager to automatically register and unregister as store.
Parameters:
-
store
(Store[Any]
) –Store instance to register.
-
exist_ok
(bool
, default:False
) –If a store with the same name exists, overwrite it.
Raises:
-
StoreExistsError
–If a store with the same name is already registered and
exist_ok
is false.
Source code in proxystore/store/__init__.py
store_registration() ¶
Context manager that registers and unregisters a set of stores.
Example
from proxystore.connectors.local import LocalConnector
from proxystore.store import Store
from proxystore.store import store_registration
with Store('store', LocalConnector()) as store:
with store_registration(store):
...
stores = [
Store('store1', LocalConnector()),
Store('store2', LocalConnector()),
]
with store_registration(*stores):
...
Parameters:
-
stores
(Store[Any]
, default:()
) –Set of
Store
instances to register then unregister when the context manager is exited. -
exist_ok
(bool
, default:False
) –If a store with the same name exists, overwrite it.
Raises:
-
StoreExistsError
–If a store with the same name is already registered and
exist_ok
is false.
Source code in proxystore/store/__init__.py
unregister_store() ¶
Unregisters the store instance from the global registry.
Note
This function is a no-op if no store matching the name exists (i.e., no exception will be raised).
Parameters: