llm/docs/plugins/plugin-utilities.md

22 lines
696 B
Markdown
Raw Normal View History

2023-07-11 14:43:21 +00:00
# Utility functions for plugins
LLM provides some utility functions that may be useful to plugins.
## llm.user_dir()
LLM stores various pieces of logging and configuration data in a directory on the user's machine.
On macOS this directory is `~/Library/Application Support/io.datasette.llm`, but this will differ on other operating systems.
The `llm.user_dir()` function returns the path to this directory as a `pathlib.Path` object.
Plugins can use this to store their own data in a subdirectory of this directory.
```python
import llm
user_dir = llm.user_dir()
plugin_dir = data_path = user_dir / "my-plugin"
plugin_dir.mkdir(exist_ok=True)
data_path = plugin_dir / "plugin-data.db"
```