HugeGraph Python 客户端快速上手
hugegraph-python-client 是 Apache HugeGraph 的 Python SDK。它支持管理 Schema、读写图数据、执行 Gremlin 查询、进行 OLTP 实时图遍历以及
提交异步 OLAP 全图计算任务。HugeGraph-LLM 和 HugeGraph-ML 也依赖该客户端进行图数据库交互。
客户端源码位于 hugegraph-ai 仓库的 hugegraph-python-client/ 目录下,导入包名为 pyhugegraph。
环境要求
- Python >= 3.12(支持 Python 3.12–3.14)。
- HugeGraph Server 1.5.0 或更高版本(Server 1.7+ 推荐开启 GraphSpace 模式;1.5/1.6 使用传统路由)。
pip或uv包管理器。
运行时依赖包括 decorator、requests、urllib3 和 rich。
安装
客户端提供两种安装方式,具体取决于使用的是 PyPI 稳定发行版还是 master 分支最新的开发功能。
版本与功能边界说明:
已发布的 PyPI 发行包(hugegraph-python 1.7.x)为稳定基础版本,以 CamelCase 命名风格为主(带旧版 snake_case 别名)。
本文档演示的现代特性——包括原生 snake_case API、client.olap() 全图计算算法、client.task().wait() 任务轮询等待、
client.close() 连接生命周期管理以及更新后的遍历器签名——均对齐 master 分支最新实现。
如需体验或测试这些新特性,请通过源码方式安装客户端。
连接与数据写入
客户端初始化参数
PyHugeClient(url, graph, user, pwd, graphspace=None, timeout=None, *, token=None)
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
url | str | 必填 | HugeGraph Server 基础地址。若未携带协议前缀,会自动补齐 http://(例如 127.0.0.1:8080)。 |
graph | str | 必填 | 目标图实例名称,为第二个位置参数。 |
user | str | 必填 | 用户名,用于 HTTP Basic Auth 认证。 |
pwd | str | 必填 | 密码,用于 HTTP Basic Auth 认证。 |
graphspace | str 或 None | None | GraphSpace 名称。为 None 时通过版本探测自动决定路由。 |
timeout | float、tuple[float, float] 或 None | None | (connect, read) 超时秒数,或统一指定单个浮点数。默认值为 (0.5, 15.0)。 |
token | str 或 None | None | 显式指定 Bearer Token;提供时优先覆盖 Basic Auth 认证。 |
对于幂等请求,在收到 500、502、504 错误响应时最多重试 3 次(退避系数为 0.1)。异步任务轮询等待期间会自动管理截止时间预算,不额外触发重定向或 HTTP 重试。
服务端版本与 GraphSpace 路由
客户端在初始化阶段自动解析 GraphSpace 路由:
- 显式传入非空
graphspace时,直接启用对应的 GraphSpace 路由模式。 graphspace=None时,客户端向GET {url}/versions发起探测以获取服务端内核版本。- HugeGraph Server 1.7+ 默认启用 GraphSpace 并分配至
DEFAULT。 - HugeGraph Server 1.5 / 1.6 保持传统无 GraphSpace 路由。
- 低于 1.5.0 的版本不支持,初始化时会抛出
RuntimeError。 - 若版本探测失败且未显式指定 GraphSpace,客户端初始化将直接抛出异常,避免错误猜测服务端路由结构。
路由模式决定了服务端请求路径前缀:开启 GraphSpace 时为 /graphspaces/<graphspace>/graphs/<graph>/...,关闭时为 /graphs/<graph>/...。
客户端入口概览
PyHugeClient 实例维护全局共享的 HTTP Session。所有管理器均采用延迟加载并缓存复用:
| 访问入口 | 管理器类 | 功能范围 |
|---|---|---|
client.schema() | SchemaManager | 属性类型、顶点类型、边类型、索引类型管理 |
client.graph() | GraphManager | 顶点与边增删改查、批量写入、条件分页查询 |
client.gremlin() | GremlinManager | 执行 Gremlin 查询语句 |
client.traverser() | TraverserManager | 实时图遍历与路径查询(OLTP) |
client.rank() | RankManager | 实时个性化推荐排序(OLTP) |
client.olap() | OlapManager | 异步全图计算算法作业(OLAP) |
client.task() | TaskManager | 异步任务状态查询、结果轮询等待、任务取消与删除 |
client.graphs() | GraphsManager | 图元数据查看、配置导出、图列表、清空全图数据 |
client.graphspaces() | GraphspaceManager | 多图空间(GraphSpace)生命周期管理 |
client.schema_templates() | SchemaTemplateManager | 可复用 Schema 模板管理 |
client.auth() | AuthManager | 用户、用户组、目标资源、所属关系与权限管理 |
client.variable() | VariableManager | 图级别持久化键值变量 |
client.metrics() | MetricsManager | 服务端监控指标数据采集 |
client.version() | VersionManager | 服务端及各组件版本信息 |
client.rest() | RestClient | 底层 REST API 直接调用及扩展端点 |
常用操作
定义 Schema
Schema 构造器采用链式调用。调用 create() 执行创建,或使用 append()、eliminate()、remove() 修改已有定义:
查询 Schema
增删改查图数据
图数据 API 直接接收 Python 属性字典:
add_vertex 返回包含 id、label、type 与 properties 的 VertexData 实例。
add_edge 返回包含 id、label、type、outV、outVLabel、inV、inVLabel 与 properties 的 EdgeData 实例。
传入客户端的顶点 ID 可以是字符串、整数或 uuid.UUID 对象。布尔类型会被拦截拒绝,整数必须位于 Java 64 位有符号整型范围内。
批量导入数据
add_vertices 接收 (label, properties) 元组列表,add_edges 接收 (label, out_id, in_id, out_label, in_label, properties) 元组列表:
分页与条件查询
执行 Gremlin 查询
exec() 会根据图实例名称及解析出的 GraphSpace 自动绑定 graph 与 g 别名,并解析返回服务端响应中的 result 数据内容。
实时图遍历(OLTP)
client.traverser() 封装了服务端实时图遍历接口,支持多跳邻居、最短路径、共同邻居与相似度计算:
POST 方式的遍历接口支持复杂请求体:advanced_paths、customized_paths、template_paths、customized_crosspoints 以及 fusiform_similarity。
OLAP 全图计算任务
对于全图级别的重型计算算法(如 PageRank、Louvain 社区发现、中心度计算等),请使用 client.olap()。这些作业在服务端以异步任务方式运行并通过 Task ID 进行跟踪管理:
支持的 OLAP 算法
服务端提供了 17 个唯一的全图计算算法名称:
| 算法类别 | 具体算法名称 |
|---|---|
| 图统计 | count_edge、count_vertex、subgraph_stat、triangle_count、rings |
| 中心度 | betweenness_centrality、closeness_centrality、degree_centrality、eigenvector_centrality、stress_centrality |
| 社区与聚类 | cluster_coefficient、k_core、louvain、lpa、weak_connected_component |
| 排序与相似度 | page_rank、fusiform_similarity |
类似 page_rank 的算法会将计算出的权重属性回写到图中。在要求显式 Schema 声明的环境中,执行 PageRank 前需在参与计算的顶点类型上提前声明名为 r_rank 的可空 DOUBLE 属性。
任务生命周期管理
TaskManager 提供了对异步任务的完整管控能力:
wait(id, timeout=300, poll_interval=1)轮询期间仅查询任务状态而不拉取大体积结果,完成后再统一获取最终产出。TaskTimeoutError仅代表客户端轮询等待超时,服务端后台运行的任务作业不会被终止。- 如需强行终止服务端任务,请显式调用
cancel_task(id)。
图变量、监控与元数据
认证与权限控制
PyHugeClient 同时支持 HTTP Basic Auth 与 Bearer Token 认证:
AuthManager 支持在 GraphSpace 隔离下管理用户、用户组、目标资源、所属关系以及操作权限:
方法命名规范与迁移说明
- 推荐规范:新代码请统一使用
snake_case方法名(如add_vertex、property_key等)。 - 兼容保证:现有的公开 CamelCase 方法(如
addVertex、propertyKey等)作为直接别名持续得到兼容支持。 - 客户端生命周期:结束调用后请统一通过
client.close()释放连接池会话资源,无需单独关闭单个 manager。 - 返回契约:
- 传统快捷接口
get_all_graphs()、get_version()和get_graph_info()保持返回 JSON 字符串以维护向前兼容。 - 标准现代接口
client.graphs().list()、client.version().version()和client.graphs().get(graph_name)直接返回已解析的 Python 字典。 - 带权最短路径与单源最短路径方法不再支持
max_depth参数(服务端接口不支持);请使用capacity、max_degree和skip_degree参数进行限制。
- 传统快捷接口
底层 REST API 直接调用
对于批量原生接口调用或高级管理器尚未封装的扩展接口,可通过 client.rest() 直接访问完整 REST 接口面:
下表列出与服务端完全对齐的 194 个底层 REST 端点:
| Python REST entry | Method | Path | Query parameters |
|---|---|---|---|
rest.access.create() | POST | /graphspaces/{graphspace}/auth/accesses | — |
rest.access.delete() | DELETE | /graphspaces/{graphspace}/auth/accesses/{id} | — |
rest.access.get() | GET | /graphspaces/{graphspace}/auth/accesses/{id} | — |
rest.access.list() | GET | /graphspaces/{graphspace}/auth/accesses | group, target, limit |
rest.access.update() | PUT | /graphspaces/{graphspace}/auth/accesses/{id} | — |
rest.adamic_adar.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/adamicadar | vertex, other, direction, label, max_degree, limit |
rest.algorithm.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/jobs/algorithm/{name} | — |
rest.all_shortest_paths.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/allshortestpaths | source, target, direction, label, max_depth, max_degree, skip_degree, with_vertex, with_edge, capacity |
rest.arthas.start_arthas() | PUT | /arthas | — |
rest.belong.create() | POST | /graphspaces/{graphspace}/auth/belongs | — |
rest.belong.delete() | DELETE | /graphspaces/{graphspace}/auth/belongs/{id} | — |
rest.belong.get() | GET | /graphspaces/{graphspace}/auth/belongs/{id} | — |
rest.belong.list() | GET | /graphspaces/{graphspace}/auth/belongs | user, group, limit |
rest.belong.update() | PUT | /graphspaces/{graphspace}/auth/belongs/{id} | — |
rest.computer.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/jobs/computer/{name} | — |
rest.count.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/count | — |
rest.crosspoints.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/crosspoints | source, target, direction, label, max_depth, max_degree, capacity, limit |
rest.customized_crosspoints.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/customizedcrosspoints | — |
rest.customized_paths.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/customizedpaths | — |
rest.cypher.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/cypher | — |
rest.cypher.query() | GET | /graphspaces/{graphspace}/graphs/{graph}/cypher | cypher |
rest.edge.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/graph/edges | — |
rest.edge.create_batch() | POST | /graphspaces/{graphspace}/graphs/{graph}/graph/edges/batch | check_vertex |
rest.edge.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/graph/edges/{id} | label |
rest.edge.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/graph/edges/{id} | — |
rest.edge.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/graph/edges | vertex_id, direction, label, properties, keep_start_p, offset, page, limit |
rest.edge.update_batch() | PUT | /graphspaces/{graphspace}/graphs/{graph}/graph/edges/batch | — |
rest.edge.update_by_id() | PUT | /graphspaces/{graphspace}/graphs/{graph}/graph/edges/{id} | action |
rest.edge_existence.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/edgeexist | source, target, label, sort_values, limit |
rest.edge_label.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/schema/edgelabels | — |
rest.edge_label.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/schema/edgelabels/{name} | — |
rest.edge_label.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/edgelabels/{name} | — |
rest.edge_label.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/edgelabels | names |
rest.edge_label.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/schema/edgelabels/{name} | action |
rest.edges.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/edges | ids |
rest.edges.scan() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/edges/scan | start, end, page, page_limit |
rest.edges.shards() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/edges/shards | split_size |
rest.exception_trace.get() | GET | /exception/trace | — |
rest.exception_trace.trace() | PUT | /exception/trace | — |
rest.fusiform_similarity.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/fusiformsimilarity | — |
rest.graph_space.check_default_role() | GET | /graphspaces/{graphspace}/role | user, role, graph |
rest.graph_space.create() | POST | /graphspaces | — |
rest.graph_space.delete() | DELETE | /graphspaces/{name} | — |
rest.graph_space.delete_default_role() | DELETE | /graphspaces/{graphspace}/role | user, role, graph |
rest.graph_space.get() | GET | /graphspaces/{graphspace} | — |
rest.graph_space.list() | GET | /graphspaces | — |
rest.graph_space.list_profile() | GET | /graphspaces/profile | prefix |
rest.graph_space.manage() | PUT | /graphspaces/{name} | — |
rest.graph_space.set_default_role() | POST | /graphspaces/{graphspace}/role | — |
rest.graph_space_group.create() | POST | /graphspaces/{graphspace}/auth/groups | — |
rest.graph_space_group.delete() | DELETE | /graphspaces/{graphspace}/auth/groups/{id} | — |
rest.graph_space_group.get() | GET | /graphspaces/{graphspace}/auth/groups/{id} | — |
rest.graph_space_group.list() | GET | /graphspaces/{graphspace}/auth/groups | limit |
rest.graph_space_group.update() | PUT | /graphspaces/{graphspace}/auth/groups/{id} | — |
rest.graphs.clear() | DELETE | /graphspaces/{graphspace}/graphs/{name}/clear | confirm_message |
rest.graphs.clone_schema() | POST | /graphspaces/{graphspace}/graphs/{name}/schema-clone | source |
rest.graphs.compact() | PUT | /graphspaces/{graphspace}/graphs/{name}/compact | — |
rest.graphs.create() | POST | /graphspaces/{graphspace}/graphs/{name} | clone_graph_name |
rest.graphs.create_by_text() | POST | /graphspaces/{graphspace}/graphs/{name} | clone_graph_name |
rest.graphs.create_snapshot() | PUT | /graphspaces/{graphspace}/graphs/{name}/snapshot_create | — |
rest.graphs.drop() | DELETE | /graphspaces/{graphspace}/graphs/{name} | confirm_message |
rest.graphs.get() | GET | /graphspaces/{graphspace}/graphs/{name} | — |
rest.graphs.get_conf() | GET | /graphspaces/{graphspace}/graphs/{name}/conf | — |
rest.graphs.get_default() | GET | /graphspaces/{graphspace}/graphs/default | — |
rest.graphs.graph_read_mode_get() | GET | /graphspaces/{graphspace}/graphs/{name}/graph_read_mode | — |
rest.graphs.graph_read_mode_set() | PUT | /graphspaces/{graphspace}/graphs/{name}/graph_read_mode | — |
rest.graphs.list() | GET | /graphspaces/{graphspace}/graphs | — |
rest.graphs.list_profile() | GET | /graphspaces/{graphspace}/graphs/profile | prefix |
rest.graphs.loading_mode_get() | GET | /graphspaces/{graphspace}/graphs/{name}/mode/owners | — |
rest.graphs.loading_mode_set() | PUT | /graphspaces/{graphspace}/graphs/{name}/mode/owners | — |
rest.graphs.manage() | PUT | /graphspaces/{graphspace}/graphs/{name} | — |
rest.graphs.mode_get() | GET | /graphspaces/{graphspace}/graphs/{name}/mode | — |
rest.graphs.mode_set() | PUT | /graphspaces/{graphspace}/graphs/{name}/mode | — |
rest.graphs.reload() | PUT | /graphspaces/{graphspace}/graphs/manage | — |
rest.graphs.resume_snapshot() | PUT | /graphspaces/{graphspace}/graphs/{name}/snapshot_resume | — |
rest.graphs.set_default() | POST | /graphspaces/{graphspace}/graphs/{name}/default | — |
rest.graphs.unset_default() | DELETE | /graphspaces/{graphspace}/graphs/{name}/default | — |
rest.gremlin.get() | GET | /gremlin | gremlin, language; additional query map |
rest.gremlin.post() | POST | /gremlin | — |
rest.gremlin_job.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/jobs/gremlin | — |
rest.group.create() | POST | /auth/groups | — |
rest.group.delete() | DELETE | /auth/groups/{id} | — |
rest.group.get() | GET | /auth/groups/{id} | — |
rest.group.list() | GET | /auth/groups | limit |
rest.group.update() | PUT | /auth/groups/{id} | — |
rest.index_label.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/schema/indexlabels | — |
rest.index_label.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/schema/indexlabels/{name} | — |
rest.index_label.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/indexlabels/{name} | — |
rest.index_label.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/indexlabels | names |
rest.index_label.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/schema/indexlabels/{name} | action |
rest.jaccard_similarity.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/jaccardsimilarity | vertex, other, direction, label, max_degree |
rest.jaccard_similarity.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/jaccardsimilarity | — |
rest.kneighbor.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/kneighbor | source, direction, label, max_depth, count_only, max_degree, limit |
rest.kneighbor.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/kneighbor | — |
rest.kout.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/kout | source, direction, label, max_depth, nearest, count_only, max_degree, capacity, limit |
rest.kout.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/kout | — |
rest.login.login() | POST | /auth/login | — |
rest.login.logout() | DELETE | /auth/logout | — |
rest.login.verify_token() | GET | /auth/verify | — |
rest.manager.check_default_role() | GET | /graphspaces/{graphspace}/auth/managers/default | role, graph |
rest.manager.check_role() | GET | /graphspaces/{graphspace}/auth/managers/check | type |
rest.manager.create_manager() | POST | /graphspaces/{graphspace}/auth/managers | — |
rest.manager.delete() | DELETE | /graphspaces/{graphspace}/auth/managers | user, type |
rest.manager.get_roles_in_gs() | GET | /graphspaces/{graphspace}/auth/managers/role | user |
rest.manager.list() | GET | /graphspaces/{graphspace}/auth/managers | type |
rest.metrics.all() | GET | /metrics | type |
rest.metrics.backend() | GET | /metrics/backend | — |
rest.metrics.counters() | GET | /metrics/counters | — |
rest.metrics.gauges() | GET | /metrics/gauges | — |
rest.metrics.histograms() | GET | /metrics/histograms | — |
rest.metrics.meters() | GET | /metrics/meters | — |
rest.metrics.statistics() | GET | /metrics/statistics | type |
rest.metrics.system() | GET | /metrics/system | — |
rest.metrics.timers() | GET | /metrics/timers | — |
rest.multi_node_shortest_path.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/multinodeshortestpath | — |
rest.neighbor_rank.neighbor_rank() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/neighborrank | — |
rest.paths.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/paths | source, target, direction, label, max_depth, max_degree, capacity, limit |
rest.paths.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/paths | — |
rest.personal_rank.personal_rank() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/personalrank | — |
rest.profile.get_profile() | GET | / | — |
rest.profile.show_all_apis() | GET | /apis | — |
rest.project.create() | POST | /graphspaces/{graphspace}/auth/projects | — |
rest.project.delete() | DELETE | /graphspaces/{graphspace}/auth/projects/{id} | — |
rest.project.get() | GET | /graphspaces/{graphspace}/auth/projects/{id} | — |
rest.project.list() | GET | /graphspaces/{graphspace}/auth/projects | limit |
rest.project.update() | PUT | /graphspaces/{graphspace}/auth/projects/{id} | action |
rest.property_key.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/schema/propertykeys | — |
rest.property_key.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/schema/propertykeys/{name} | — |
rest.property_key.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/propertykeys/{name} | — |
rest.property_key.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/propertykeys | names |
rest.property_key.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/schema/propertykeys/{name} | action |
rest.raft.add_peer() | POST | /graphspaces/{graphspace}/graphs/{graph}/raft/add_peer | group, endpoint |
rest.raft.get_leader() | GET | /graphspaces/{graphspace}/graphs/{graph}/raft/get_leader | group |
rest.raft.list_peers() | GET | /graphspaces/{graphspace}/graphs/{graph}/raft/list_peers | group |
rest.raft.remove_peer() | POST | /graphspaces/{graphspace}/graphs/{graph}/raft/remove_peer | group, endpoint |
rest.raft.set_leader() | POST | /graphspaces/{graphspace}/graphs/{graph}/raft/set_leader | group, endpoint |
rest.raft.transfer_leader() | POST | /graphspaces/{graphspace}/graphs/{graph}/raft/transfer_leader | group, endpoint |
rest.rays.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/rays | source, direction, label, max_depth, max_degree, capacity, limit, with_vertex, with_edge |
rest.rebuild.edge_label_rebuild() | PUT | /graphspaces/{graphspace}/graphs/{graph}/jobs/rebuild/edgelabels/{name} | — |
rest.rebuild.index_label_rebuild() | PUT | /graphspaces/{graphspace}/graphs/{graph}/jobs/rebuild/indexlabels/{name} | — |
rest.rebuild.vertex_label_rebuild() | PUT | /graphspaces/{graphspace}/graphs/{graph}/jobs/rebuild/vertexlabels/{name} | — |
rest.resource_allocation.create() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/resourceallocation | vertex, other, direction, label, max_degree, limit |
rest.rings.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/rings | source, direction, label, max_depth, source_in_ring, max_degree, capacity, limit, with_vertex, with_edge |
rest.same_neighbors.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/sameneighbors | vertex, other, direction, label, max_degree, limit |
rest.same_neighbors.same_neighbors() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/sameneighbors | — |
rest.same_neighbors_batch.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/sameneighborsbatch | — |
rest.schema.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema | — |
rest.schema_template.create() | POST | /graphspaces/{graphspace}/schematemplates | — |
rest.schema_template.delete() | DELETE | /graphspaces/{graphspace}/schematemplates/{name} | — |
rest.schema_template.get() | GET | /graphspaces/{graphspace}/schematemplates/{name} | — |
rest.schema_template.list() | GET | /graphspaces/{graphspace}/schematemplates | — |
rest.schema_template.update() | PUT | /graphspaces/{graphspace}/schematemplates/{name} | — |
rest.shortest_path.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/shortestpath | source, target, direction, label, max_depth, max_degree, skip_degree, with_vertex, with_edge, capacity |
rest.single_source_shortest_path.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/singlesourceshortestpath | source, direction, label, weight, max_degree, skip_degree, with_vertex, with_edge, capacity, limit |
rest.target.create() | POST | /graphspaces/{graphspace}/auth/targets | — |
rest.target.delete() | DELETE | /graphspaces/{graphspace}/auth/targets/{id} | — |
rest.target.get() | GET | /graphspaces/{graphspace}/auth/targets/{id} | — |
rest.target.list() | GET | /graphspaces/{graphspace}/auth/targets | limit |
rest.target.update() | PUT | /graphspaces/{graphspace}/auth/targets/{id} | — |
rest.task.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/tasks/{id} | force |
rest.task.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/tasks/{id} | with_result |
rest.task.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/tasks | status, ids, limit, page |
rest.task.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/tasks/{id} | action |
rest.template_paths.post() | POST | /graphspaces/{graphspace}/graphs/{graph}/traversers/templatepaths | — |
rest.user.create() | POST | /graphspaces/{graphspace}/auth/users | — |
rest.user.delete() | DELETE | /graphspaces/{graphspace}/auth/users/{id} | — |
rest.user.get() | GET | /graphspaces/{graphspace}/auth/users/{id} | — |
rest.user.list() | GET | /graphspaces/{graphspace}/auth/users | name, limit |
rest.user.role() | GET | /graphspaces/{graphspace}/auth/users/{id}/role | — |
rest.user.update() | PUT | /graphspaces/{graphspace}/auth/users/{id} | — |
rest.variables.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/variables/{key} | — |
rest.variables.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/variables/{key} | — |
rest.variables.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/variables | — |
rest.variables.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/variables/{key} | — |
rest.version.list() | GET | /versions | — |
rest.vertex.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices | — |
rest.vertex.create_batch() | POST | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices/batch | — |
rest.vertex.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices/{id} | label |
rest.vertex.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices/{id} | — |
rest.vertex.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices | label, properties, keep_start_p, offset, page, limit |
rest.vertex.update_batch() | PUT | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices/batch | — |
rest.vertex.update_by_id() | PUT | /graphspaces/{graphspace}/graphs/{graph}/graph/vertices/{id} | action |
rest.vertex_label.create() | POST | /graphspaces/{graphspace}/graphs/{graph}/schema/vertexlabels | — |
rest.vertex_label.delete() | DELETE | /graphspaces/{graphspace}/graphs/{graph}/schema/vertexlabels/{name} | — |
rest.vertex_label.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/vertexlabels/{name} | — |
rest.vertex_label.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/schema/vertexlabels | names |
rest.vertex_label.update() | PUT | /graphspaces/{graphspace}/graphs/{graph}/schema/vertexlabels/{name} | action |
rest.vertices.list() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/vertices | ids |
rest.vertices.scan() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/vertices/scan | start, end, page, page_limit |
rest.vertices.shards() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/vertices/shards | split_size |
rest.weighted_shortest_path.get() | GET | /graphspaces/{graphspace}/graphs/{graph}/traversers/weightedshortestpath | source, target, direction, label, weight, max_degree, skip_degree, with_vertex, with_edge, capacity |
rest.white_ip_list.list() | GET | /whiteiplist | — |
rest.white_ip_list.update_status() | PUT | /whiteiplist | status |
rest.white_ip_list.update_white_ips() | POST | /whiteiplist | — |
异常处理
常见异常定义位于 pyhugegraph.utils.exceptions:
| 异常类型 | 触发场景 |
|---|---|
NotAuthorizedError | 服务端返回 HTTP 401 未认证 |
NotFoundError | 服务端返回 HTTP 404 资源未找到 |
ServerError | 服务端返回非 2xx 响应(附带服务端错误详情) |
ResponseParseError | 响应内容无法反序列化为预期格式 |
ServiceUnavailableError | 服务端暂时不可用 |
InvalidParameterError, CreateError, RemoveError, UpdateError, DataFormatError | 客户端本地参数或格式校验失败 |
敏感参数(密码、Token、密钥等)在日志输出中会自动脱敏处理。
开发与测试验证
在 HugeGraph-AI 仓库根目录下执行代码规范与测试套件:
代码格式化与静态检查:
运行单元测试与契约测试:
针对正在运行的 HugeGraph Server 执行集成测试:
主线 CI 默认使用 hugegraph/hugegraph:latest 镜像进行集成验证,并对 1.7.0 执行兼容回归。源码与测试位于 hugegraph-python-client/src/pyhugegraph/ 和 hugegraph-python-client/src/tests/。