Skip to main content

CodeIndex 的官方 Python SDK,内置 Node Worker 以便直接查询索引

Project description

CodeIndex Python SDK(内置 Node Worker)

该 SDK 旨在让 Python 用户通过 pip install 的方式,直接访问 CodeIndex 已有的索引与查询能力。实现思路是在 SDK 内部维护一个透明的 Node Worker(使用本仓库构建产物),Python 端仅暴露同步 API。

安装

从 PyPI 安装(推荐)

# 使用阿里云镜像源(推荐,速度更快)
pip install -i https://mirrors.aliyun.com/pypi/simple/ lydiacai-codeindex-sdk

# 或使用官方 PyPI 源
pip install lydiacai-codeindex-sdk

本地开发安装

  1. 构建 CodeIndex:在仓库根目录执行
    npm install
    npm run build
    
    这样会生成 dist/,Python Worker 需要加载其中的 index.js
  2. Python 依赖:进入 sdk/python,安装本地包
    pip install -e .
    
  3. Node 运行时:确保系统可执行 node(>= 18)。

快速上手

from codeindex_sdk import CodeIndexClient, CodeIndexConfig

config = CodeIndexConfig(
    root_dir="/path/to/project",
    db_path=".codeindex/project.db",
    languages=["go", "ts"],
)

with CodeIndexClient(config) as client:
    symbols = client.find_symbols(name="BindRepoReq", language="go")
    props = client.object_properties(object_name="Giter", language="go")
    chain = client.call_chain(from_symbol=12345, direction="forward", depth=2)

工作原理

  • CodeIndexClient 会在首次调用时自动启动一个 Node Worker(worker_server.js),Worker 内部复用 CodeIndex 类加载索引数据库。
  • Python 与 Worker 之间通过 JSON-RPC(基于 stdin/stdout)通信,所有请求同步发送。
  • 如果 Worker 故障,客户端会抛出异常;你可以捕获后重新实例化客户端。

常见问题

  • Node 未安装CodeIndexClient 会在启动 Worker 时检测 node,若找不到会抛出 NodeRuntimeError
  • 索引未构建:请先使用 CLI node dist/src/cli/index.js index ... 建立 .db 文件。
  • 长时间任务:可以通过 timeout 参数控制每次请求的最大等待时间。

后续计划

  • 支持 gRPC/HTTP Worker,降低进程通信耦合。
  • 增加异步 API 与批量查询能力。

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

lydiacai_codeindex_sdk-0.1.4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

lydiacai_codeindex_sdk-0.1.4-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file lydiacai_codeindex_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: lydiacai_codeindex_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for lydiacai_codeindex_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a8ea9cbd626c35c129e8f92b7d34bad6e05b27754cd90f1a206e46e2bf2d9253
MD5 be774df3a3151160c63391edebfb0fc7
BLAKE2b-256 ca49ba50907b97e697badce48acbfe9481c55fe3c297f3b09b815e3cd8851f81

See more details on using hashes here.

File details

Details for the file lydiacai_codeindex_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for lydiacai_codeindex_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8539f1100abcf24c2fa2defc0ef574440d340620528101a5491b86502dba064a
MD5 89312bc8c8f51d8a028e0cf0bc42a4cb
BLAKE2b-256 ce1fbc0239023f2b1c55643625068b0e0ca3849c6143c8ec9567ea75b51313b6

See more details on using hashes here.

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