This is the multi-page printable view of this section. .
HugeGraph Client
The Java and Go clients are maintained in the HugeGraph Toolchain repository, while the Python client is maintained in the HugeGraph-AI repository. Their installation methods and APIs differ; see the corresponding pages for details.
1 - HugeGraph-Java-Client
1 Overview
HugeGraph Java Client translates Java APIs into REST requests to HugeGraph Server. It supports managing schemas and graph data, executing Gremlin queries, and calling Traverser APIs. See the Client API for detailed interfaces; this page shows how to use the client in a Java project.
For other languages, use the Go Client or the Python Client maintained in the HugeGraph-AI repository.
2 What You Need
- JDK 11 (used by the current CI; the source target remains Java 8)
- Maven 3.6+
3 How To Use
The basic steps to use HugeGraph-Client are as follows:
- Build a new Maven project by IDEA or Eclipse
- Add HugeGraph-Client dependency in a pom file;
- Create an object to invoke the interface of HugeGraph-Client
See the complete example in the following section for the detail.
4 Complete Example
4.1 Build New Maven Project
Using IDEA or Eclipse to create the project:
4.2 Add Hugegraph-Client Dependency In POM
Development versions of the client and server may differ. Check the corresponding release notes for compatibility before upgrading.
4.3 Example
4.3.1 SingleExample
4.3.2 BatchExample
4.4 Run The Example
Before running Example, you need to start the Server. For the startup process, seeHugeGraph-Server Quick Start.
4.5 More Information About Client-API
2 - HugeGraph Python Client Quick Start
hugegraph-python-client is the Python SDK for HugeGraph. It manages schemas, reads and writes graph data, and executes Gremlin queries. HugeGraph-LLM and HugeGraph-ML also use this client.
The module lives in the hugegraph-ai repository under hugegraph-python-client/. The import name is pyhugegraph.
Requirements
- Python 3.9 or later for the client itself. The HugeGraph-AI workspace requires Python 3.10 or later, and CI runs the client tests on 3.10 and 3.11.
- HugeGraph Server 1.5.0 or later. The client refuses to connect to older servers; use client v1.3.x for those.
uv(recommended) orpip
Runtime dependencies are decorator, requests, setuptools, urllib3 and rich.
Installation
The released package is published on PyPI as hugegraph-python:
The PyPI release lags behind the repository. In the source tree the distribution is declared as
hugegraph-python-clientand versioned with the rest of HugeGraph-AI, so install from source if you need the newest code.
To use the latest repository code, sync the workspace from the root of the HugeGraph-AI repository. hugegraph-python-client is a workspace member exposed through the python-client extra, so plain uv sync does not pull it in:
Connect and Write Data
Client Parameters
PyHugeClient(url, graph, user, pwd, graphspace=None, timeout=None)
| Parameter | Type | Default | Description |
|---|---|---|---|
url | str | required | Base URL of HugeGraph Server. If the value has no scheme, http:// is prepended, so 127.0.0.1:8080 also works. |
graph | str | required | Graph name. This is the second positional parameter. |
user | str | required | Username, sent as HTTP basic auth. |
pwd | str | required | Password, sent as HTTP basic auth. |
graphspace | str or None | None | GraphSpace name. See below for how None is resolved. |
timeout | tuple[float, float] or None | None | (connect, read) timeouts in seconds. None becomes (0.5, 15.0). |
Every HTTP session retries three times with a 0.1 backoff factor on 500, 502 and 504 responses.
Server Version and GraphSpace
The client resolves GraphSpace at construction time:
- A non-empty
graphspacestring turns GraphSpace mode on directly. - Otherwise the client sends
GET {url}/versionsand readsversions.core. - A server older than 1.5.0 raises
RuntimeErrorasking you to upgrade the server or use client v1.3.x. - A server newer than 1.5.0 gets
graphspaceset toDEFAULTand GraphSpace mode turned on, with a warning in the log. A server at exactly 1.5.0 keeps GraphSpace mode off. - If the probe fails for network reasons, GraphSpace mode stays off.
The mode decides the request prefix: /graphspaces/<graphspace>/graphs/<graph>/... when GraphSpace is on, /graphs/<graph>/... when it is off.
Managers on the Client
Each accessor builds its manager lazily and gives it a dedicated HTTP session.
| Accessor | Manager | Covers |
|---|---|---|
client.schema() | SchemaManager | Property keys, vertex labels, edge labels, index labels |
client.graph() | GraphManager | Vertex and edge CRUD, batch writes, paging |
client.gremlin() | GremlinManager | Gremlin execution |
client.graphs() | GraphsManager | Graph list, graph info, config, clear data |
client.traverser() | TraverserManager | Traversal and path algorithms |
client.variable() | VariableManager | Graph variables |
client.task() | TaskManager | Async task list, query, cancel, delete |
client.auth() | AuthManager | Users, groups, targets, belongs, accesses |
client.metrics() | MetricsManager | Server metrics |
client.version() | VersionManager | Server version |
RankManager, RebuildManager and ServicesManager also ship in pyhugegraph.api, but PyHugeClient does not expose accessors for them yet; construct them directly with a session if you need them.
Common Operations
Build the Schema
The schema builders are fluent. Call create() last, or append(), eliminate() and remove() to change an existing definition.
Query the Schema
Read, Update and Delete Graph Data
The graph API takes property dictionaries, not chained property builders:
addVertex returns a VertexData with id, label, type and properties. addEdge returns an EdgeData with id, label, type, outV, outVLabel, inV, inVLabel and properties.
Vertex ids passed to the client may be strings, integers or uuid.UUID values. Booleans are rejected, and integers must fit the Java signed long range.
Batch Writes
addVertices takes (label, properties) pairs, and addEdges takes (label, out_id, in_id, out_label, in_label, properties) tuples. Both return objects that carry only the generated ids.
Paging and Conditional Queries
Execute Gremlin
exec binds the graph and g aliases for you, based on the graph name and the resolved GraphSpace, and returns the result field of the server response. A response missing requestId, status or result raises ResponseParseError.
Traverse the Graph
TraverserManager wraps the server traverser endpoints. Its methods use snake_case.
The POST-based variants take request bodies: advanced_paths, customized_paths, template_paths, customized_crosspoints and fusiform_similarity.
Graph Variables
Async Tasks
Server Metrics and Graph Info
Authentication and Authorization
AuthManager follows the server routing: users, targets, belongs and accesses are mounted under /graphspaces/{graphspace}/auth/..., while groups stay at the server-level /auth/groups. On HugeGraph 1.7.0 and later a graphspace must be resolved, otherwise these calls raise ValueError before any request is sent.
Method Naming
Manager methods written in camelCase, such as addVertex and getVertexById, also get a snake_case alias generated at construction time. graph.add_vertex(...) and graph.addVertex(...) reach the same method. The camelCase spellings are marked deprecated in the debug log, so prefer snake_case in new code.
Error Handling
Exceptions live in pyhugegraph.utils.exceptions:
| Exception | Raised when |
|---|---|
NotAuthorizedError | The server answers 401 |
NotFoundError | The server answers 404, or a required argument is missing |
ServerError | Any other non-2xx response, with the server message attached |
ResponseParseError | A successful response cannot be parsed into the expected shape |
ServiceUnavailableError | The server reports ServiceUnavailableException |
InvalidParameterError, CreateError, RemoveError, UpdateError, DataFormatError | Raised by individual builders and structures |
Request and response bodies are logged with password, token and secret values redacted.
API parameters may change with the HugeGraph REST API version. If an interface is incompatible, first check the REST API documentation for the current server version and the client test cases.
Development Checks
Run formatting and static checks from the root of the HugeGraph-AI repository:
Run the tests the same way CI does:
CI runs the integration job against the hugegraph/hugegraph:1.7.0 image. HUGEGRAPH_GRAPHSPACE is also read when you need a non-default space.
The source code and tests are under hugegraph-python-client/src/pyhugegraph/ and hugegraph-python-client/src/tests/. A runnable example is at hugegraph-python-client/src/pyhugegraph/example/hugegraph_example.py.
3 - HugeGraph Go Client Quick Start
HugeGraph Go Client is the Go SDK in the Toolchain repository. It currently provides APIs for version queries, schemas (property keys, vertex labels, and edge labels), vertices, and Gremlin. An edge data API is not implemented yet.
This module is still under development. Refer to the source code under
hugegraph-client-go/api/v1for the currently available interfaces.
Requirements
- Go 1.19 or later
- An accessible HugeGraph Server; examples use
http://127.0.0.1:8080
Installation
Run the following command in a Go module project:
Initialize the Client
NewCommonClient requires Host to be an IP address and Port to be between 1 and 65535. The client always connects over plain HTTP. Leave the username and password empty when authentication is disabled; Basic Auth is sent only when both are set.
GraphSpace is applied only by the Vertex API, which then calls /graphspaces/{space}/graphs/{graph}/..., and by the default Gremlin aliases (an empty value is treated as DEFAULT). The schema entry points and Version() always call /graphs/{graph}/... and /versions, regardless of GraphSpace. Use DEFAULT for the default space; leaving GraphSpace empty makes the Vertex API fall back to the /graphs/{graph} path used by older servers.
The Versions value returned by Version() includes the HugeGraph Server, Core, Gremlin, and REST API versions. The NewDefaultCommonClient() helper in the source connects to the hugegraph graph at 127.0.0.1:8080 with admin/pa authentication and a ColorLogger that prints every request and response body. Production code should normally pass an explicit configuration instead.
Configuration Options
hugegraph.Config has the following fields:
| Field | Type | Description |
|---|---|---|
Host | string | HugeGraph Server IP address. Host names are rejected. |
Port | int | HugeGraph Server REST port, 1 to 65535 |
GraphSpace | string | Graph space; only used by the Vertex API and the default Gremlin aliases. Set an empty string when not needed. |
Graph | string | Graph name configured on the server |
Username | string | Server username; empty string when authentication is disabled |
Password | string | Server password; empty string when authentication is disabled |
Transport | http.RoundTripper | Custom HTTP transport; http.DefaultTransport when nil |
Logger | hgtransport.Logger | Request/response logger; no logging when nil |
The hgtransport package ships four loggers: TextLogger (plain text), ColorLogger (terminal colors), CurlLogger (runnable curl commands), and JSONLogger (JSON lines). Each has the same fields: Output (an io.Writer), EnableRequestBody, and EnableResponseBody.
Available Entry Points
CommonClient currently exposes the following entry points:
| Entry point | Purpose |
|---|---|
Version() | Query the server version |
Schema() | Query the complete schema |
Propertykey | Create, GetAll, GetByName, UpdateUserdata, DeleteByName |
VertexLabel | Create, GetAll, GetByName, UpdateUserdata, DeleteByName |
EdgeLabel | Create, GetAll, DeleteByName |
Vertex | Create, BatchCreate, UpdateProperties (with WithAction: append or eliminate) |
Gremlin | Get and Post. Post defaults language to gremlin-groovy, fills the graph/g aliases from GraphSpace and Graph, and returns the parsed result in Data. Get only returns the status code and prints the raw response to stdout. |
Each operation takes functional options named With... on the operation itself, for example client.Gremlin.Post.WithGremlin(...) or client.Propertykey.GetByName.WithName(...).
The
Vertexoperations takemodel.Vertex[any]values from theinternal/modelpackage. Go does not allow importing aninternalpackage from another module, so at the moment theVertexAPI can only be called from code inside the client module itself; its test file is also fully commented out.
For complete usage, see the tests in each API directory, such as version_test.go, gemlin_test.go, and vertexlabel_test.go.