https://github.com/nonebot/plugin-localstore
Local Storage Support for NoneBot2
https://github.com/nonebot/plugin-localstore
Last synced: about 1 year ago
JSON representation
Local Storage Support for NoneBot2
- Host: GitHub
- URL: https://github.com/nonebot/plugin-localstore
- Owner: nonebot
- License: mit
- Created: 2021-03-22T08:48:24.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T08:08:19.000Z (over 1 year ago)
- Last Synced: 2024-10-29T23:33:41.562Z (over 1 year ago)
- Language: Python
- Homepage: https://nonebot.dev/docs/best-practice/data-storing
- Size: 209 KB
- Stars: 22
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NoneBot Plugin LocalStore
_✨ NoneBot 本地数据存储插件 ✨_
## 使用方式
加载插件后使用 `require` 声明插件依赖,直接使用 `localstore` 插件提供的函数即可。
```python
from pathlib import Path
from nonebot import require
require("nonebot_plugin_localstore")
import nonebot_plugin_localstore as store
plugin_cache_dir: Path = store.get_plugin_cache_dir()
plugin_cache_file: Path = store.get_plugin_cache_file("filename")
plugin_config_dir: Path = store.get_plugin_config_dir()
plugin_config_file: Path = store.get_plugin_config_file("filename")
plugin_data_dir: Path = store.get_plugin_data_dir()
plugin_data_file: Path = store.get_plugin_data_file("filename")
```
## 存储路径
在项目安装插件后,可以使用 `nb-cli` 查看具体的存储路径:
```bash
nb localstore
```
参考路径如下:
### cache path
- macOS: `~/Library/Caches/`
- Unix: `~/.cache/` (XDG default)
- Windows: `C:\Users\\AppData\Local\\Cache`
### data path
- macOS: `~/Library/Application Support/`
- Unix: `~/.local/share/` or in $XDG_DATA_HOME, if defined
- Win XP (not roaming): `C:\Documents and Settings\\Application Data\`
- Win 7 (not roaming): `C:\Users\\AppData\Local\`
### config path
- macOS: same as user_data_dir
- Unix: `~/.config/`
- Win XP (roaming): `C:\Documents and Settings\\Local Settings\Application Data\`
- Win 7 (roaming): `C:\Users\\AppData\Roaming\`
## 配置项
插件支持配置全局存储路径,也支持为插件单独配置存储路径。
```dotenv
LOCALSTORE_CACHE_DIR=/tmp/cache
LOCALSTORE_DATA_DIR=/tmp/data
LOCALSTORE_CONFIG_DIR=/tmp/config
LOCALSTORE_PLUGIN_CACHE_DIR='
{
"plugin1": "/tmp/plugin1/cache",
"plugin2:sub_plugin": "/tmp/plugin2/sub_plugin/cache"
}
'
LOCALSTORE_PLUGIN_DATA_DIR='
{
"plugin1": "/tmp/plugin1/data",
"plugin2:sub_plugin": "/tmp/plugin2/sub_plugin/data"
}
'
LOCALSTORE_PLUGIN_CONFIG_DIR='
{
"plugin1": "/tmp/plugin1/config",
"plugin2:sub_plugin": "/tmp/plugin2/sub_plugin/config"
}
'
```
