Skip to main content

pyimaskill是一个面向 IMA OpenAPI的Python同步客户端,支持个人笔记和知识库的常见操作。

Project description

pyimaskill

PyPI Python License

pyimaskill 是一个面向 IMA OpenAPI 的 Python 同步客户端,支持个人笔记和知识库的常见操作。

功能特性

  • 笔记管理:搜索、列出笔记本、列出笔记、新建、追加、读取
  • 知识库管理:搜索、浏览、导入网页、上传文件
  • 类型安全:基于 Pydantic 模型自动解析响应
  • 同步设计:基于 requests.Session,无需 async/await
  • 凭证友好提示:支持 api_key 过期时间校验(有效期一个月)

安装

pip install pyimaskill

开发环境:

git clone https://github.com/AJayBBB/pyimaskill.git
cd pyimaskill
pip install -e ".[dev]"

快速开始

1. 获取凭证

前往 ima.qq.com/agent-interface 获取:

  • client_id:客户端 ID
  • api_key:API 密钥(支持一个月有效期

2. 初始化客户端

from pyimaskill import ImaClient

client = ImaClient(
    client_id="your-client-id",
    api_key="your-api-key",
)

3. 笔记操作示例

from pyimaskill import ImaClient

with ImaClient(client_id="your-client-id", api_key="your-api-key") as client:
    # 搜索笔记
    result = client.notes.search(query="Python", start=0, end=20)
    for note in result.docs:
        print(note.doc.basic_info.title)

    # 新建笔记
    doc_id = client.notes.import_doc(
        content="# 示例笔记\n\n这里是 Markdown 正文。",
    )
    print("创建成功:", doc_id)

4. 知识库操作示例

from pyimaskill import ImaClient

client = ImaClient(client_id="your-client-id", api_key="your-api-key")

# 获取知识库列表
kb_result = client.knowledge.search_knowledge_base(query="", cursor="", limit=20)

if not kb_result.info_list:
    print("您还没有创建任何知识库,请先创建知识库后再试。")
else:
    print(f"找到 {len(kb_result.info_list)} 个知识库:")
    for idx, kb in enumerate(kb_result.info_list, 1):
        print(f"  {idx}. {kb.name} (ID: {kb.id})")

# 导入微信公众号文章到知识库
kb_id = "your-knowledge-base-id"
article_url = "https://mp.weixin.qq.com/s/xxxxx"

import_result = client.knowledge.import_urls(
    knowledge_base_id=kb_id,
    urls=[article_url],
)

url_result = import_result.results.get(article_url)
if url_result and url_result.ret_code == 0:
    print(f"添加成功!媒体ID: {url_result.media_id}")
else:
    print(f"添加失败: {url_result.errmsg if url_result else '未知错误'}")

可选参数

client = ImaClient(
    client_id="your-client-id",
    api_key="your-api-key",
    api_key_expires_at="2026-05-06T08:00:00+08:00",  # 可选,用于过期提醒
    base_url="https://ima.qq.com",  # 可选,默认值
    timeout=30.0,  # 可选,默认值
)

文档

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyimaskill-0.0.3.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyimaskill-0.0.3-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file pyimaskill-0.0.3.tar.gz.

File metadata

  • Download URL: pyimaskill-0.0.3.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyimaskill-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5dc6467a634945e249f17d5b7b5c7322a5b8dbc27ea0c3db5705e9d1e987e8cd
MD5 20b085c3f825a5bbe5048298db8df7b5
BLAKE2b-256 55b68d11d555856c70ec6b1ec7264c392c7aedc9d976cb3315fb99f181bbfe3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyimaskill-0.0.3.tar.gz:

Publisher: publish.yml on AJayBBB/pyimaskill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyimaskill-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyimaskill-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyimaskill-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b8fbd9f1e36ba19a97298fe77815d35052de49510ee9ab1b11999bca6ae12af
MD5 afc9ae5d4316f5a9d93980dbc0332cc3
BLAKE2b-256 c7718e8aafaa3412559d4b3c8c9cf9deec05ca1c801cbd1b22a0c5129fba7fc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyimaskill-0.0.3-py3-none-any.whl:

Publisher: publish.yml on AJayBBB/pyimaskill

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page