非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能
Project description
ima-python-sdk
非官方的 IMA OpenAPI Python SDK,提供知识库和笔记管理功能。
本项目参考 ima-skills 中的 API 文档和脚本实现,与 IMA 官方无关。
安装
pip install ima-python-sdk
配置
SDK 需要 client_id 和 api_key 两个凭证,按以下优先级自动发现:
- 构造参数 —
ImaClient(client_id="...", api_key="...") - 环境变量 —
IMA_OPENAPI_CLIENTID/IMA_OPENAPI_APIKEY - 配置文件 —
~/.config/ima/client_id/~/.config/ima/api_key
CLI 使用
--kb_id 可通过环境变量 IMA_KB_ID 设置,避免每次手动指定。
# 知识库
ima-sdk kb addable
ima-sdk kb upload report.pdf --kb_id xxx # 上传到根目录
ima-sdk kb upload report.pdf 论文/机器学习 --kb_id xxx # 上传到指定目录
ima-sdk kb import-url https://example.com --kb_id xxx
# 笔记
ima-sdk note search "会议记录"
ima-sdk note create "# 标题"
ima-sdk note read <doc_id> --raw
SDK 使用
from ima_sdk import ImaClient, KnowledgeBaseManager, NotesManager
client = ImaClient() # 自动读取环境变量或配置文件
kb = KnowledgeBaseManager(client)
notes = NotesManager(client)
# 知识库操作
kb.upload_file("/path/to/report.pdf", knowledge_base_id="xxx")
kb.import_urls(["https://example.com"], knowledge_base_id="xxx")
results = kb.search_knowledge("关键词", knowledge_base_id="xxx")
# 笔记操作
doc_id = notes.create("# 标题\n\n正文内容")
docs, total, is_end = notes.search("会议记录")
content = notes.get_content(doc_id)
特性
- 零第三方依赖 — 仅使用 Python 标准库(urllib, hmac, hashlib, dataclasses)
- 凭证自动发现 — 构造参数 > 环境变量 > 配置文件,三级优先
- 自动翻页 — 列表接口支持
fetch_all=True - 完整上传流程 —
upload_file()一个方法完成预检、重名检查、创建媒体、COS 上传、添加知识 - UTF-8 安全 — 笔记写入前自动校验编码
License
MIT
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
ima_python_sdk-0.1.0.tar.gz
(23.0 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 ima_python_sdk-0.1.0.tar.gz.
File metadata
- Download URL: ima_python_sdk-0.1.0.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a137ee76e31f7a6257ca098f3cb6ba97ce983396839c28f49526f2a360624a10
|
|
| MD5 |
c28018f809c069d72261e34b15ef9c26
|
|
| BLAKE2b-256 |
c709571b18b188b687dc6c4d389815d6d6004a47b39aab0aebcc81141db49156
|
File details
Details for the file ima_python_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ima_python_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99ffb1c217fc173e4025f7acbdd4c76183e6fe5216b059665038ff80d19afdf
|
|
| MD5 |
9818907ccfdef9422660ab71c2386a12
|
|
| BLAKE2b-256 |
d3250c47bae88cf1f8479647bd29b991f067183fad4a64d77f6b3960f765ea64
|