Skip to content

gufo.blob.sync.memory

MemoryBlob implementation.

MemoryBlob

Bases: BlobBase

In-memory implementation of Blob storage.

Stores all objects in process memory with optional limits
  • max_objects: maximum number of keys allowed
  • max_size: maximum total size of all stored values in bytes

max_objects property

Maximum number of objects allowed in the blob store.

If set to None, the number of objects is unlimited.

Returns:

Type Description
int | None

Maximum number of stored keys or None if unlimited.

max_size property

Maximum total size of all stored values in bytes.

If set to None, total storage size is unlimited.

Returns:

Type Description
int | None

Maximum total size in bytes or None if unlimited.

delete(key)

Delete key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
KeyError

If the key does not exist.

BlobError

On backend or I/O failure.

exists(key)

Check whether a key exists in the blob store.

Parameters:

Name Type Description Default
key str

Object key.

required

Returns:

Type Description
bool

True if the key exists, False otherwise.

Raises:

Type Description
BlobError

On backend or I/O failure.

get(key)

Retrieve data by key.

Parameters:

Name Type Description Default
key str

Object key.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

parse_url(url) classmethod

Parse URL and extract parameters for constructor.

Parameters:

Name Type Description Default
url str

URL to parse.

required

Returns:

Type Description
dict[str, Any]

**kwargs for constructor.

put(key, data)

Store binary data under the given key.

If the key already exists, its value is overwritten.

Parameters:

Name Type Description Default
key str

Object key.

required
data bytes

Binary payload.

required

Raises:

Type Description
BlobError

On backend or I/O failure.

scan(prefix)

Iterate all keys within prefix.

Parameters:

Name Type Description Default
prefix str

Prefix to scan.

required

Returns:

Type Description
Iterable[str]

Yields matched keys.

Raises:

Type Description
BlobError

On backend or I/O failure.