Skip to content

Commit 48e47f4

Browse files
authored
v3 (#12)
* Support for IndraDB v3 * Upgrade deps * Test for property indexing * Bump version
1 parent e510b63 commit 48e47f4

File tree

10 files changed

+1121
-285
lines changed

10 files changed

+1121
-285
lines changed

indradb/client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import itertools
44

55
import grpc
6-
import indradb.indradb_pb2 as indradb_proto
76
import indradb.indradb_pb2_grpc as indradb_grpc
87

98
from .models import Vertex, Edge, VertexProperty, EdgeProperty, VertexProperties, EdgeProperties
@@ -34,9 +33,13 @@ def __init__(self, host="localhost:27615"):
3433
self.stub = indradb_grpc.IndraDBStub(channel)
3534

3635
def ping(self):
37-
req = indradb_proto.google_dot_protobuf_dot_empty__pb2.Empty()
36+
req = proto.google_dot_protobuf_dot_empty__pb2.Empty()
3837
return self.stub.Ping(req)
3938

39+
def index_property(self, name):
40+
req = proto.IndexPropertyRequest(name=proto.Identifier(value=name))
41+
return self.stub.IndexProperty(req)
42+
4043
def create_vertex(self, vertex):
4144
"""
4245
Creates a new vertex.
@@ -195,15 +198,15 @@ def edge(self, key):
195198
def vertex_property(self, id, name, value):
196199
self._add_req(vertex_property=proto.VertexPropertyBulkInsertItem(
197200
id=proto.Uuid(value=id.bytes),
198-
name=name,
201+
name=proto.Identifier(value=name),
199202
value=proto.Json(value=json.dumps(value)),
200203
))
201204
return self
202205

203206
def edge_property(self, key, name, value):
204207
self._add_req(edge_property=proto.EdgePropertyBulkInsertItem(
205208
key=key.to_message(),
206-
name=name,
209+
name=proto.Identifier(value=name),
207210
value=proto.Json(value=json.dumps(value)),
208211
))
209212
return self
@@ -229,13 +232,13 @@ def create_vertex(self, vertex):
229232
self._add_req(create_vertex=vertex.to_message())
230233
return self
231234

232-
def create_vertex_from_type(self, type):
235+
def create_vertex_from_type(self, t):
233236
"""
234237
Creates a new vertex from a type.
235238
236-
`type` specifies the new vertex's type.
239+
`t` specifies the new vertex's type.
237240
"""
238-
self._add_req(create_vertex_from_type=proto.Type(value=type))
241+
self._add_req(create_vertex_from_type=proto.Identifier(value=t))
239242
return self
240243

241244
def get_vertices(self, query):
@@ -260,7 +263,7 @@ def get_vertex_count(self):
260263
"""
261264
Gets the total number of vertices in the datastore.
262265
"""
263-
self._add_req(get_vertex_count=indradb_proto.google_dot_protobuf_dot_empty__pb2.Empty())
266+
self._add_req(get_vertex_count=proto.google_dot_protobuf_dot_empty__pb2.Empty())
264267
return self
265268

266269
def create_edge(self, key):
@@ -300,7 +303,7 @@ def get_edge_count(self, id, t, direction):
300303
"""
301304
self._add_req(get_edge_count=proto.GetEdgeCountRequest(
302305
id=proto.Uuid(value=id.bytes),
303-
t=proto.Type(value=t) if t is not None else None,
306+
t=proto.Identifier(value=t) if t is not None else None,
304307
direction=direction.value,
305308
))
306309
return self

indradb/indradb_pb2.py

Lines changed: 804 additions & 184 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

indradb/indradb_pb2_grpc.py

Lines changed: 201 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,215 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
23
import grpc
34

45
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
56
import indradb.indradb_pb2 as indradb__pb2
67

78

89
class IndraDBStub(object):
9-
# missing associated documentation comment in .proto file
10-
pass
11-
12-
def __init__(self, channel):
13-
"""Constructor.
14-
15-
Args:
16-
channel: A grpc.Channel.
17-
"""
18-
self.Ping = channel.unary_unary(
19-
'/indradb.IndraDB/Ping',
20-
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
21-
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
22-
)
23-
self.BulkInsert = channel.stream_unary(
24-
'/indradb.IndraDB/BulkInsert',
25-
request_serializer=indradb__pb2.BulkInsertItem.SerializeToString,
26-
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
27-
)
28-
self.Transaction = channel.stream_stream(
29-
'/indradb.IndraDB/Transaction',
30-
request_serializer=indradb__pb2.TransactionRequest.SerializeToString,
31-
response_deserializer=indradb__pb2.TransactionResponse.FromString,
32-
)
10+
"""Missing associated documentation comment in .proto file."""
11+
12+
def __init__(self, channel):
13+
"""Constructor.
14+
15+
Args:
16+
channel: A grpc.Channel.
17+
"""
18+
self.Ping = channel.unary_unary(
19+
'/indradb.IndraDB/Ping',
20+
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
21+
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
22+
)
23+
self.Sync = channel.unary_unary(
24+
'/indradb.IndraDB/Sync',
25+
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
26+
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
27+
)
28+
self.BulkInsert = channel.stream_unary(
29+
'/indradb.IndraDB/BulkInsert',
30+
request_serializer=indradb__pb2.BulkInsertItem.SerializeToString,
31+
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
32+
)
33+
self.Transaction = channel.stream_stream(
34+
'/indradb.IndraDB/Transaction',
35+
request_serializer=indradb__pb2.TransactionRequest.SerializeToString,
36+
response_deserializer=indradb__pb2.TransactionResponse.FromString,
37+
)
38+
self.IndexProperty = channel.unary_unary(
39+
'/indradb.IndraDB/IndexProperty',
40+
request_serializer=indradb__pb2.IndexPropertyRequest.SerializeToString,
41+
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
42+
)
3343

3444

3545
class IndraDBServicer(object):
36-
# missing associated documentation comment in .proto file
37-
pass
38-
39-
def Ping(self, request, context):
40-
# missing associated documentation comment in .proto file
41-
pass
42-
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
43-
context.set_details('Method not implemented!')
44-
raise NotImplementedError('Method not implemented!')
45-
46-
def BulkInsert(self, request_iterator, context):
47-
# missing associated documentation comment in .proto file
48-
pass
49-
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
50-
context.set_details('Method not implemented!')
51-
raise NotImplementedError('Method not implemented!')
52-
53-
def Transaction(self, request_iterator, context):
54-
# missing associated documentation comment in .proto file
55-
pass
56-
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
57-
context.set_details('Method not implemented!')
58-
raise NotImplementedError('Method not implemented!')
46+
"""Missing associated documentation comment in .proto file."""
47+
48+
def Ping(self, request, context):
49+
"""Pings the server.
50+
"""
51+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
52+
context.set_details('Method not implemented!')
53+
raise NotImplementedError('Method not implemented!')
54+
55+
def Sync(self, request, context):
56+
"""Syncs persisted content. Depending on the datastore implementation,
57+
this has different meanings - including potentially being a no-op.
58+
"""
59+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
60+
context.set_details('Method not implemented!')
61+
raise NotImplementedError('Method not implemented!')
62+
63+
def BulkInsert(self, request_iterator, context):
64+
"""Bulk inserts many vertices, edges, and/or properties.
65+
66+
Note that datastores have discretion on how to approach safeguard vs
67+
performance tradeoffs. In particular:
68+
* If the datastore is disk-backed, it may or may not flush before
69+
returning.
70+
* The datastore might not verify for correctness; e.g., it might not
71+
ensure that the relevant vertices exist before inserting an edge.
72+
If you want maximum protection, use the equivalent functions in
73+
transactions, which will provide more safeguards.
74+
"""
75+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
76+
context.set_details('Method not implemented!')
77+
raise NotImplementedError('Method not implemented!')
78+
79+
def Transaction(self, request_iterator, context):
80+
"""Runs a transaction.
81+
"""
82+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
83+
context.set_details('Method not implemented!')
84+
raise NotImplementedError('Method not implemented!')
85+
86+
def IndexProperty(self, request, context):
87+
"""Enables indexing on a specified property. When indexing is enabled on a
88+
property, it's possible to query on its presence and values.
89+
"""
90+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
91+
context.set_details('Method not implemented!')
92+
raise NotImplementedError('Method not implemented!')
5993

6094

6195
def add_IndraDBServicer_to_server(servicer, server):
62-
rpc_method_handlers = {
63-
'Ping': grpc.unary_unary_rpc_method_handler(
64-
servicer.Ping,
65-
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
66-
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
67-
),
68-
'BulkInsert': grpc.stream_unary_rpc_method_handler(
69-
servicer.BulkInsert,
70-
request_deserializer=indradb__pb2.BulkInsertItem.FromString,
71-
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
72-
),
73-
'Transaction': grpc.stream_stream_rpc_method_handler(
74-
servicer.Transaction,
75-
request_deserializer=indradb__pb2.TransactionRequest.FromString,
76-
response_serializer=indradb__pb2.TransactionResponse.SerializeToString,
77-
),
78-
}
79-
generic_handler = grpc.method_handlers_generic_handler(
80-
'indradb.IndraDB', rpc_method_handlers)
81-
server.add_generic_rpc_handlers((generic_handler,))
96+
rpc_method_handlers = {
97+
'Ping': grpc.unary_unary_rpc_method_handler(
98+
servicer.Ping,
99+
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
100+
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
101+
),
102+
'Sync': grpc.unary_unary_rpc_method_handler(
103+
servicer.Sync,
104+
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
105+
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
106+
),
107+
'BulkInsert': grpc.stream_unary_rpc_method_handler(
108+
servicer.BulkInsert,
109+
request_deserializer=indradb__pb2.BulkInsertItem.FromString,
110+
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
111+
),
112+
'Transaction': grpc.stream_stream_rpc_method_handler(
113+
servicer.Transaction,
114+
request_deserializer=indradb__pb2.TransactionRequest.FromString,
115+
response_serializer=indradb__pb2.TransactionResponse.SerializeToString,
116+
),
117+
'IndexProperty': grpc.unary_unary_rpc_method_handler(
118+
servicer.IndexProperty,
119+
request_deserializer=indradb__pb2.IndexPropertyRequest.FromString,
120+
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
121+
),
122+
}
123+
generic_handler = grpc.method_handlers_generic_handler(
124+
'indradb.IndraDB', rpc_method_handlers)
125+
server.add_generic_rpc_handlers((generic_handler,))
126+
127+
128+
# This class is part of an EXPERIMENTAL API.
129+
class IndraDB(object):
130+
"""Missing associated documentation comment in .proto file."""
131+
132+
@staticmethod
133+
def Ping(request,
134+
target,
135+
options=(),
136+
channel_credentials=None,
137+
call_credentials=None,
138+
insecure=False,
139+
compression=None,
140+
wait_for_ready=None,
141+
timeout=None,
142+
metadata=None):
143+
return grpc.experimental.unary_unary(request, target, '/indradb.IndraDB/Ping',
144+
google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
145+
google_dot_protobuf_dot_empty__pb2.Empty.FromString,
146+
options, channel_credentials,
147+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
148+
149+
@staticmethod
150+
def Sync(request,
151+
target,
152+
options=(),
153+
channel_credentials=None,
154+
call_credentials=None,
155+
insecure=False,
156+
compression=None,
157+
wait_for_ready=None,
158+
timeout=None,
159+
metadata=None):
160+
return grpc.experimental.unary_unary(request, target, '/indradb.IndraDB/Sync',
161+
google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
162+
google_dot_protobuf_dot_empty__pb2.Empty.FromString,
163+
options, channel_credentials,
164+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
165+
166+
@staticmethod
167+
def BulkInsert(request_iterator,
168+
target,
169+
options=(),
170+
channel_credentials=None,
171+
call_credentials=None,
172+
insecure=False,
173+
compression=None,
174+
wait_for_ready=None,
175+
timeout=None,
176+
metadata=None):
177+
return grpc.experimental.stream_unary(request_iterator, target, '/indradb.IndraDB/BulkInsert',
178+
indradb__pb2.BulkInsertItem.SerializeToString,
179+
google_dot_protobuf_dot_empty__pb2.Empty.FromString,
180+
options, channel_credentials,
181+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
182+
183+
@staticmethod
184+
def Transaction(request_iterator,
185+
target,
186+
options=(),
187+
channel_credentials=None,
188+
call_credentials=None,
189+
insecure=False,
190+
compression=None,
191+
wait_for_ready=None,
192+
timeout=None,
193+
metadata=None):
194+
return grpc.experimental.stream_stream(request_iterator, target, '/indradb.IndraDB/Transaction',
195+
indradb__pb2.TransactionRequest.SerializeToString,
196+
indradb__pb2.TransactionResponse.FromString,
197+
options, channel_credentials,
198+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
199+
200+
@staticmethod
201+
def IndexProperty(request,
202+
target,
203+
options=(),
204+
channel_credentials=None,
205+
call_credentials=None,
206+
insecure=False,
207+
compression=None,
208+
wait_for_ready=None,
209+
timeout=None,
210+
metadata=None):
211+
return grpc.experimental.unary_unary(request, target, '/indradb.IndraDB/IndexProperty',
212+
indradb__pb2.IndexPropertyRequest.SerializeToString,
213+
google_dot_protobuf_dot_empty__pb2.Empty.FromString,
214+
options, channel_credentials,
215+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

0 commit comments

Comments
 (0)