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.2.tar.gz (8.1 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.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lydiacai_codeindex_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 8.1 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.2.tar.gz
Algorithm Hash digest
SHA256 f83fbcbdb6697c5400ee4968b876c42d3bd5d4e6810980cdd94d8592fbd99b38
MD5 9b8fc1a01c97ea15a17fee8e56b354d8
BLAKE2b-256 296b2681b8406c71fe40eed9636f33fdb0b56c4c3c57f1335c7e987d26ba07d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lydiacai_codeindex_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b49b92245293a40b2a60b3220203b02427a285752206b042a61d3b8d7479299b
MD5 ae118def973f5d21db62c1e88e8a79ba
BLAKE2b-256 2e0ca781d82e28ff93f2dde41176c9b5f505a14584d19f52e09c2520aae64e30

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