NapCat SDK for Python - Fully typed and async ready
Project description
NapCat-SDK for Python
Type-Safe • Async-Ready • Framework-Free
Stop guessing parameter types. Let the IDE do the work.
告别查文档,享受 100% 类型覆盖 带来的极致补全体验。
⚡ The "IDE Magic"
这就是为什么你应该选择 NapCat-SDK:
| 智能 API 补全 + 精准参数提示 | 原生开发体验 + 零心智负担 |
|---|---|
👆 真正的 140+ API 全量类型覆盖,每一次按键都有 IDE 的守护。
✨ Features
- 🚀 完全异步: 基于
websockets+asyncio,高并发无压力。 - 💎 强类型优先: 每一个 Event、每一个 MessageSegment 都有严格定义。
- 🔌 双模式支持: Client (正向) / Server (反向) 随意切换。
- 🛠 零依赖: 仅依赖
websockets和orjson,极其轻量。
📸 Quick Look
🖱️ 点击复制代码文本
import asyncio
from napcat import NapCatClient, GroupMessageEvent, PrivateMessageEvent
# --- 消费者 A: 监听私聊 ---
async def listen_private(client: NapCatClient):
print(">> 私聊监听启动")
# 独立的 async for,享受完整的事件流副本
async for event in client.events():
match event:
case PrivateMessageEvent():
print(f"[私信] {event.sender.nickname}: {event.raw_message}")
await event.send_msg("已阅")
case _:
pass
# --- 消费者 B: 监听群聊 ---
async def listen_group(client: NapCatClient):
print(">> 群聊监听启动")
# 另一个独立的 async for,互不抢占
async for event in client.events():
match event:
case GroupMessageEvent():
print(f"[群消息] {event.group_id}: {event.raw_message}")
await event.reply("复读")
case _:
pass
async def main():
# 正向 WebSocket 连接
async with NapCatClient(ws_url="ws://localhost:80", token="123") as client:
# 关键点:使用 gather 同时运行多个消费者
await asyncio.gather(
listen_private(client),
listen_group(client)
)
if __name__ == "__main__":
asyncio.run(main())
📦 Installation
uv add napcat-sdk
# or
pip install napcat-sdk
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
napcat_sdk-0.2.5.tar.gz
(31.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file napcat_sdk-0.2.5.tar.gz.
File metadata
- Download URL: napcat_sdk-0.2.5.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1069275e7245560a30fdbfa87d22e5561c1fbfca89e290e455e760513fd1b42
|
|
| MD5 |
99a6c66f460b94121912e30b2a47a588
|
|
| BLAKE2b-256 |
713ab83ae81082433c466ce97975aea7a11785a9f2704513c4ef9e5af4c208c5
|
File details
Details for the file napcat_sdk-0.2.5-py3-none-any.whl.
File metadata
- Download URL: napcat_sdk-0.2.5-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f6b73055e6f1e0d537a2f0d8195ff28d21aa8f6caf948fef7a1beaffeeeb910
|
|
| MD5 |
d7b36be733f3e6ac73de54a397cd2e45
|
|
| BLAKE2b-256 |
9645002fc409792469e973bb066303a05e6d3d79c4024577a5c848950a320a66
|