Skip to content

proxystore.connectors.local

In-process local storage connector implementation.

LocalKey

Bases: NamedTuple

Key to objects store in a LocalConnector.

Attributes:

  • id (str) –

    Unique object ID.

LocalConnector

LocalConnector(
    store_dict: dict[LocalKey, bytes] | None = None
)

Connector that store objects in the local process's memory.

Warning

This connector exists primarily for testing purposes.

Parameters:

  • store_dict (dict[LocalKey, bytes] | None, default: None ) –

    Dictionary to store data in. If not specified, a new empty dict will be generated.

Source code in proxystore/connectors/local.py
def __init__(
    self,
    store_dict: dict[LocalKey, bytes] | None = None,
) -> None:
    self._store: dict[LocalKey, bytes] = {}
    if store_dict is not None:
        self._store = store_dict

close()

close() -> None

Close the connector and clean up.

Source code in proxystore/connectors/local.py
def close(self) -> None:
    """Close the connector and clean up."""
    pass

config()

config() -> dict[str, Any]

Get the connector configuration.

The configuration contains all the information needed to reconstruct the connector object.

Source code in proxystore/connectors/local.py
def config(self) -> dict[str, Any]:
    """Get the connector configuration.

    The configuration contains all the information needed to reconstruct
    the connector object.
    """
    return {'store_dict': self._store}

from_config() classmethod

from_config(config: dict[str, Any]) -> LocalConnector

Create a new connector instance from a configuration.

Parameters:

  • config (dict[str, Any]) –

    Configuration returned by .config().

Source code in proxystore/connectors/local.py
@classmethod
def from_config(cls, config: dict[str, Any]) -> LocalConnector:
    """Create a new connector instance from a configuration.

    Args:
        config: Configuration returned by `#!python .config()`.
    """
    return cls(**config)

evict()

evict(key: LocalKey) -> None

Evict the object associated with the key.

Parameters:

  • key (LocalKey) –

    Key associated with object to evict.

Source code in proxystore/connectors/local.py
def evict(self, key: LocalKey) -> None:
    """Evict the object associated with the key.

    Args:
        key: Key associated with object to evict.
    """
    if key in self._store:
        del self._store[key]

exists()

exists(key: LocalKey) -> bool

Check if an object associated with the key exists.

Parameters:

  • key (LocalKey) –

    Key potentially associated with stored object.

Returns:

  • bool

    If an object associated with the key exists.

Source code in proxystore/connectors/local.py
def exists(self, key: LocalKey) -> bool:
    """Check if an object associated with the key exists.

    Args:
        key: Key potentially associated with stored object.

    Returns:
        If an object associated with the key exists.
    """
    return key in self._store

get()

get(key: LocalKey) -> bytes | None

Get the serialized object associated with the key.

Parameters:

  • key (LocalKey) –

    Key associated with the object to retrieve.

Returns:

  • bytes | None

    Serialized object or None if the object does not exist.

Source code in proxystore/connectors/local.py
def get(self, key: LocalKey) -> bytes | None:
    """Get the serialized object associated with the key.

    Args:
        key: Key associated with the object to retrieve.

    Returns:
        Serialized object or `None` if the object does not exist.
    """
    return self._store.get(key, None)

get_batch()

get_batch(keys: Sequence[LocalKey]) -> list[bytes | None]

Get a batch of serialized objects associated with the keys.

Parameters:

  • keys (Sequence[LocalKey]) –

    Sequence of keys associated with objects to retrieve.

Returns:

  • list[bytes | None]

    List with same order as keys with the serialized objects or None if the corresponding key does not have an associated object.

Source code in proxystore/connectors/local.py
def get_batch(self, keys: Sequence[LocalKey]) -> list[bytes | None]:
    """Get a batch of serialized objects associated with the keys.

    Args:
        keys: Sequence of keys associated with objects to retrieve.

    Returns:
        List with same order as `keys` with the serialized objects or \
        `None` if the corresponding key does not have an associated object.
    """
    return [self.get(key) for key in keys]

new_key()

new_key(obj: bytes | None = None) -> LocalKey

Create a new key.

Parameters:

  • obj (bytes | None, default: None ) –

    Optional object which the key will be associated with. Ignored in this implementation.

Returns:

  • LocalKey

    Key which can be used to retrieve an object once set() has been called on the key.

Source code in proxystore/connectors/local.py
def new_key(self, obj: bytes | None = None) -> LocalKey:
    """Create a new key.

    Args:
        obj: Optional object which the key will be associated with.
            Ignored in this implementation.

    Returns:
        Key which can be used to retrieve an object once \
        [`set()`][proxystore.connectors.local.LocalConnector.set] \
        has been called on the key.
    """
    return LocalKey(str(uuid.uuid4()))

put()

put(obj: bytes) -> LocalKey

Put a serialized object in the store.

Parameters:

  • obj (bytes) –

    Serialized object to put in the store.

Returns:

  • LocalKey

    Key which can be used to retrieve the object.

Source code in proxystore/connectors/local.py
def put(self, obj: bytes) -> LocalKey:
    """Put a serialized object in the store.

    Args:
        obj: Serialized object to put in the store.

    Returns:
        Key which can be used to retrieve the object.
    """
    key = LocalKey(str(uuid.uuid4()))
    self._store[key] = obj
    return key

put_batch()

put_batch(objs: Sequence[bytes]) -> list[LocalKey]

Put a batch of serialized objects in the store.

Parameters:

  • objs (Sequence[bytes]) –

    Sequence of serialized objects to put in the store.

Returns:

  • list[LocalKey]

    List of keys with the same order as objs which can be used to retrieve the objects.

Source code in proxystore/connectors/local.py
def put_batch(self, objs: Sequence[bytes]) -> list[LocalKey]:
    """Put a batch of serialized objects in the store.

    Args:
        objs: Sequence of serialized objects to put in the store.

    Returns:
        List of keys with the same order as `objs` which can be used to \
        retrieve the objects.
    """
    return [self.put(obj) for obj in objs]

set()

set(key: LocalKey, obj: bytes) -> None

Set the object associated with a key.

Parameters:

  • key (LocalKey) –

    Key that the object will be associated with.

  • obj (bytes) –

    Object to associate with the key.

Source code in proxystore/connectors/local.py
def set(self, key: LocalKey, obj: bytes) -> None:
    """Set the object associated with a key.

    Args:
        key: Key that the object will be associated with.
        obj: Object to associate with the key.
    """
    self._store[key] = obj