Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 2.12.36 instead.
Reason given by maintainers: 发错了

ApeMind Python SDK (apemind-sdk)

ApeMind 官方 Python SDK,基于仓库公开 OpenAPI 规范(docs/openapi/openapi.json)自动生成 Pydantic v2 数据模型与同步 / 异步 httpx 客户端,覆盖知识库、文档、检索与 Agent 对话核心业务链路。

安装

方式一:通过 PyPI 安装(推荐)

pip install apemind-sdk

方式二:安装 GitHub Release 构建包(支持内网/离线私有化环境)

每次发版 CI 会自动构建对应版本的 .whl、.tar.gz 与 apemind-sdk-SHA256SUMS.txt 并附在 GitHub Release 下:

# 下载对应版本的 wheel 后安装(可拷入离线环境执行)
pip install ./apemind_sdk-<version>-py3-none-any.whl

方式三:从源码目录安装

pip install ./sdk/python

快速开始

客户端默认读取环境变量 APEMIND_BASE_URL(默认 https://apemind.ai)、APEMIND_API_KEY 与可选的 APEMIND_WORKSPACE_ID,也支持在构造时显式传入:

from apemind import ApeMindClient, extract_turn_text

with ApeMindClient(
    base_url="https://apemind.ai",
    api_key="sk-...",
    workspace_id="org_...",
) as client:
    # 1. 创建知识库(声明式配置)
    kb = client.knowledge_bases.create(title="产品制度库")
    kb_id = kb.metadata.id

    # 2. 两步上传文档并等待索引完成
    uploaded = client.documents.upload(kb_id, "handbook.pdf", path="制度/handbook.pdf")
    client.documents.confirm(kb_id, [uploaded.document_id])
    doc = client.documents.wait_until_indexed(kb_id, uploaded.document_id)

    # 3. 知识库混合检索(向量 + 全文 + 图谱)
    search_res = client.search.collection(kb_id, "年假天数如何计算?", vector_topk=5, fulltext_topk=5)
    for item in search_res.items or []:
        print(item.rank, item.score, item.content[:80])

    # 4. Agent 异步 Turn 对话与句级引用
    chat = client.chats.create(agent_id="agent_...")
    turn = client.chats.ask(chat.id, "请总结年假制度并给出依据条款。")
    print(extract_turn_text(turn))
    evidence = client.chats.get_turn_evidence(chat.id, turn.turn_id)

需要异步调用时使用 AsyncApeMindClient(接口与同步版一致):

from apemind import AsyncApeMindClient

async with AsyncApeMindClient(base_url="https://apemind.ai", api_key="sk-...") as client:
    res = await client.search.collection("kb_...", "合同解除条件")

覆盖能力与客户端分层

  • 高层资源接口(推荐日常使用):
    • client.knowledge_bases:声明式创建/查询/局部更新、列表、索引状态汇总、重建失败索引、删除
    • client.documents:单步上传、两步暂存上传 + 确认、URL 抓取、列表/详情、内容读写、原文件下载、删除、索引轮询等待 wait_until_indexed()
    • client.search:单知识库多路混合检索 collection()、跨库检索 workspace()、检索历史、grep() / read()
    • client.agents:声明式创建/列表/查询/局部更新/删除 Agent
    • client.chats:会话管理、异步 Turn 创建/轮询/等待/取消/句级证据、OpenAI 兼容同步 chat_completions() 与流式 stream_chat_completions()
    • client.me() / client.list_workspaces():当前认证身份与可用组织工作空间
  • 底层自动生成绑定:通过 client.api 直接访问所有 65 个从 OpenAPI 自动生成的强类型方法,通过 apemind.models 访问所有自动生成的 Pydantic v2 模型。

示例代码

从 OpenAPI 重新生成与测试

# 重新生成 src/apemind/_generated/{models.py,api.py,__init__.py}
python3 sdk/python/scripts/generate_sdk.py

# 校验无漂移(CI 门禁同款)
python3 sdk/python/scripts/generate_sdk.py --check

# 运行单元测试与代码检查
PYTHONPATH=sdk/python/src pytest sdk/python/tests -q
ruff check sdk/python/src sdk/python/scripts sdk/python/tests sdk/python/examples

发布机制

仓库每次发布 v* 正式 Release(或推送 sdk/v* Tag)时,.github/workflows/release-python-sdk.yml 会自动:

  1. 将 Tag 转换为 PEP 440 版本号(如 v2.12.33 → 2.12.33);
  2. 校验 OpenAPI 零漂移并运行 SDK 单元测试;
  3. 构建 .whl、.tar.gz 与 apemind-sdk-SHA256SUMS.txt,并在干净虚拟环境中验证 wheel 安装与导入;
  4. 上传构建产物到对应 GitHub Release;
  5. 当仓库变量 APEMIND_PYPI_PUBLISH=true(稳定版本号 vX.Y.Z / sdk/vX.Y.Z)或手动触发 workflow_dispatch 勾选 publish_pypi 时,通过 pypi GitHub Environment(支持 PyPI Trusted Publishing OIDC 或 PYPI_API_TOKEN)自动发布到 PyPI。

Metadata

Release files for apemind-sdk 2.12.35

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

Source distribution (sdist)

Source distribution for apemind-sdk 2.12.35
File Size Uploaded Provenance Actions
apemind_sdk-2.12.35.tar.gz 51.2 kB With provenance Details for apemind_sdk-2.12.35.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apemind-sdk 2.12.35
File Interpreter ABI Platform Actions
apemind_sdk-2.12.35-py3-none-any.whl Python 3 none any Details for apemind_sdk-2.12.35-py3-none-any.whl

Total release size: 95.0 kB

Release files / apemind_sdk-2.12.35.tar.gz

Download URL apemind_sdk-2.12.35.tar.gz
Size 51.2 kB
Tags Source
SHA-256 checksum
How to use checksums
806751f59dceb6e4a2c4750443f886580e7d0a045c1e4f95f1e78b5281c12a18
BLAKE2b-256 checksum
How to use checksums
ce666a824efca057b9379d201b03246394769ce40c6d0d027c492f3900c8a57c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / apemind_sdk-2.12.35-py3-none-any.whl

Download URL apemind_sdk-2.12.35-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8784e227ca25a57d731d899fdb1bc21a079b5c2a53bfcfae180e692a55a8b8d
BLAKE2b-256 checksum
How to use checksums
ea347b0c06839101e8591ac6d9c0cb497c2d7ddee97c161866829cbd010981c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for apemind-sdk 2.12.35

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 apemind_sdk-2.12.35.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 Nov 26, 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

2.12.35 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