API Reference

final class Storage(path, *, indent)[source]

Core key-value store, that is responsible for correctly storing JSON and writing it to file.

instances: t.ClassVar[list[te.Self]] = []
async classmethod init(path, *, write_interval=300, indent=2)[source]

Python doesn’t have async init methods, so we have to use this.

Parameters:
  • path (Path | str) – Path to database file. Do note that you should allocate entire folder to the database, because this library creates a few temp files near the db for technical reasons.

  • write_interval (Union[int, Literal[False]]) – How often we should write to database in seconds? Set to False to disable automatic writing at all.

  • indent (int | None) – If it is not None, data in database file will be pretty printed with that indent level. Value is directly passed to json.dump().

Return type:

Self

async read()[source]

Read content from the db file.

This method is usually called only on initialization, but if you added some data to the file manually, you can call this method to sync in-memory state with what is written on disk.

Return type:

None

async write()[source]

Save changes on disk.

You can also manually call this method whenever you want.

Return type:

None

async _write_loop(interval)[source]

Call write() every N seconds.

Parameters:

interval (int) – How long we wait between every write.

Return type:

Never

async _append_command(key, value)[source]

Handle AOF logic on every set().

Return type:

None

async set(key, value, *, _replay=False)[source]

Set a key to value.

Parameters:

_replay (bool) – If True, we won’t do AOF stuff. This is used when we replay operations from AOF.

Return type:

None

async get(key)[source]
Return type:

SERIALIZABLE_TYPE