Stores
dyui.store.Store
Section titled “dyui.store.Store”class Store(Protocol)Persistence backend for threads, messages and uploaded-file metadata.
Implement this protocol to plug in your own database; pass an instance as
App(persist=...). All methods are coroutines.
Store.create_thread()
Section titled “Store.create_thread()”async def create_thread(user_id: str, *, title: str = DEFAULT_TITLE) -> dict[str, Any]Create and return a new thread record.
Store.get_thread()
Section titled “Store.get_thread()”async def get_thread(thread_id: str) -> Optional[dict[str, Any]]Return a thread record (without messages) or None.
Store.list_threads()
Section titled “Store.list_threads()”async def list_threads(user_id: str, *, limit: int = 200) -> list[dict[str, Any]]Return the user’s threads, most recently updated first.
Store.update_thread()
Section titled “Store.update_thread()”async def update_thread(thread_id: str, **fields: Any) -> Optional[dict[str, Any]]Update title, title_locked, session and/or updated_at.
Store.delete_thread()
Section titled “Store.delete_thread()”async def delete_thread(thread_id: str) -> boolDelete a thread and its messages. Returns whether it existed.
Store.get_messages()
Section titled “Store.get_messages()”async def get_messages(thread_id: str) -> list[dict[str, Any]]Return a thread’s messages in insertion order.
Store.get_message()
Section titled “Store.get_message()”async def get_message(thread_id: str, message_id: str) -> Optional[dict[str, Any]]Return one message or None.
Store.put_message()
Section titled “Store.put_message()”async def put_message(thread_id: str, message: dict[str, Any]) -> NoneInsert or replace a message (by id); replacing keeps its position.
Store.delete_messages_after()
Section titled “Store.delete_messages_after()”async def delete_messages_after( thread_id: str, message_id: str, *, inclusive: bool = False,) -> intDelete messages after message_id (and it, if inclusive). Returns the count.
Store.put_file()
Section titled “Store.put_file()”async def put_file(record: dict[str, Any]) -> NoneSave uploaded-file metadata.
Store.get_file()
Section titled “Store.get_file()”async def get_file(file_id: str) -> Optional[dict[str, Any]]Return uploaded-file metadata or None.
Store.close()
Section titled “Store.close()”async def close() -> NoneRelease resources.
dyui.store.SQLiteStore
Section titled “dyui.store.SQLiteStore”class SQLiteStore(path: Union[str, Path])A dyui.store.Store backed by a SQLite file.
Parameters
| Name | Type | Description |
|---|---|---|
path |
Union[str, Path] |
Database file path (parent directories are created on first use). |
SQLiteStore.create_thread()
Section titled “SQLiteStore.create_thread()”async def create_thread(user_id: str, *, title: str = DEFAULT_TITLE) -> dict[str, Any]SQLiteStore.get_thread()
Section titled “SQLiteStore.get_thread()”async def get_thread(thread_id: str) -> Optional[dict[str, Any]]SQLiteStore.list_threads()
Section titled “SQLiteStore.list_threads()”async def list_threads(user_id: str, *, limit: int = 200) -> list[dict[str, Any]]SQLiteStore.update_thread()
Section titled “SQLiteStore.update_thread()”async def update_thread(thread_id: str, **fields: Any) -> Optional[dict[str, Any]]SQLiteStore.delete_thread()
Section titled “SQLiteStore.delete_thread()”async def delete_thread(thread_id: str) -> boolSQLiteStore.get_messages()
Section titled “SQLiteStore.get_messages()”async def get_messages(thread_id: str) -> list[dict[str, Any]]SQLiteStore.get_message()
Section titled “SQLiteStore.get_message()”async def get_message(thread_id: str, message_id: str) -> Optional[dict[str, Any]]SQLiteStore.put_message()
Section titled “SQLiteStore.put_message()”async def put_message(thread_id: str, message: dict[str, Any]) -> NoneSQLiteStore.delete_messages_after()
Section titled “SQLiteStore.delete_messages_after()”async def delete_messages_after( thread_id: str, message_id: str, *, inclusive: bool = False,) -> intSQLiteStore.put_file()
Section titled “SQLiteStore.put_file()”async def put_file(record: dict[str, Any]) -> NoneSQLiteStore.get_file()
Section titled “SQLiteStore.get_file()”async def get_file(file_id: str) -> Optional[dict[str, Any]]SQLiteStore.close()
Section titled “SQLiteStore.close()”async def close() -> Nonedyui.store.MemoryStore
Section titled “dyui.store.MemoryStore”class MemoryStoreA dyui.store.Store that keeps everything in process memory.
Records are deep-copied on the way in and out, so callers can’t mutate stored state by accident.
MemoryStore.create_thread()
Section titled “MemoryStore.create_thread()”async def create_thread(user_id: str, *, title: str = DEFAULT_TITLE) -> dict[str, Any]MemoryStore.get_thread()
Section titled “MemoryStore.get_thread()”async def get_thread(thread_id: str) -> Optional[dict[str, Any]]MemoryStore.list_threads()
Section titled “MemoryStore.list_threads()”async def list_threads(user_id: str, *, limit: int = 200) -> list[dict[str, Any]]MemoryStore.update_thread()
Section titled “MemoryStore.update_thread()”async def update_thread(thread_id: str, **fields: Any) -> Optional[dict[str, Any]]MemoryStore.delete_thread()
Section titled “MemoryStore.delete_thread()”async def delete_thread(thread_id: str) -> boolMemoryStore.get_messages()
Section titled “MemoryStore.get_messages()”async def get_messages(thread_id: str) -> list[dict[str, Any]]MemoryStore.get_message()
Section titled “MemoryStore.get_message()”async def get_message(thread_id: str, message_id: str) -> Optional[dict[str, Any]]MemoryStore.put_message()
Section titled “MemoryStore.put_message()”async def put_message(thread_id: str, message: dict[str, Any]) -> NoneMemoryStore.delete_messages_after()
Section titled “MemoryStore.delete_messages_after()”async def delete_messages_after( thread_id: str, message_id: str, *, inclusive: bool = False,) -> intMemoryStore.put_file()
Section titled “MemoryStore.put_file()”async def put_file(record: dict[str, Any]) -> NoneMemoryStore.get_file()
Section titled “MemoryStore.get_file()”async def get_file(file_id: str) -> Optional[dict[str, Any]]MemoryStore.close()
Section titled “MemoryStore.close()”async def close() -> None