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_backoff_factor: float = 1,
polling_interval_limit: float | None = None,
polling_timeout: float | None = None
) -> Future[T]
Create a future to an object.
Example
from proxystore.connectors.file import FileConnector
from proxystore.store import Store
from proxystore.store.future import Future
def remote_foo(future: Future) -> 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
Future.proxy()
are experimental features and may change in future releases.
Parameters:
-
evict
(bool
, default:False
) βIf a proxy returned by
Future.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
) βInitial seconds to sleep between polling the store for the object.
-
polling_backoff_factor
(float
, default:1
) βMultiplicative factor applied to the polling_interval applied after each unsuccessful poll.
-
polling_interval_limit
(float | None
, default:None
) βMaximum polling interval allowed. Prevents the backoff factor from increasing the current polling interval to unreasonable values.
-
polling_timeout
(float | None
, default:None
) βOptional maximum number of seconds to poll for. If the timeout is reached an error is raised.
Returns:
-
Future[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
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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
|
evict() ¶
evict(key: ConnectorKeyT) -> None
Evict the object associated with the key.
Parameters:
-
key
(ConnectorKeyT
) βKey associated with object to evict.
Source code in proxystore/store/base.py
exists() ¶
exists(key: ConnectorKeyT) -> bool
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.
Raises:
-
SerializationError
βIf an exception is caught when deserializing the object associated with the key.
Source code in proxystore/store/base.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
|
is_cached() ¶
is_cached(key: ConnectorKeyT) -> bool
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,
lifetime: Lifetime | None = None,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
populate_target: bool = False,
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. Mutually exclusive with the
lifetime
parameter. -
lifetime
(Lifetime | None
, default:None
) βAttach the proxy to this lifetime. The object associated with the proxy will be evicted when the lifetime ends. Mutually exclusive with the
evict
parameter. -
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.
-
populate_target
(bool
, default:False
) βSet the returned proxy to point at
obj
. I.e., return an already resolved proxy. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. Setting this flag is helpful when serializing the returned proxy on this process will incidentally resolve the proxy. -
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
. -
ValueError
βIf
evict
isTrue
andlifetime
is notNone
because these parameters are mutually exclusive.
Source code in proxystore/store/base.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 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 |
|
proxy_batch() ¶
proxy_batch(
objs: Sequence[T | NonProxiableT],
*,
evict: bool = False,
lifetime: Lifetime | None = None,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
populate_target: bool = False,
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. Mutually exclusive with the
lifetime
parameter. -
lifetime
(Lifetime | None
, default:None
) βAttach the proxies to this lifetime. The objects associated with each proxy will be evicted when the lifetime ends. Mutually exclusive with the
evict
parameter. -
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.
-
populate_target
(bool
, default:False
) βSet each returned proxy to point at its corresponding
obj
. I.e., return an already resolved proxy. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. Setting this flag is helpful when serializing a returned proxy on this process will incidentally resolve the proxy. -
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
. -
ValueError
βIf
evict
isTrue
andlifetime
is notNone
because these parameters are mutually exclusive.
Source code in proxystore/store/base.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
|
proxy_from_key() ¶
proxy_from_key(
key: ConnectorKeyT,
*,
evict: bool = False,
lifetime: Lifetime | None = None,
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. Mutually exclusive with the
lifetime
parameter. -
lifetime
(Lifetime | None
, default:None
) βAttach the proxy to this lifetime. The object associated with the proxy will be evicted when the lifetime ends. Mutually exclusive with the
evict
parameter. -
deserializer
(DeserializerT | None
, default:None
) βOptionally override the default deserializer for the store instance.
Returns:
-
Proxy[T]
βA proxy of the object.
Raises:
-
ValueError
βIf
evict
isTrue
andlifetime
is notNone
because these parameters are mutually exclusive.
Source code in proxystore/store/base.py
locked_proxy() ¶
locked_proxy(
obj: T | NonProxiableT,
*,
evict: bool = False,
lifetime: Lifetime | None = None,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
populate_target: bool = False,
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. Mutually exclusive with the
lifetime
parameter. -
lifetime
(Lifetime | None
, default:None
) βAttach the proxy to this lifetime. The object associated with the proxy will be evicted when the lifetime ends. Mutually exclusive with the
evict
parameter. -
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.
-
populate_target
(bool
, default:False
) βSet the returned proxy to point at
obj
. I.e., return an already resolved proxy. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. Setting this flag is helpful when serializing the returned proxy on this process will incidentally resolve the proxy. -
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
. -
ValueError
βIf
evict
isTrue
andlifetime
is notNone
because these parameters are mutually exclusive.
Source code in proxystore/store/base.py
owned_proxy() ¶
owned_proxy(
obj: T | NonProxiableT,
*,
serializer: SerializerT | None = None,
deserializer: DeserializerT | None = None,
populate_target: bool = False,
skip_nonproxiable: bool = True,
**kwargs: Any
) -> OwnedProxy[T] | NonProxiableT
Create a proxy that will enforce ownership rules over the object.
An OwnedProxy
will auto-evict
the object once it goes out of scope. This proxy type can also
be borrowed.
Parameters:
-
obj
(T | NonProxiableT
) βThe object to place in store and return a proxy for.
-
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.
-
populate_target
(bool
, default:False
) βSet the returned proxy to point at
obj
. I.e., return an already resolved proxy. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. Setting this flag is helpful when serializing the returned proxy on this process will incidentally resolve the proxy. -
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:
-
OwnedProxy[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
put() ¶
put(
obj: Any,
*,
lifetime: Lifetime | None = None,
serializer: SerializerT | None = None,
**kwargs: Any
) -> ConnectorKeyT
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.
-
lifetime
(Lifetime | None
, default:None
) βAttach the key to this lifetime. The object associated with the key will be evicted when the lifetime ends.
-
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],
*,
lifetime: Lifetime | None = None,
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.
-
lifetime
(Lifetime | None
, default:None
) βAttach the keys to this lifetime. The objects associated with each key will be evicted when the lifetime ends.
-
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
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
|
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() -> Store[ConnectorT]
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: