Skip to main content

Python client library for IMA OpenAPI — manage notes and knowledge bases programmatically

Project description

pyimaskill

PyPI Python License

pyimaskill 是一个面向 IMA OpenAPI 的 Python 同步客户端,支持个人笔记和知识库的常见操作。无需 asyncio,代码简单直接,非常适合 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.1.tar.gz (17.5 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.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyimaskill-0.0.1.tar.gz
  • Upload date:
  • Size: 17.5 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.1.tar.gz
Algorithm Hash digest
SHA256 1e795ea18f23666432755029e2082ad8ba3228b1bb091d5bdc5afa115f944604
MD5 b6dde1281ab1d84ff13c4ad6dfe43dd7
BLAKE2b-256 c45a29308c31b459da55e95c6bcefdcc75c62cfa1e17bd9ab7b49e24d85f4160

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyimaskill-0.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pyimaskill-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7002183302fd49b08e46d6b489fb4e8d0691da6f6be0c62e1871bb1ea5ce92f
MD5 2d0061d353efc270c8e3a943c3f79351
BLAKE2b-256 35bad64a370c1738798eab9da32b5fad16237a1821a9420cf3dd35ad261eb199

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyimaskill-0.0.1-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