Storage

A key/value store for the SDK's state.

On this page

Protocol in sponsorkit.storage.

from sponsorkit import Storage

Also importable from sponsorkit.storage.

class Storage(Protocol):
    ...

A key/value store for the SDK's state. Keys are targets_hash values; values are JSON text.

Implement this to keep Sponsorkit's state somewhere else (for example an OS keychain). Implementations must make write() atomic: a concurrent read() sees either the old or the new value, never a partial one.

Implement the methods below on any class; no subclassing is needed (it is a runtime_checkable Protocol).

Methods#

read()#

def read(self, key: str) -> str | None

Return the stored JSON text, or None if nothing is stored.

write()#

def write(self, key: str, data: str) -> None

Atomically replace the stored JSON text.

delete()#

def delete(self, key: str) -> None

Remove the stored value, if any.