diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 4445bac..ac6ea40 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -20,7 +20,7 @@ lint: ignore: - linters: [ALL] paths: - - pydgraph/proto/api_pb*.py + - pydgraph/proto/*_pb2*.py enabled: - trivy@0.59.1 diff --git a/pydgraph/client.py b/pydgraph/client.py index 47bcf27..6d8ef02 100755 --- a/pydgraph/client.py +++ b/pydgraph/client.py @@ -11,6 +11,20 @@ from pydgraph import errors, txn, util from pydgraph.meta import VERSION from pydgraph.proto import api_pb2 as api +from pydgraph.proto import api_v2_pb2 as api_v2 +from pydgraph.proto.api_v2_pb2 import ( + AllocateIDsRequest, +) +from pydgraph.proto.api_v2_pb2 import AlterRequest as AlterRequestV2 +from pydgraph.proto.api_v2_pb2 import ( + CreateNamespaceRequest, + DropNamespaceRequest, + ListNamespacesRequest, + RunDQLRequest, + SignInUserRequest, + UpdateExtSnapshotStreamingStateRequest, + UpdateNamespaceRequest, +) __author__ = "Mohit Ranka " __maintainer__ = "Hypermode Inc. " @@ -130,6 +144,337 @@ def alter(self, operation, timeout=None, metadata=None, credentials=None): else: self._common_except_alter(error) + def ping(self, timeout=None, metadata=None, credentials=None): + """Runs a ping via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = api_v2.PingRequest() + try: + return self.any_client().ping( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().ping( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def allocate_ids( + self, how_many, lease_type, timeout=None, metadata=None, credentials=None + ): + """Runs an AllocateIDs via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = AllocateIDsRequest(how_many=how_many, lease_type=lease_type) + try: + return self.any_client().allocate_ids( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().allocate_ids( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def sign_in_user( + self, + user_id, + password, + refresh_token=None, + timeout=None, + metadata=None, + credentials=None, + ): + """Runs a SignInUser via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = SignInUserRequest( + user_id=user_id, password=password, refresh_token=refresh_token + ) + try: + return self.any_client().sign_in_user( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().sign_in_user( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def alter_v2( + self, + op, + ns_name=None, + schema=None, + run_in_background=False, + predicate_to_drop=None, + type_to_drop=None, + timeout=None, + metadata=None, + credentials=None, + ): + """Runs an Alter (v2) via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = AlterRequestV2( + op=op, + ns_name=ns_name, + schema=schema, + run_in_background=run_in_background, + predicate_to_drop=predicate_to_drop, + type_to_drop=type_to_drop, + ) + try: + return self.any_client().alter_v2( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().alter_v2( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def run_dql( + self, + dql_query, + ns_name=None, + vars=None, + read_only=False, + best_effort=False, + resp_format=api_v2.RespFormat.JSON, + timeout=None, + metadata=None, + credentials=None, + ): + """Runs a RunDQL via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = RunDQLRequest( + dql_query=dql_query, + ns_name=ns_name, + vars=vars, + read_only=read_only, + best_effort=best_effort, + resp_format=resp_format, + ) + try: + return self.any_client().run_dql( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().run_dql( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def create_namespace(self, ns_name, timeout=None, metadata=None, credentials=None): + """Runs a CreateNamespace via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = CreateNamespaceRequest(ns_name=ns_name) + try: + return self.any_client().create_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().create_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def drop_namespace(self, ns_name, timeout=None, metadata=None, credentials=None): + """Runs a DropNamespace via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = DropNamespaceRequest(ns_name=ns_name) + try: + return self.any_client().drop_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().drop_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def update_namespace( + self, ns_name, rename_to_ns, timeout=None, metadata=None, credentials=None + ): + """Runs an UpdateNamespace via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = UpdateNamespaceRequest(ns_name=ns_name, rename_to_ns=rename_to_ns) + try: + return self.any_client().update_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().update_namespace( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def list_namespaces(self, timeout=None, metadata=None, credentials=None): + """Runs a ListNamespaces via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = ListNamespacesRequest() + try: + return self.any_client().list_namespaces( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().list_namespaces( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def update_ext_snapshot_streaming_state( + self, + start=False, + finish=False, + drop_data=False, + timeout=None, + metadata=None, + credentials=None, + ): + """Runs an UpdateExtSnapshotStreamingState via this client.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + req = UpdateExtSnapshotStreamingStateRequest( + start=start, finish=finish, drop_data=drop_data + ) + try: + return self.any_client().update_ext_snapshot_streaming_state( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + if util.is_jwt_expired(error): + self.retry_login() + new_metadata = self.add_login_metadata(metadata) + return self.any_client().update_ext_snapshot_streaming_state( + req, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + else: + raise error + + def stream_ext_snapshot( + self, request_iterator, timeout=None, metadata=None, credentials=None + ): + """Runs a StreamExtSnapshot via this client. This is a client-streaming RPC. + The caller is responsible for handling JWT expiry and retries for this streaming call. + """ + """Note this is only supported on Dgraph v25.0.0 and above.""" + new_metadata = self.add_login_metadata(metadata) + try: + # The underlying gRPC stub expects an iterator for client-streaming RPCs. + return self.any_client().stream_ext_snapshot( + request_iterator, + timeout=timeout, + metadata=new_metadata, + credentials=credentials, + ) + except Exception as error: + # JWT retry logic is not implemented for streaming calls as it's non-trivial. + # The stream would be broken on error anyway. + self._common_except_alter(error) + @staticmethod def _common_except_alter(error): if util.is_retriable_error(error): @@ -142,6 +487,7 @@ def _common_except_alter(error): def async_alter(self, operation, timeout=None, metadata=None, credentials=None): """The async version of alter.""" + """Note this is only supported on Dgraph v25.0.0 and above.""" new_metadata = self.add_login_metadata(metadata) return self.any_client().async_alter( operation, timeout=timeout, metadata=new_metadata, credentials=credentials diff --git a/pydgraph/client_stub.py b/pydgraph/client_stub.py index da432db..80b8480 100644 --- a/pydgraph/client_stub.py +++ b/pydgraph/client_stub.py @@ -3,10 +3,14 @@ """Stub for RPC request.""" +import logging + import grpc +from pydgraph.errors import V2NotSupportedError from pydgraph.meta import VERSION from pydgraph.proto import api_pb2_grpc as api_grpc +from pydgraph.proto import api_v2_pb2_grpc as api_v2_grpc try: from urllib.parse import urlparse @@ -29,6 +33,7 @@ def __init__(self, addr="localhost:9080", credentials=None, options=None): self.channel = grpc.secure_channel(addr, credentials, options) self.stub = api_grpc.DgraphStub(self.channel) + self.stub_v2 = api_v2_grpc.DgraphStub(self.channel) def login(self, login_req, timeout=None, metadata=None, credentials=None): return self.stub.Login( @@ -71,14 +76,138 @@ def check_version(self, check, timeout=None, metadata=None, credentials=None): check, timeout=timeout, metadata=metadata, credentials=credentials ) + def ping(self, req, timeout=None, metadata=None, credentials=None): + """Runs ping operation.""" + try: + return self.stub_v2.Ping( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def allocate_ids(self, req, timeout=None, metadata=None, credentials=None): + """Runs AllocateIDs operation.""" + try: + return self.stub_v2.AllocateIDs( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def sign_in_user(self, req, timeout=None, metadata=None, credentials=None): + """Runs SignInUser operation.""" + try: + return self.stub_v2.SignInUser( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def alter_v2(self, req, timeout=None, metadata=None, credentials=None): + """Runs Alter operation.""" + try: + return self.stub_v2.Alter( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def run_dql(self, req, timeout=None, metadata=None, credentials=None): + """Runs RunDQL operation.""" + try: + return self.stub_v2.RunDQL( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def create_namespace(self, req, timeout=None, metadata=None, credentials=None): + """Runs CreateNamespace operation.""" + try: + return self.stub_v2.CreateNamespace( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def drop_namespace(self, req, timeout=None, metadata=None, credentials=None): + """Runs DropNamespace operation.""" + try: + return self.stub_v2.DropNamespace( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def update_namespace(self, req, timeout=None, metadata=None, credentials=None): + """Runs UpdateNamespace operation.""" + try: + return self.stub_v2.UpdateNamespace( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def list_namespaces(self, req, timeout=None, metadata=None, credentials=None): + """Runs ListNamespaces operation.""" + try: + return self.stub_v2.ListNamespaces( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def update_ext_snapshot_streaming_state( + self, req, timeout=None, metadata=None, credentials=None + ): + """Runs UpdateExtSnapshotStreamingState operation.""" + try: + return self.stub_v2.UpdateExtSnapshotStreamingState( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + + def stream_ext_snapshot(self, req, timeout=None, metadata=None, credentials=None): + """Runs StreamExtSnapshot operation.""" + try: + return self.stub_v2.StreamExtSnapshot( + req, timeout=timeout, metadata=metadata, credentials=credentials + ) + except grpc.RpcError as e: + if e.code() == grpc.StatusCode.UNIMPLEMENTED: + raise V2NotSupportedError() from e + raise + def close(self): """Deletes channel and stub.""" try: self.channel.close() - except: - pass + except Exception: + logging.debug("Failed to close gRPC channel, ignoring.", exc_info=True) del self.channel del self.stub + del self.stub_v2 @staticmethod def parse_host(cloud_endpoint): diff --git a/pydgraph/errors.py b/pydgraph/errors.py index 57c218c..7603f7e 100644 --- a/pydgraph/errors.py +++ b/pydgraph/errors.py @@ -43,3 +43,12 @@ class TransactionError(Exception): def __init__(self, msg): super(TransactionError, self).__init__(msg) + + +class V2NotSupportedError(Exception): + """Error thrown when a v2 API is called on a server that doesn't support it.""" + + def __init__(self): + super(V2NotSupportedError, self).__init__( + "The Dgraph server does not support v2 API calls. Please upgrade your Dgraph instance." + ) diff --git a/pydgraph/meta.py b/pydgraph/meta.py index 5336ef2..2ce27c4 100644 --- a/pydgraph/meta.py +++ b/pydgraph/meta.py @@ -3,4 +3,4 @@ """Metadata about this package.""" -VERSION = "24.3.0" +VERSION = "25.0.0" diff --git a/pydgraph/proto/api.proto b/pydgraph/proto/api.proto index 78df31b..d4397a8 100644 --- a/pydgraph/proto/api.proto +++ b/pydgraph/proto/api.proto @@ -12,7 +12,7 @@ syntax = "proto3"; package api; -option go_package = "github.com/dgraph-io/dgo/v240/protos/api"; +option go_package = "github.com/dgraph-io/dgo/v250/protos/api"; option java_package = "io.dgraph"; option java_outer_classname = "DgraphProto"; diff --git a/pydgraph/proto/api_pb2.py b/pydgraph/proto/api_pb2.py index 413f23b..bb1aede 100644 --- a/pydgraph/proto/api_pb2.py +++ b/pydgraph/proto/api_pb2.py @@ -14,14 +14,14 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tapi.proto\x12\x03\x61pi\"\xb8\x02\n\x07Request\x12\x10\n\x08start_ts\x18\x01 \x01(\x04\x12\r\n\x05query\x18\x04 \x01(\t\x12$\n\x04vars\x18\x05 \x03(\x0b\x32\x16.api.Request.VarsEntry\x12\x11\n\tread_only\x18\x06 \x01(\x08\x12\x13\n\x0b\x62\x65st_effort\x18\x07 \x01(\x08\x12 \n\tmutations\x18\x0c \x03(\x0b\x32\r.api.Mutation\x12\x12\n\ncommit_now\x18\r \x01(\x08\x12,\n\x0bresp_format\x18\x0e \x01(\x0e\x32\x17.api.Request.RespFormat\x12\x0c\n\x04hash\x18\x0f \x01(\t\x1a+\n\tVarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x1f\n\nRespFormat\x12\x08\n\x04JSON\x10\x00\x12\x07\n\x03RDF\x10\x01\"\x14\n\x04Uids\x12\x0c\n\x04uids\x18\x01 \x03(\t\"\x1d\n\x0cListOfString\x12\r\n\x05value\x18\x01 \x03(\t\"\xbc\x02\n\x08Response\x12\x0c\n\x04json\x18\x01 \x01(\x0c\x12\x1c\n\x03txn\x18\x02 \x01(\x0b\x32\x0f.api.TxnContext\x12\x1d\n\x07latency\x18\x03 \x01(\x0b\x32\x0c.api.Latency\x12\x1d\n\x07metrics\x18\x04 \x01(\x0b\x32\x0c.api.Metrics\x12%\n\x04uids\x18\x0c \x03(\x0b\x32\x17.api.Response.UidsEntry\x12\x0b\n\x03rdf\x18\r \x01(\x0c\x12%\n\x04hdrs\x18\x0e \x03(\x0b\x32\x17.api.Response.HdrsEntry\x1a+\n\tUidsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a>\n\tHdrsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12 \n\x05value\x18\x02 \x01(\x0b\x32\x11.api.ListOfString:\x02\x38\x01\"\xad\x01\n\x08Mutation\x12\x10\n\x08set_json\x18\x01 \x01(\x0c\x12\x13\n\x0b\x64\x65lete_json\x18\x02 \x01(\x0c\x12\x12\n\nset_nquads\x18\x03 \x01(\x0c\x12\x12\n\ndel_nquads\x18\x04 \x01(\x0c\x12\x17\n\x03set\x18\x05 \x03(\x0b\x32\n.api.NQuad\x12\x17\n\x03\x64\x65l\x18\x06 \x03(\x0b\x32\n.api.NQuad\x12\x0c\n\x04\x63ond\x18\t \x01(\t\x12\x12\n\ncommit_now\x18\x0e \x01(\x08\"\xd2\x01\n\tOperation\x12\x0e\n\x06schema\x18\x01 \x01(\t\x12\x11\n\tdrop_attr\x18\x02 \x01(\t\x12\x10\n\x08\x64rop_all\x18\x03 \x01(\x08\x12&\n\x07\x64rop_op\x18\x04 \x01(\x0e\x32\x15.api.Operation.DropOp\x12\x12\n\ndrop_value\x18\x05 \x01(\t\x12\x19\n\x11run_in_background\x18\x06 \x01(\x08\"9\n\x06\x44ropOp\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41LL\x10\x01\x12\x08\n\x04\x44\x41TA\x10\x02\x12\x08\n\x04\x41TTR\x10\x03\x12\x08\n\x04TYPE\x10\x04\"\x17\n\x07Payload\x12\x0c\n\x04\x44\x61ta\x18\x01 \x01(\x0c\"m\n\nTxnContext\x12\x10\n\x08start_ts\x18\x01 \x01(\x04\x12\x11\n\tcommit_ts\x18\x02 \x01(\x04\x12\x0f\n\x07\x61\x62orted\x18\x03 \x01(\x08\x12\x0c\n\x04keys\x18\x04 \x03(\t\x12\r\n\x05preds\x18\x05 \x03(\t\x12\x0c\n\x04hash\x18\x06 \x01(\t\"\x07\n\x05\x43heck\"\x16\n\x07Version\x12\x0b\n\x03tag\x18\x01 \x01(\t\"x\n\x07Latency\x12\x12\n\nparsing_ns\x18\x01 \x01(\x04\x12\x15\n\rprocessing_ns\x18\x02 \x01(\x04\x12\x13\n\x0b\x65ncoding_ns\x18\x03 \x01(\x04\x12\x1b\n\x13\x61ssign_timestamp_ns\x18\x04 \x01(\x04\x12\x10\n\x08total_ns\x18\x05 \x01(\x04\"f\n\x07Metrics\x12+\n\x08num_uids\x18\x01 \x03(\x0b\x32\x19.api.Metrics.NumUidsEntry\x1a.\n\x0cNumUidsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x04:\x02\x38\x01\"\xa3\x01\n\x05NQuad\x12\x0f\n\x07subject\x18\x01 \x01(\t\x12\x11\n\tpredicate\x18\x02 \x01(\t\x12\x11\n\tobject_id\x18\x03 \x01(\t\x12 \n\x0cobject_value\x18\x04 \x01(\x0b\x32\n.api.Value\x12\x0c\n\x04lang\x18\x06 \x01(\t\x12\x1a\n\x06\x66\x61\x63\x65ts\x18\x07 \x03(\x0b\x32\n.api.Facet\x12\x11\n\tnamespace\x18\x08 \x01(\x04J\x04\x08\x05\x10\x06\"\xa4\x02\n\x05Value\x12\x15\n\x0b\x64\x65\x66\x61ult_val\x18\x01 \x01(\tH\x00\x12\x13\n\tbytes_val\x18\x02 \x01(\x0cH\x00\x12\x11\n\x07int_val\x18\x03 \x01(\x03H\x00\x12\x12\n\x08\x62ool_val\x18\x04 \x01(\x08H\x00\x12\x11\n\x07str_val\x18\x05 \x01(\tH\x00\x12\x14\n\ndouble_val\x18\x06 \x01(\x01H\x00\x12\x11\n\x07geo_val\x18\x07 \x01(\x0cH\x00\x12\x12\n\x08\x64\x61te_val\x18\x08 \x01(\x0cH\x00\x12\x16\n\x0c\x64\x61tetime_val\x18\t \x01(\x0cH\x00\x12\x16\n\x0cpassword_val\x18\n \x01(\tH\x00\x12\x11\n\x07uid_val\x18\x0b \x01(\x04H\x00\x12\x16\n\x0c\x62igfloat_val\x18\x0c \x01(\x0cH\x00\x12\x16\n\x0cvfloat32_val\x18\r \x01(\x0cH\x00\x42\x05\n\x03val\"\xab\x01\n\x05\x46\x61\x63\x65t\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x0c\x12$\n\x08val_type\x18\x03 \x01(\x0e\x32\x12.api.Facet.ValType\x12\x0e\n\x06tokens\x18\x04 \x03(\t\x12\r\n\x05\x61lias\x18\x05 \x01(\t\"A\n\x07ValType\x12\n\n\x06STRING\x10\x00\x12\x07\n\x03INT\x10\x01\x12\t\n\x05\x46LOAT\x10\x02\x12\x08\n\x04\x42OOL\x10\x03\x12\x0c\n\x08\x44\x41TETIME\x10\x04\"Z\n\x0cLoginRequest\x12\x0e\n\x06userid\x18\x01 \x01(\t\x12\x10\n\x08password\x18\x02 \x01(\t\x12\x15\n\rrefresh_token\x18\x03 \x01(\t\x12\x11\n\tnamespace\x18\x04 \x01(\x04\".\n\x03Jwt\x12\x12\n\naccess_jwt\x18\x01 \x01(\t\x12\x13\n\x0brefresh_jwt\x18\x02 \x01(\t2\xe7\x01\n\x06\x44graph\x12+\n\x05Login\x12\x11.api.LoginRequest\x1a\r.api.Response\"\x00\x12&\n\x05Query\x12\x0c.api.Request\x1a\r.api.Response\"\x00\x12\'\n\x05\x41lter\x12\x0e.api.Operation\x1a\x0c.api.Payload\"\x00\x12\x33\n\rCommitOrAbort\x12\x0f.api.TxnContext\x1a\x0f.api.TxnContext\"\x00\x12*\n\x0c\x43heckVersion\x12\n.api.Check\x1a\x0c.api.Version\"\x00\x42\x42\n\tio.dgraphB\x0b\x44graphProtoZ(github.com/dgraph-io/dgo/v240/protos/apib\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\tapi.proto\x12\x03\x61pi\"\xb8\x02\n\x07Request\x12\x10\n\x08start_ts\x18\x01 \x01(\x04\x12\r\n\x05query\x18\x04 \x01(\t\x12$\n\x04vars\x18\x05 \x03(\x0b\x32\x16.api.Request.VarsEntry\x12\x11\n\tread_only\x18\x06 \x01(\x08\x12\x13\n\x0b\x62\x65st_effort\x18\x07 \x01(\x08\x12 \n\tmutations\x18\x0c \x03(\x0b\x32\r.api.Mutation\x12\x12\n\ncommit_now\x18\r \x01(\x08\x12,\n\x0bresp_format\x18\x0e \x01(\x0e\x32\x17.api.Request.RespFormat\x12\x0c\n\x04hash\x18\x0f \x01(\t\x1a+\n\tVarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x1f\n\nRespFormat\x12\x08\n\x04JSON\x10\x00\x12\x07\n\x03RDF\x10\x01\"\x14\n\x04Uids\x12\x0c\n\x04uids\x18\x01 \x03(\t\"\x1d\n\x0cListOfString\x12\r\n\x05value\x18\x01 \x03(\t\"\xbc\x02\n\x08Response\x12\x0c\n\x04json\x18\x01 \x01(\x0c\x12\x1c\n\x03txn\x18\x02 \x01(\x0b\x32\x0f.api.TxnContext\x12\x1d\n\x07latency\x18\x03 \x01(\x0b\x32\x0c.api.Latency\x12\x1d\n\x07metrics\x18\x04 \x01(\x0b\x32\x0c.api.Metrics\x12%\n\x04uids\x18\x0c \x03(\x0b\x32\x17.api.Response.UidsEntry\x12\x0b\n\x03rdf\x18\r \x01(\x0c\x12%\n\x04hdrs\x18\x0e \x03(\x0b\x32\x17.api.Response.HdrsEntry\x1a+\n\tUidsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a>\n\tHdrsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12 \n\x05value\x18\x02 \x01(\x0b\x32\x11.api.ListOfString:\x02\x38\x01\"\xad\x01\n\x08Mutation\x12\x10\n\x08set_json\x18\x01 \x01(\x0c\x12\x13\n\x0b\x64\x65lete_json\x18\x02 \x01(\x0c\x12\x12\n\nset_nquads\x18\x03 \x01(\x0c\x12\x12\n\ndel_nquads\x18\x04 \x01(\x0c\x12\x17\n\x03set\x18\x05 \x03(\x0b\x32\n.api.NQuad\x12\x17\n\x03\x64\x65l\x18\x06 \x03(\x0b\x32\n.api.NQuad\x12\x0c\n\x04\x63ond\x18\t \x01(\t\x12\x12\n\ncommit_now\x18\x0e \x01(\x08\"\xd2\x01\n\tOperation\x12\x0e\n\x06schema\x18\x01 \x01(\t\x12\x11\n\tdrop_attr\x18\x02 \x01(\t\x12\x10\n\x08\x64rop_all\x18\x03 \x01(\x08\x12&\n\x07\x64rop_op\x18\x04 \x01(\x0e\x32\x15.api.Operation.DropOp\x12\x12\n\ndrop_value\x18\x05 \x01(\t\x12\x19\n\x11run_in_background\x18\x06 \x01(\x08\"9\n\x06\x44ropOp\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03\x41LL\x10\x01\x12\x08\n\x04\x44\x41TA\x10\x02\x12\x08\n\x04\x41TTR\x10\x03\x12\x08\n\x04TYPE\x10\x04\"\x17\n\x07Payload\x12\x0c\n\x04\x44\x61ta\x18\x01 \x01(\x0c\"m\n\nTxnContext\x12\x10\n\x08start_ts\x18\x01 \x01(\x04\x12\x11\n\tcommit_ts\x18\x02 \x01(\x04\x12\x0f\n\x07\x61\x62orted\x18\x03 \x01(\x08\x12\x0c\n\x04keys\x18\x04 \x03(\t\x12\r\n\x05preds\x18\x05 \x03(\t\x12\x0c\n\x04hash\x18\x06 \x01(\t\"\x07\n\x05\x43heck\"\x16\n\x07Version\x12\x0b\n\x03tag\x18\x01 \x01(\t\"x\n\x07Latency\x12\x12\n\nparsing_ns\x18\x01 \x01(\x04\x12\x15\n\rprocessing_ns\x18\x02 \x01(\x04\x12\x13\n\x0b\x65ncoding_ns\x18\x03 \x01(\x04\x12\x1b\n\x13\x61ssign_timestamp_ns\x18\x04 \x01(\x04\x12\x10\n\x08total_ns\x18\x05 \x01(\x04\"f\n\x07Metrics\x12+\n\x08num_uids\x18\x01 \x03(\x0b\x32\x19.api.Metrics.NumUidsEntry\x1a.\n\x0cNumUidsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x04:\x02\x38\x01\"\xa3\x01\n\x05NQuad\x12\x0f\n\x07subject\x18\x01 \x01(\t\x12\x11\n\tpredicate\x18\x02 \x01(\t\x12\x11\n\tobject_id\x18\x03 \x01(\t\x12 \n\x0cobject_value\x18\x04 \x01(\x0b\x32\n.api.Value\x12\x0c\n\x04lang\x18\x06 \x01(\t\x12\x1a\n\x06\x66\x61\x63\x65ts\x18\x07 \x03(\x0b\x32\n.api.Facet\x12\x11\n\tnamespace\x18\x08 \x01(\x04J\x04\x08\x05\x10\x06\"\xa4\x02\n\x05Value\x12\x15\n\x0b\x64\x65\x66\x61ult_val\x18\x01 \x01(\tH\x00\x12\x13\n\tbytes_val\x18\x02 \x01(\x0cH\x00\x12\x11\n\x07int_val\x18\x03 \x01(\x03H\x00\x12\x12\n\x08\x62ool_val\x18\x04 \x01(\x08H\x00\x12\x11\n\x07str_val\x18\x05 \x01(\tH\x00\x12\x14\n\ndouble_val\x18\x06 \x01(\x01H\x00\x12\x11\n\x07geo_val\x18\x07 \x01(\x0cH\x00\x12\x12\n\x08\x64\x61te_val\x18\x08 \x01(\x0cH\x00\x12\x16\n\x0c\x64\x61tetime_val\x18\t \x01(\x0cH\x00\x12\x16\n\x0cpassword_val\x18\n \x01(\tH\x00\x12\x11\n\x07uid_val\x18\x0b \x01(\x04H\x00\x12\x16\n\x0c\x62igfloat_val\x18\x0c \x01(\x0cH\x00\x12\x16\n\x0cvfloat32_val\x18\r \x01(\x0cH\x00\x42\x05\n\x03val\"\xab\x01\n\x05\x46\x61\x63\x65t\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x0c\x12$\n\x08val_type\x18\x03 \x01(\x0e\x32\x12.api.Facet.ValType\x12\x0e\n\x06tokens\x18\x04 \x03(\t\x12\r\n\x05\x61lias\x18\x05 \x01(\t\"A\n\x07ValType\x12\n\n\x06STRING\x10\x00\x12\x07\n\x03INT\x10\x01\x12\t\n\x05\x46LOAT\x10\x02\x12\x08\n\x04\x42OOL\x10\x03\x12\x0c\n\x08\x44\x41TETIME\x10\x04\"Z\n\x0cLoginRequest\x12\x0e\n\x06userid\x18\x01 \x01(\t\x12\x10\n\x08password\x18\x02 \x01(\t\x12\x15\n\rrefresh_token\x18\x03 \x01(\t\x12\x11\n\tnamespace\x18\x04 \x01(\x04\".\n\x03Jwt\x12\x12\n\naccess_jwt\x18\x01 \x01(\t\x12\x13\n\x0brefresh_jwt\x18\x02 \x01(\t2\xe7\x01\n\x06\x44graph\x12+\n\x05Login\x12\x11.api.LoginRequest\x1a\r.api.Response\"\x00\x12&\n\x05Query\x12\x0c.api.Request\x1a\r.api.Response\"\x00\x12\'\n\x05\x41lter\x12\x0e.api.Operation\x1a\x0c.api.Payload\"\x00\x12\x33\n\rCommitOrAbort\x12\x0f.api.TxnContext\x1a\x0f.api.TxnContext\"\x00\x12*\n\x0c\x43heckVersion\x12\n.api.Check\x1a\x0c.api.Version\"\x00\x42\x42\n\tio.dgraphB\x0b\x44graphProtoZ(github.com/dgraph-io/dgo/v250/protos/apib\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'api_pb2', _globals) if not _descriptor._USE_C_DESCRIPTORS: _globals['DESCRIPTOR']._loaded_options = None - _globals['DESCRIPTOR']._serialized_options = b'\n\tio.dgraphB\013DgraphProtoZ(github.com/dgraph-io/dgo/v240/protos/api' + _globals['DESCRIPTOR']._serialized_options = b'\n\tio.dgraphB\013DgraphProtoZ(github.com/dgraph-io/dgo/v250/protos/api' _globals['_REQUEST_VARSENTRY']._loaded_options = None _globals['_REQUEST_VARSENTRY']._serialized_options = b'8\001' _globals['_RESPONSE_UIDSENTRY']._loaded_options = None diff --git a/pydgraph/proto/api_v2.proto b/pydgraph/proto/api_v2.proto new file mode 100644 index 0000000..6886242 --- /dev/null +++ b/pydgraph/proto/api_v2.proto @@ -0,0 +1,186 @@ +/* + * SPDX-FileCopyrightText: © Hypermode Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +// Style guide for Protocol Buffer 3. +// Use CamelCase (with an initial capital) for message names – for example, +// SongServerRequest. Use underscore_separated_names for field names – for +// example, song_name. + +syntax = "proto3"; + +package api.v2; + +option go_package = "github.com/dgraph-io/dgo/v250/protos/api.v2"; + +option java_package = "io.dgraph.v2"; +option java_outer_classname = "DgraphProto"; + +service Dgraph { + rpc Ping(PingRequest) returns (PingResponse) {} + rpc AllocateIDs(AllocateIDsRequest) returns (AllocateIDsResponse) {} + + rpc SignInUser(SignInUserRequest) returns (SignInUserResponse) {} + rpc Alter(AlterRequest) returns (AlterResponse) {} + rpc RunDQL(RunDQLRequest) returns (RunDQLResponse) {} + + rpc CreateNamespace(CreateNamespaceRequest) returns (CreateNamespaceResponse) {} + rpc DropNamespace(DropNamespaceRequest) returns (DropNamespaceResponse) {} + rpc UpdateNamespace(UpdateNamespaceRequest) returns (UpdateNamespaceResponse) {} + rpc ListNamespaces(ListNamespacesRequest) returns (ListNamespacesResponse) {} + + rpc UpdateExtSnapshotStreamingState(UpdateExtSnapshotStreamingStateRequest) returns (UpdateExtSnapshotStreamingStateResponse) {} + rpc StreamExtSnapshot(stream StreamExtSnapshotRequest) returns (StreamExtSnapshotResponse) {} +} + +message PingRequest {} + +message PingResponse { + string version = 1; +} + +enum LeaseType { + NS = 0; + UID = 1; + TS = 2; +} + +message AllocateIDsRequest { + uint64 how_many = 1; + LeaseType lease_type = 2; +} + +message AllocateIDsResponse { + uint64 start = 1; + uint64 end = 2; // inclusive +} + +message SignInUserRequest { + string user_id = 1; + string password = 2; + string refresh_token = 3; +} + +message SignInUserResponse { + string access_jwt = 1; + string refresh_jwt = 2; +} + +message AlterRequest { + AlterOp op = 1; + string ns_name = 2; + string schema = 3; + bool run_in_background = 4; + string predicate_to_drop = 5; + string type_to_drop = 6; +} + +message AlterResponse {} + +enum AlterOp { + NONE = 0; + DROP_ALL = 1; + DROP_ALL_IN_NS = 2; + DROP_DATA_IN_NS = 3; + DROP_PREDICATE_IN_NS = 4; + DROP_TYPE_IN_NS = 5; + SCHEMA_IN_NS = 6; +} + +enum RespFormat { + JSON = 0; + RDF = 1; +} + +message RunDQLRequest { + string ns_name = 1; + string dql_query = 2; + map vars = 3; + bool read_only = 4; + bool best_effort = 5; + RespFormat resp_format = 6; +} + +message RunDQLResponse { + TxnContext txn = 1; + bytes query_result = 2; // could be rdf or json + map blank_uids = 3; // mapping of blank_node => uid in hex + Latency latency = 4; + Metrics metrics = 5; +} + +message TxnContext { + uint64 start_ts = 1; + uint64 commit_ts = 2; + bool aborted = 3; + repeated string keys = 4; // List of keys to be used for conflict detection. + repeated string preds = 5; // List of predicates involved in this transaction. + string hash = 6; +} + +message Latency { + uint64 parsing_ns = 1; + uint64 processing_ns = 2; + uint64 resp_encoding_ns = 3; + uint64 assign_timestamp_ns = 4; + uint64 total_ns = 5; +} + +message Metrics { + // uids_touched is the map of number of uids read for each attribute/predicate. + map uids_touched = 1; +} + +message CreateNamespaceRequest { + string ns_name = 1; +} + +message CreateNamespaceResponse {} + +message DropNamespaceRequest { + string ns_name = 1; +} + +message DropNamespaceResponse {} + +message UpdateNamespaceRequest { + string ns_name = 1; + string rename_to_ns = 2; +} + +message UpdateNamespaceResponse {} + +message ListNamespacesRequest {} + +message ListNamespacesResponse { + map ns_list = 1; +} + +message Namespace { + string name = 1; + uint64 id = 2; +} + +message UpdateExtSnapshotStreamingStateRequest { + bool start = 1; + bool finish = 2; + bool drop_data = 3; +} + +message UpdateExtSnapshotStreamingStateResponse { + repeated uint32 groups = 1; +} + +message StreamExtSnapshotRequest { + uint32 group_id = 1; + bool forward = 2; + StreamPacket pkt = 3; +} + +message StreamExtSnapshotResponse {} + +message StreamPacket { + bytes data = 1; + bool done = 2; +} diff --git a/pydgraph/proto/api_v2_pb2.py b/pydgraph/proto/api_v2_pb2.py new file mode 100644 index 0000000..8389f00 --- /dev/null +++ b/pydgraph/proto/api_v2_pb2.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# NO CHECKED-IN PROTOBUF GENCODE +# source: api_v2.proto +# Protobuf Python Version: 5.29.0 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import runtime_version as _runtime_version +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +_runtime_version.ValidateProtobufRuntimeVersion( + _runtime_version.Domain.PUBLIC, + 5, + 29, + 0, + '', + 'api_v2.proto' +) +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x61pi_v2.proto\x12\x06\x61pi.v2\"\r\n\x0bPingRequest\"\x1f\n\x0cPingResponse\x12\x0f\n\x07version\x18\x01 \x01(\t\"M\n\x12\x41llocateIDsRequest\x12\x10\n\x08how_many\x18\x01 \x01(\x04\x12%\n\nlease_type\x18\x02 \x01(\x0e\x32\x11.api.v2.LeaseType\"1\n\x13\x41llocateIDsResponse\x12\r\n\x05start\x18\x01 \x01(\x04\x12\x0b\n\x03\x65nd\x18\x02 \x01(\x04\"M\n\x11SignInUserRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x10\n\x08password\x18\x02 \x01(\t\x12\x15\n\rrefresh_token\x18\x03 \x01(\t\"=\n\x12SignInUserResponse\x12\x12\n\naccess_jwt\x18\x01 \x01(\t\x12\x13\n\x0brefresh_jwt\x18\x02 \x01(\t\"\x98\x01\n\x0c\x41lterRequest\x12\x1b\n\x02op\x18\x01 \x01(\x0e\x32\x0f.api.v2.AlterOp\x12\x0f\n\x07ns_name\x18\x02 \x01(\t\x12\x0e\n\x06schema\x18\x03 \x01(\t\x12\x19\n\x11run_in_background\x18\x04 \x01(\x08\x12\x19\n\x11predicate_to_drop\x18\x05 \x01(\t\x12\x14\n\x0ctype_to_drop\x18\x06 \x01(\t\"\x0f\n\rAlterResponse\"\xe0\x01\n\rRunDQLRequest\x12\x0f\n\x07ns_name\x18\x01 \x01(\t\x12\x11\n\tdql_query\x18\x02 \x01(\t\x12-\n\x04vars\x18\x03 \x03(\x0b\x32\x1f.api.v2.RunDQLRequest.VarsEntry\x12\x11\n\tread_only\x18\x04 \x01(\x08\x12\x13\n\x0b\x62\x65st_effort\x18\x05 \x01(\x08\x12\'\n\x0bresp_format\x18\x06 \x01(\x0e\x32\x12.api.v2.RespFormat\x1a+\n\tVarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xf8\x01\n\x0eRunDQLResponse\x12\x1f\n\x03txn\x18\x01 \x01(\x0b\x32\x12.api.v2.TxnContext\x12\x14\n\x0cquery_result\x18\x02 \x01(\x0c\x12\x39\n\nblank_uids\x18\x03 \x03(\x0b\x32%.api.v2.RunDQLResponse.BlankUidsEntry\x12 \n\x07latency\x18\x04 \x01(\x0b\x32\x0f.api.v2.Latency\x12 \n\x07metrics\x18\x05 \x01(\x0b\x32\x0f.api.v2.Metrics\x1a\x30\n\x0e\x42lankUidsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"m\n\nTxnContext\x12\x10\n\x08start_ts\x18\x01 \x01(\x04\x12\x11\n\tcommit_ts\x18\x02 \x01(\x04\x12\x0f\n\x07\x61\x62orted\x18\x03 \x01(\x08\x12\x0c\n\x04keys\x18\x04 \x03(\t\x12\r\n\x05preds\x18\x05 \x03(\t\x12\x0c\n\x04hash\x18\x06 \x01(\t\"}\n\x07Latency\x12\x12\n\nparsing_ns\x18\x01 \x01(\x04\x12\x15\n\rprocessing_ns\x18\x02 \x01(\x04\x12\x18\n\x10resp_encoding_ns\x18\x03 \x01(\x04\x12\x1b\n\x13\x61ssign_timestamp_ns\x18\x04 \x01(\x04\x12\x10\n\x08total_ns\x18\x05 \x01(\x04\"u\n\x07Metrics\x12\x36\n\x0cuids_touched\x18\x01 \x03(\x0b\x32 .api.v2.Metrics.UidsTouchedEntry\x1a\x32\n\x10UidsTouchedEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x04:\x02\x38\x01\")\n\x16\x43reateNamespaceRequest\x12\x0f\n\x07ns_name\x18\x01 \x01(\t\"\x19\n\x17\x43reateNamespaceResponse\"\'\n\x14\x44ropNamespaceRequest\x12\x0f\n\x07ns_name\x18\x01 \x01(\t\"\x17\n\x15\x44ropNamespaceResponse\"?\n\x16UpdateNamespaceRequest\x12\x0f\n\x07ns_name\x18\x01 \x01(\t\x12\x14\n\x0crename_to_ns\x18\x02 \x01(\t\"\x19\n\x17UpdateNamespaceResponse\"\x17\n\x15ListNamespacesRequest\"\x97\x01\n\x16ListNamespacesResponse\x12;\n\x07ns_list\x18\x01 \x03(\x0b\x32*.api.v2.ListNamespacesResponse.NsListEntry\x1a@\n\x0bNsListEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12 \n\x05value\x18\x02 \x01(\x0b\x32\x11.api.v2.Namespace:\x02\x38\x01\"%\n\tNamespace\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x04\"Z\n&UpdateExtSnapshotStreamingStateRequest\x12\r\n\x05start\x18\x01 \x01(\x08\x12\x0e\n\x06\x66inish\x18\x02 \x01(\x08\x12\x11\n\tdrop_data\x18\x03 \x01(\x08\"9\n\'UpdateExtSnapshotStreamingStateResponse\x12\x0e\n\x06groups\x18\x01 \x03(\r\"`\n\x18StreamExtSnapshotRequest\x12\x10\n\x08group_id\x18\x01 \x01(\r\x12\x0f\n\x07\x66orward\x18\x02 \x01(\x08\x12!\n\x03pkt\x18\x03 \x01(\x0b\x32\x14.api.v2.StreamPacket\"\x1b\n\x19StreamExtSnapshotResponse\"*\n\x0cStreamPacket\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\x0c\x12\x0c\n\x04\x64one\x18\x02 \x01(\x08*$\n\tLeaseType\x12\x06\n\x02NS\x10\x00\x12\x07\n\x03UID\x10\x01\x12\x06\n\x02TS\x10\x02*\x8b\x01\n\x07\x41lterOp\x12\x08\n\x04NONE\x10\x00\x12\x0c\n\x08\x44ROP_ALL\x10\x01\x12\x12\n\x0e\x44ROP_ALL_IN_NS\x10\x02\x12\x13\n\x0f\x44ROP_DATA_IN_NS\x10\x03\x12\x18\n\x14\x44ROP_PREDICATE_IN_NS\x10\x04\x12\x13\n\x0f\x44ROP_TYPE_IN_NS\x10\x05\x12\x10\n\x0cSCHEMA_IN_NS\x10\x06*\x1f\n\nRespFormat\x12\x08\n\x04JSON\x10\x00\x12\x07\n\x03RDF\x10\x01\x32\xf5\x06\n\x06\x44graph\x12\x33\n\x04Ping\x12\x13.api.v2.PingRequest\x1a\x14.api.v2.PingResponse\"\x00\x12H\n\x0b\x41llocateIDs\x12\x1a.api.v2.AllocateIDsRequest\x1a\x1b.api.v2.AllocateIDsResponse\"\x00\x12\x45\n\nSignInUser\x12\x19.api.v2.SignInUserRequest\x1a\x1a.api.v2.SignInUserResponse\"\x00\x12\x36\n\x05\x41lter\x12\x14.api.v2.AlterRequest\x1a\x15.api.v2.AlterResponse\"\x00\x12\x39\n\x06RunDQL\x12\x15.api.v2.RunDQLRequest\x1a\x16.api.v2.RunDQLResponse\"\x00\x12T\n\x0f\x43reateNamespace\x12\x1e.api.v2.CreateNamespaceRequest\x1a\x1f.api.v2.CreateNamespaceResponse\"\x00\x12N\n\rDropNamespace\x12\x1c.api.v2.DropNamespaceRequest\x1a\x1d.api.v2.DropNamespaceResponse\"\x00\x12T\n\x0fUpdateNamespace\x12\x1e.api.v2.UpdateNamespaceRequest\x1a\x1f.api.v2.UpdateNamespaceResponse\"\x00\x12Q\n\x0eListNamespaces\x12\x1d.api.v2.ListNamespacesRequest\x1a\x1e.api.v2.ListNamespacesResponse\"\x00\x12\x84\x01\n\x1fUpdateExtSnapshotStreamingState\x12..api.v2.UpdateExtSnapshotStreamingStateRequest\x1a/.api.v2.UpdateExtSnapshotStreamingStateResponse\"\x00\x12\\\n\x11StreamExtSnapshot\x12 .api.v2.StreamExtSnapshotRequest\x1a!.api.v2.StreamExtSnapshotResponse\"\x00(\x01\x42H\n\x0cio.dgraph.v2B\x0b\x44graphProtoZ+github.com/dgraph-io/dgo/v250/protos/api.v2b\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'api_v2_pb2', _globals) +if not _descriptor._USE_C_DESCRIPTORS: + _globals['DESCRIPTOR']._loaded_options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\014io.dgraph.v2B\013DgraphProtoZ+github.com/dgraph-io/dgo/v250/protos/api.v2' + _globals['_RUNDQLREQUEST_VARSENTRY']._loaded_options = None + _globals['_RUNDQLREQUEST_VARSENTRY']._serialized_options = b'8\001' + _globals['_RUNDQLRESPONSE_BLANKUIDSENTRY']._loaded_options = None + _globals['_RUNDQLRESPONSE_BLANKUIDSENTRY']._serialized_options = b'8\001' + _globals['_METRICS_UIDSTOUCHEDENTRY']._loaded_options = None + _globals['_METRICS_UIDSTOUCHEDENTRY']._serialized_options = b'8\001' + _globals['_LISTNAMESPACESRESPONSE_NSLISTENTRY']._loaded_options = None + _globals['_LISTNAMESPACESRESPONSE_NSLISTENTRY']._serialized_options = b'8\001' + _globals['_LEASETYPE']._serialized_start=2119 + _globals['_LEASETYPE']._serialized_end=2155 + _globals['_ALTEROP']._serialized_start=2158 + _globals['_ALTEROP']._serialized_end=2297 + _globals['_RESPFORMAT']._serialized_start=2299 + _globals['_RESPFORMAT']._serialized_end=2330 + _globals['_PINGREQUEST']._serialized_start=24 + _globals['_PINGREQUEST']._serialized_end=37 + _globals['_PINGRESPONSE']._serialized_start=39 + _globals['_PINGRESPONSE']._serialized_end=70 + _globals['_ALLOCATEIDSREQUEST']._serialized_start=72 + _globals['_ALLOCATEIDSREQUEST']._serialized_end=149 + _globals['_ALLOCATEIDSRESPONSE']._serialized_start=151 + _globals['_ALLOCATEIDSRESPONSE']._serialized_end=200 + _globals['_SIGNINUSERREQUEST']._serialized_start=202 + _globals['_SIGNINUSERREQUEST']._serialized_end=279 + _globals['_SIGNINUSERRESPONSE']._serialized_start=281 + _globals['_SIGNINUSERRESPONSE']._serialized_end=342 + _globals['_ALTERREQUEST']._serialized_start=345 + _globals['_ALTERREQUEST']._serialized_end=497 + _globals['_ALTERRESPONSE']._serialized_start=499 + _globals['_ALTERRESPONSE']._serialized_end=514 + _globals['_RUNDQLREQUEST']._serialized_start=517 + _globals['_RUNDQLREQUEST']._serialized_end=741 + _globals['_RUNDQLREQUEST_VARSENTRY']._serialized_start=698 + _globals['_RUNDQLREQUEST_VARSENTRY']._serialized_end=741 + _globals['_RUNDQLRESPONSE']._serialized_start=744 + _globals['_RUNDQLRESPONSE']._serialized_end=992 + _globals['_RUNDQLRESPONSE_BLANKUIDSENTRY']._serialized_start=944 + _globals['_RUNDQLRESPONSE_BLANKUIDSENTRY']._serialized_end=992 + _globals['_TXNCONTEXT']._serialized_start=994 + _globals['_TXNCONTEXT']._serialized_end=1103 + _globals['_LATENCY']._serialized_start=1105 + _globals['_LATENCY']._serialized_end=1230 + _globals['_METRICS']._serialized_start=1232 + _globals['_METRICS']._serialized_end=1349 + _globals['_METRICS_UIDSTOUCHEDENTRY']._serialized_start=1299 + _globals['_METRICS_UIDSTOUCHEDENTRY']._serialized_end=1349 + _globals['_CREATENAMESPACEREQUEST']._serialized_start=1351 + _globals['_CREATENAMESPACEREQUEST']._serialized_end=1392 + _globals['_CREATENAMESPACERESPONSE']._serialized_start=1394 + _globals['_CREATENAMESPACERESPONSE']._serialized_end=1419 + _globals['_DROPNAMESPACEREQUEST']._serialized_start=1421 + _globals['_DROPNAMESPACEREQUEST']._serialized_end=1460 + _globals['_DROPNAMESPACERESPONSE']._serialized_start=1462 + _globals['_DROPNAMESPACERESPONSE']._serialized_end=1485 + _globals['_UPDATENAMESPACEREQUEST']._serialized_start=1487 + _globals['_UPDATENAMESPACEREQUEST']._serialized_end=1550 + _globals['_UPDATENAMESPACERESPONSE']._serialized_start=1552 + _globals['_UPDATENAMESPACERESPONSE']._serialized_end=1577 + _globals['_LISTNAMESPACESREQUEST']._serialized_start=1579 + _globals['_LISTNAMESPACESREQUEST']._serialized_end=1602 + _globals['_LISTNAMESPACESRESPONSE']._serialized_start=1605 + _globals['_LISTNAMESPACESRESPONSE']._serialized_end=1756 + _globals['_LISTNAMESPACESRESPONSE_NSLISTENTRY']._serialized_start=1692 + _globals['_LISTNAMESPACESRESPONSE_NSLISTENTRY']._serialized_end=1756 + _globals['_NAMESPACE']._serialized_start=1758 + _globals['_NAMESPACE']._serialized_end=1795 + _globals['_UPDATEEXTSNAPSHOTSTREAMINGSTATEREQUEST']._serialized_start=1797 + _globals['_UPDATEEXTSNAPSHOTSTREAMINGSTATEREQUEST']._serialized_end=1887 + _globals['_UPDATEEXTSNAPSHOTSTREAMINGSTATERESPONSE']._serialized_start=1889 + _globals['_UPDATEEXTSNAPSHOTSTREAMINGSTATERESPONSE']._serialized_end=1946 + _globals['_STREAMEXTSNAPSHOTREQUEST']._serialized_start=1948 + _globals['_STREAMEXTSNAPSHOTREQUEST']._serialized_end=2044 + _globals['_STREAMEXTSNAPSHOTRESPONSE']._serialized_start=2046 + _globals['_STREAMEXTSNAPSHOTRESPONSE']._serialized_end=2073 + _globals['_STREAMPACKET']._serialized_start=2075 + _globals['_STREAMPACKET']._serialized_end=2117 + _globals['_DGRAPH']._serialized_start=2333 + _globals['_DGRAPH']._serialized_end=3218 +# @@protoc_insertion_point(module_scope) diff --git a/pydgraph/proto/api_v2_pb2_grpc.py b/pydgraph/proto/api_v2_pb2_grpc.py new file mode 100644 index 0000000..c8bf116 --- /dev/null +++ b/pydgraph/proto/api_v2_pb2_grpc.py @@ -0,0 +1,527 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc +import warnings + +import api_v2_pb2 as api__v2__pb2 + +GRPC_GENERATED_VERSION = '1.71.2' +GRPC_VERSION = grpc.__version__ +_version_not_supported = False + +try: + from grpc._utilities import first_version_is_lower + _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION) +except ImportError: + _version_not_supported = True + +if _version_not_supported: + raise RuntimeError( + f'The grpc package installed is at version {GRPC_VERSION},' + + f' but the generated code in api_v2_pb2_grpc.py depends on' + + f' grpcio>={GRPC_GENERATED_VERSION}.' + + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}' + + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.' + ) + + +class DgraphStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Ping = channel.unary_unary( + '/api.v2.Dgraph/Ping', + request_serializer=api__v2__pb2.PingRequest.SerializeToString, + response_deserializer=api__v2__pb2.PingResponse.FromString, + _registered_method=True) + self.AllocateIDs = channel.unary_unary( + '/api.v2.Dgraph/AllocateIDs', + request_serializer=api__v2__pb2.AllocateIDsRequest.SerializeToString, + response_deserializer=api__v2__pb2.AllocateIDsResponse.FromString, + _registered_method=True) + self.SignInUser = channel.unary_unary( + '/api.v2.Dgraph/SignInUser', + request_serializer=api__v2__pb2.SignInUserRequest.SerializeToString, + response_deserializer=api__v2__pb2.SignInUserResponse.FromString, + _registered_method=True) + self.Alter = channel.unary_unary( + '/api.v2.Dgraph/Alter', + request_serializer=api__v2__pb2.AlterRequest.SerializeToString, + response_deserializer=api__v2__pb2.AlterResponse.FromString, + _registered_method=True) + self.RunDQL = channel.unary_unary( + '/api.v2.Dgraph/RunDQL', + request_serializer=api__v2__pb2.RunDQLRequest.SerializeToString, + response_deserializer=api__v2__pb2.RunDQLResponse.FromString, + _registered_method=True) + self.CreateNamespace = channel.unary_unary( + '/api.v2.Dgraph/CreateNamespace', + request_serializer=api__v2__pb2.CreateNamespaceRequest.SerializeToString, + response_deserializer=api__v2__pb2.CreateNamespaceResponse.FromString, + _registered_method=True) + self.DropNamespace = channel.unary_unary( + '/api.v2.Dgraph/DropNamespace', + request_serializer=api__v2__pb2.DropNamespaceRequest.SerializeToString, + response_deserializer=api__v2__pb2.DropNamespaceResponse.FromString, + _registered_method=True) + self.UpdateNamespace = channel.unary_unary( + '/api.v2.Dgraph/UpdateNamespace', + request_serializer=api__v2__pb2.UpdateNamespaceRequest.SerializeToString, + response_deserializer=api__v2__pb2.UpdateNamespaceResponse.FromString, + _registered_method=True) + self.ListNamespaces = channel.unary_unary( + '/api.v2.Dgraph/ListNamespaces', + request_serializer=api__v2__pb2.ListNamespacesRequest.SerializeToString, + response_deserializer=api__v2__pb2.ListNamespacesResponse.FromString, + _registered_method=True) + self.UpdateExtSnapshotStreamingState = channel.unary_unary( + '/api.v2.Dgraph/UpdateExtSnapshotStreamingState', + request_serializer=api__v2__pb2.UpdateExtSnapshotStreamingStateRequest.SerializeToString, + response_deserializer=api__v2__pb2.UpdateExtSnapshotStreamingStateResponse.FromString, + _registered_method=True) + self.StreamExtSnapshot = channel.stream_unary( + '/api.v2.Dgraph/StreamExtSnapshot', + request_serializer=api__v2__pb2.StreamExtSnapshotRequest.SerializeToString, + response_deserializer=api__v2__pb2.StreamExtSnapshotResponse.FromString, + _registered_method=True) + + +class DgraphServicer(object): + """Missing associated documentation comment in .proto file.""" + + def Ping(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def AllocateIDs(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def SignInUser(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def Alter(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def RunDQL(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def CreateNamespace(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def DropNamespace(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def UpdateNamespace(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def ListNamespaces(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def UpdateExtSnapshotStreamingState(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def StreamExtSnapshot(self, request_iterator, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_DgraphServicer_to_server(servicer, server): + rpc_method_handlers = { + 'Ping': grpc.unary_unary_rpc_method_handler( + servicer.Ping, + request_deserializer=api__v2__pb2.PingRequest.FromString, + response_serializer=api__v2__pb2.PingResponse.SerializeToString, + ), + 'AllocateIDs': grpc.unary_unary_rpc_method_handler( + servicer.AllocateIDs, + request_deserializer=api__v2__pb2.AllocateIDsRequest.FromString, + response_serializer=api__v2__pb2.AllocateIDsResponse.SerializeToString, + ), + 'SignInUser': grpc.unary_unary_rpc_method_handler( + servicer.SignInUser, + request_deserializer=api__v2__pb2.SignInUserRequest.FromString, + response_serializer=api__v2__pb2.SignInUserResponse.SerializeToString, + ), + 'Alter': grpc.unary_unary_rpc_method_handler( + servicer.Alter, + request_deserializer=api__v2__pb2.AlterRequest.FromString, + response_serializer=api__v2__pb2.AlterResponse.SerializeToString, + ), + 'RunDQL': grpc.unary_unary_rpc_method_handler( + servicer.RunDQL, + request_deserializer=api__v2__pb2.RunDQLRequest.FromString, + response_serializer=api__v2__pb2.RunDQLResponse.SerializeToString, + ), + 'CreateNamespace': grpc.unary_unary_rpc_method_handler( + servicer.CreateNamespace, + request_deserializer=api__v2__pb2.CreateNamespaceRequest.FromString, + response_serializer=api__v2__pb2.CreateNamespaceResponse.SerializeToString, + ), + 'DropNamespace': grpc.unary_unary_rpc_method_handler( + servicer.DropNamespace, + request_deserializer=api__v2__pb2.DropNamespaceRequest.FromString, + response_serializer=api__v2__pb2.DropNamespaceResponse.SerializeToString, + ), + 'UpdateNamespace': grpc.unary_unary_rpc_method_handler( + servicer.UpdateNamespace, + request_deserializer=api__v2__pb2.UpdateNamespaceRequest.FromString, + response_serializer=api__v2__pb2.UpdateNamespaceResponse.SerializeToString, + ), + 'ListNamespaces': grpc.unary_unary_rpc_method_handler( + servicer.ListNamespaces, + request_deserializer=api__v2__pb2.ListNamespacesRequest.FromString, + response_serializer=api__v2__pb2.ListNamespacesResponse.SerializeToString, + ), + 'UpdateExtSnapshotStreamingState': grpc.unary_unary_rpc_method_handler( + servicer.UpdateExtSnapshotStreamingState, + request_deserializer=api__v2__pb2.UpdateExtSnapshotStreamingStateRequest.FromString, + response_serializer=api__v2__pb2.UpdateExtSnapshotStreamingStateResponse.SerializeToString, + ), + 'StreamExtSnapshot': grpc.stream_unary_rpc_method_handler( + servicer.StreamExtSnapshot, + request_deserializer=api__v2__pb2.StreamExtSnapshotRequest.FromString, + response_serializer=api__v2__pb2.StreamExtSnapshotResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'api.v2.Dgraph', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + server.add_registered_method_handlers('api.v2.Dgraph', rpc_method_handlers) + + + # This class is part of an EXPERIMENTAL API. +class Dgraph(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def Ping(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/Ping', + api__v2__pb2.PingRequest.SerializeToString, + api__v2__pb2.PingResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def AllocateIDs(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/AllocateIDs', + api__v2__pb2.AllocateIDsRequest.SerializeToString, + api__v2__pb2.AllocateIDsResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def SignInUser(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/SignInUser', + api__v2__pb2.SignInUserRequest.SerializeToString, + api__v2__pb2.SignInUserResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def Alter(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/Alter', + api__v2__pb2.AlterRequest.SerializeToString, + api__v2__pb2.AlterResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def RunDQL(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/RunDQL', + api__v2__pb2.RunDQLRequest.SerializeToString, + api__v2__pb2.RunDQLResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def CreateNamespace(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/CreateNamespace', + api__v2__pb2.CreateNamespaceRequest.SerializeToString, + api__v2__pb2.CreateNamespaceResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def DropNamespace(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/DropNamespace', + api__v2__pb2.DropNamespaceRequest.SerializeToString, + api__v2__pb2.DropNamespaceResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def UpdateNamespace(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/UpdateNamespace', + api__v2__pb2.UpdateNamespaceRequest.SerializeToString, + api__v2__pb2.UpdateNamespaceResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def ListNamespaces(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/ListNamespaces', + api__v2__pb2.ListNamespacesRequest.SerializeToString, + api__v2__pb2.ListNamespacesResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def UpdateExtSnapshotStreamingState(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary( + request, + target, + '/api.v2.Dgraph/UpdateExtSnapshotStreamingState', + api__v2__pb2.UpdateExtSnapshotStreamingStateRequest.SerializeToString, + api__v2__pb2.UpdateExtSnapshotStreamingStateResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) + + @staticmethod + def StreamExtSnapshot(request_iterator, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.stream_unary( + request_iterator, + target, + '/api.v2.Dgraph/StreamExtSnapshot', + api__v2__pb2.StreamExtSnapshotRequest.SerializeToString, + api__v2__pb2.StreamExtSnapshotResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + _registered_method=True) diff --git a/pyproject.toml b/pyproject.toml index 0ff5774..fb0c714 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,15 +8,14 @@ authors = [{ name = "Hypermode Inc.", email = "hello@hypermode.com" }] license = { file = "LICENSE" } description = "Official Dgraph client implementation for Python" readme = "README.md" -requires-python = ">=3.7" +requires-python = ">=3.9" classifiers = [ 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Topic :: Database', 'Topic :: Software Development', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', @@ -37,6 +36,5 @@ dev = [ "pytest>=8.3.3", ] - [project.urls] "Homepage" = "https://github.com/hypermodeinc/pydgraph" diff --git a/scripts/local-test.sh b/scripts/local-test.sh index c683070..5ac5700 100755 --- a/scripts/local-test.sh +++ b/scripts/local-test.sh @@ -4,7 +4,7 @@ # Instead it assumes dgraph is already installed. function DockerCompose() { - docker compose -p pydgraph $@ + docker compose -p pydgraph "$@" } function wait-for-healthy() { diff --git a/scripts/protogen.py b/scripts/protogen.py index 1592e9a..662d202 100644 --- a/scripts/protogen.py +++ b/scripts/protogen.py @@ -26,5 +26,6 @@ "--python_out=" + protopath, "--grpc_python_out=" + protopath, os.path.join(protopath, "api.proto"), + os.path.join(protopath, "api_v2.proto"), ) ) diff --git a/tests/test_connect.py b/tests/test_connect.py index e604c43..d1e9fcd 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -1,3 +1,11 @@ +# SPDX-FileCopyrightText: © Hypermode Inc. +# SPDX-License-Identifier: Apache-2.0 + +"""Tests construction of Dgraph client.""" + +__author__ = "Matthew McNeely" +__maintainer__ = "Hypermode Inc. " + import json import os import unittest diff --git a/tests/test_v2_ops.py b/tests/test_v2_ops.py new file mode 100644 index 0000000..99b4d93 --- /dev/null +++ b/tests/test_v2_ops.py @@ -0,0 +1,105 @@ +# SPDX-FileCopyrightText: © Hypermode Inc. +# SPDX-License-Identifier: Apache-2.0 + +"""Tests for V2 API operations.""" + +__author__ = "Cascade" +__maintainer__ = "Hypermode Inc. " + +import os +import random +import unittest + +from pydgraph import open +from pydgraph.errors import V2NotSupportedError +from pydgraph.proto.api_v2_pb2 import ( + CreateNamespaceResponse, + DropNamespaceResponse, + ListNamespacesResponse, + PingResponse, +) + + +class TestV2Ops(unittest.TestCase): + client = None + _is_v2_supported = False + + @classmethod + def setUpClass(cls): + """Set up the client and check for v2 API support.""" + server_addr = os.environ.get("TEST_SERVER_ADDR", "localhost:9080") + print(f"Connecting to Dgraph at {server_addr}") + cls.client = open(f"dgraph://groot:password@{server_addr}") + + try: + # Feature-detect v2 support by trying a v2-only call. + cls.client.ping() + cls._is_v2_supported = True + print("V2 API is supported.") + except V2NotSupportedError: + cls._is_v2_supported = False + print("V2 API is not supported.") + + @classmethod + def tearDownClass(cls): + """Tear down the client.""" + if cls.client: + cls.client.close() + + def test_ping(self): + """Test the ping method.""" + self.assertIsNotNone(self.client, "Client is not initialized") + + if not self.__class__._is_v2_supported: + with self.assertRaises(V2NotSupportedError): + self.client.ping() + else: + response = self.client.ping() + self.assertIsNotNone(response, "Ping response is None") + self.assertIsInstance( + response, PingResponse, "Response is not a PingResponse" + ) + self.assertTrue(response.version, "Ping response has no version") + print(f"Dgraph version (from ping): {response.version}") + + def test_namespace(self): + """Test the namespace operations.""" + self.assertIsNotNone(self.client, "Client is not initialized") + + if not self.__class__._is_v2_supported: + self.skipTest("Skipping namespace test: V2 API not supported.") + + # generate a random namespace name + namespace = "test_" + str(random.randint(0, 10000)) # trunk-ignore(bandit/B311) + + response = self.client.create_namespace(namespace) + self.assertIsNotNone(response, "Create namespace response is None") + self.assertIsInstance( + response, + CreateNamespaceResponse, + "Response is not a CreateNamespaceResponse", + ) + + response = self.client.list_namespaces() + self.assertIsNotNone( + response, + "List namespaces response is None", + ) + self.assertIsInstance( + response, + ListNamespacesResponse, + "Response is not a ListNamespacesResponse", + ) + self.assertIn(namespace, response.ns_list, "Namespace not found in list") + + response = self.client.drop_namespace(namespace) + self.assertIsNotNone(response, "Drop namespace response is None") + self.assertIsInstance( + response, + DropNamespaceResponse, + "Response is not a DropNamespaceResponse", + ) + + +if __name__ == "__main__": + unittest.main()