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,
populate_target: bool = False,
register: 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.
-
populate_target
(bool
, default:False
) –Set the default value of
populate_target
for proxy methods of the store. -
register
(bool
, default:False
) –Register the store instance after initialization.
Raises:
-
ValueError
–If
cache_size
is less than zero. -
StoreExistsError
–If
register=True
and a store withname
already exists.
Source code in proxystore/store/base.py
close() ¶
Close the connector associated with the store.
This will (1) close the connector and (2) unregister the store if
register=True
was set during initialization.
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() ¶
config() -> StoreConfig
Get the store configuration.
Returns:
-
StoreConfig
–Store configuration.
Source code in proxystore/store/base.py
from_config()
classmethod
¶
from_config(config: StoreConfig) -> Store[Any]
Create a new store instance from a configuration.
Parameters:
-
config
(StoreConfig
) –Configuration returned by
.config()
.
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
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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
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
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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
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 | 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. 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 | None
, default:None
) –Pass
cache_defaults=True
andtarget=obj
to theProxy
constructor. I.e., return a proxy that (1) is already resolved, (2) can be used inisinstance
checks without resolving, and (3) is hashable without resolving ifobj
is a hashable type. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. IfNone
, defaults to the store-wide setting. -
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
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 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 655 656 657 658 659 660 661 662 663 664 665 666 667 |
|
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 | 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. 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 | None
, default:None
) –Pass
cache_defaults=True
andtarget=obj
to theProxy
constructor. I.e., return a proxy that (1) is already resolved, (2) can be used inisinstance
checks without resolving, and (3) is hashable without resolving ifobj
is a hashable type. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. IfNone
, defaults to the store-wide setting. -
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
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 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
|
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 | 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. 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 | None
, default:None
) –Pass
cache_defaults=True
andtarget=obj
to theProxy
constructor. I.e., return a proxy that (1) is already resolved, (2) can be used inisinstance
checks without resolving, and (3) is hashable without resolving ifobj
is a hashable type. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. IfNone
, defaults to the store-wide setting. -
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 | None = None,
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 | None
, default:None
) –Pass
cache_defaults=True
andtarget=obj
to theProxy
constructor. I.e., return a proxy that (1) is already resolved, (2) can be used inisinstance
checks without resolving, and (3) is hashable without resolving ifobj
is a hashable type. This isFalse
by default because the returned proxy will hold a reference toobj
which will prevent garbage collectingobj
. IfNone
, defaults to the store-wide setting. -
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
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|
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
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
|
StoreFactory ¶
StoreFactory(
key: ConnectorKeyT,
store_config: StoreConfig,
*,
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
(StoreConfig
) –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]
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 a registered store by 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
get_or_create_store() ¶
get_or_create_store(
store_config: StoreConfig, *, register: bool = True
) -> Store[Any]
Get a registered store or initialize a new instance from the config.
Parameters:
-
store_config
(StoreConfig
) –Store configuration used to reinitialize the store if needed.
-
register
(bool
, default:True
) –Optionally register the store if a new instance was initialized.
Returns:
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: