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 toFalseto disable automatic writing at all.indent (
int|None) – If it is notNone, data in database file will be pretty printed with that indent level. Value is directly passed tojson.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:
- async write()[source]¶
Save changes on disk.
You can also manually call this method whenever you want.
- Return type:
- async _write_loop(interval)[source]¶
Call
write()every N seconds.- Parameters:
interval (
int) – How long we wait between every write.- Return type:
Never