Skip to main content
logo

✨ nonebot-plugin-session-config ✨

LICENSE pypi python uv
ruff pre-commit

📖 介绍

本插件为每个会话(群聊、私聊等场景)提供了独立的持久化配置存储功能。

💿 安装

使用 nb-cli 安装

nb plugin install nonebot-plugin-session-config --upgrade

使用 uv 安装

uv add nonebot-plugin-session-config

安装仓库 master 分支

uv add git+https://github.com/USTC-XeF2/nonebot-plugin-session-config@master

打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot.plugins] 部分追加写入

"@local" = ["nonebot_plugin_session_config"]

⚙️ 配置

所有配置项均以 SESSION_CONFIG_ 为前缀(下文省略),且均为选填项。

配置项 默认值 说明
BASE_DIR None 配置存储的根目录,值为 None 时使用 localstore 提供的配置文件目录,一般不需要更改
DIR_FORMAT bot-{bot_id} 各机器人所属目录的命名格式,不使用 bot_id 模板参数时所有机器人共用同一目录
FILE_FORMAT {scene_type}-{scene_id}.yaml 配置文件的命名格式
USE_GLOBAL False 是否尝试使用全局配置作为默认值,开启此项时请确保会话配置与全局配置间没有意料外的重复键
ENABLE_PARAM False 是否启用会话配置参数注入功能,启用后可直接指定会话配置类作为消息处理函数参数类型,在插件冲突时可能会注入失败

🎉 使用

from nonebot import on_message

from nonebot_plugin_session_config import (
    BaseSessionConfig,
    check_enabled,
    get_session_config,
)


# 所有会话配置类均应继承自 BaseSessionConfig
class SessionConfig(BaseSessionConfig):
    test_enabled: bool = False
    test_key: int = 0


message_handler = on_message(
    rule=check_enabled(SessionConfig, "test_enabled"),
)


@message_handler.handle()
async def _(session_config: SessionConfig = get_session_config(SessionConfig)):
    await message_handler.finish(f"Test key value is: {session_config.test_key}")


# 使用自动参数注入(需在配置中启用 ENABLE_PARAM 选项)
@message_handler.handle()
async def _(session_config: SessionConfig):
    await message_handler.finish(f"Test key value is: {session_config.test_key}")

本插件提供的配置不提供在程序中动态修改的接口,若需要修改请手动或自动编辑对应的文件,无需重启即可更新。

Metadata

Release files for nonebot-plugin-session-config 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-session-config 1.0.1
File Size Uploaded Provenance Actions
nonebot_plugin_session_config-1.0.1.tar.gz 6.9 kB With provenance Details for nonebot_plugin_session_config-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-session-config 1.0.1
File Interpreter ABI Platform Actions
nonebot_plugin_session_config-1.0.1-py3-none-any.whl Python 3 none any Details for nonebot_plugin_session_config-1.0.1-py3-none-any.whl

Total release size: 15.5 kB

Release files / nonebot_plugin_session_config-1.0.1.tar.gz

Download URL nonebot_plugin_session_config-1.0.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f235f053f442e593aa1744b614fd5f2415b03acd36aa0247719535ee0d3a8bad
BLAKE2b-256 checksum
How to use checksums
486a703c4312681f2c75ac12368391386c499094103e3d72d1739cdd61115e1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 31, 2026.

Transparency log

Release files / nonebot_plugin_session_config-1.0.1-py3-none-any.whl

Download URL nonebot_plugin_session_config-1.0.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f681954a483633eb67cd73611bb4ff2c2c112b5a167a5795842c5593beb5449a
BLAKE2b-256 checksum
How to use checksums
fd3fdc0cf6ccae33552c58d1c1922942981c84cf2d203193082c534160bcb7d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 31, 2026.

Transparency log

Security for nonebot-plugin-session-config 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nonebot_plugin_session_config-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page