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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lydiacai_codeindex_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d32c01a7db071f27230c5566e9006e47f7d5728e160653a991aaad9d0890519
MD5 a978eeb909d10adf3ae30a9fd5658fe3
BLAKE2b-256 df9cdd9c9d342b5386a7904d95747f31510ba266a446afbd5a43f1e513cfd2ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lydiacai_codeindex_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fef57a667bdf8fa81d581d48dce7b9df00f56805cb82b9e9ff61036cc5d0d17f
MD5 b2c16b98faec0923e408ee75133f6f80
BLAKE2b-256 2758171348a365032df2c021667c2cf9b4529e64a649ac114aa2b6e4f2637368

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