# hugegraph-utils **Repository Path**: the_machine/hugegraph-utils ## Basic Information - **Project Name**: hugegraph-utils - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-13 - **Last Updated**: 2021-03-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Python API for HugeGraph Restful server ------------------------------------------- This package is a wrapper for HugeGraph Restful API.
See https://hugegraph.github.io/hugegraph-doc/clients/hugegraph-api.html for details. There are four important interface/object to interact with hugegraph server: - **connection**: A HugeGraphRESTConnection created by given connection configurations, i.e. host, port, and graph. Ojbects below are accessible from this obejct. - **schema**: create, edit, and remove vertex/edge/index labels. - **graph**: interact with verex and edges in the graph. - **gremlin_manager**: run gremlin queries. ## 1. Graph Schema Create schema object ```python from hugegraph_utils.api import HugeGraphRESTConnection conn = HugeGraphRESTConnection(port='8080', host='localhost', graph='hugegraph') schema = conn.schema() ``` ### 1.1 Property key ```python schema.listProertyKey() schema.propertyKey('age').asInt().valueList().create() schema.propertyKey('age').remove() schema.getPropertyKey('age') schema.getPropertyKey('age').dataType() ``` ### 1.2 Vertex Label ```python schema.listVertexLabel() schema.vertexLabel('person').useCustomizeNumberId().properties(['name']).nullableKeys(['name']).ifNotExist().create() schema.getVertexLabel('person').remove() schema.getVertexLabel('person').primaryKeys() ``` ### 1.3 Edge Label ```python schema.edgeLabel("knows").link("person", "person").properties("date").ifNotExist().create() schema.edgeLabel("knows").remove() ``` ### 1.4 Index Label ```python schema.indexLabel('personByAge').onV('person').by('age').range().ifNotExist().create() schema.indexLabel('personByAge').remove() ``` ## 2. Graph ```python from hugegraph_utils.api import HugeGraphRESTConnection from hugegraph_utils.api import T from hugegraph_utils.api import Vertex from hugegraph_utils.api import Edge conn = HugeGraphRESTConnection(port='8080', host='localhost', graph='hugegraph') schema = conn.schema() graph = conn.graph() ``` ### 2.1 Vertex and Edges ```python # Create vertex v1 = graph.addVertex(T.label, 'person', 'name', 'leon', 'age', 35, T.id, 'reese') v2 = graph.addVertex(T.label, 'person', 'name', 'chris', 'age', 40, T.id, 'finch') ada = Graph('person').property('name', 'ada') vertices = graph.addVertices([v3]) # Create edges e1 = leon.addEdge('knows', ada) edges = [ Edge('knows').source(vs[0]).target(vs[1]) ] edges = graph.addEdges(edges) # Remove vertices and edges e1.remove() v1.remove() ``` ## 3. Gremlin ```python from hugegraph_utils.api import HugeGraphRESTConnection from hugegraph_utils.api import GremlinManager conn = HugeGraphRESTConnection(port='8080', host='localhost', graph='hugegraph') g = GremlinManager() r = g.run('g.V()').toObject() r = g.run('g.E()').raw() ```