sage.grpc package

Submodules

sage.grpc.grpc_client module

class sage.grpc.grpc_client.SageClient(url: str, options: Optional[Dict[str, str]] = None, credentials: Optional[grpc.ChannelCredentials] = None, compression: Optional[str] = None)

Bases: object

A SaGe client allows to execute SPARQL queries using a SaGe server deployed with gRPC.

Args:
  • url: URL of the SaGe gRPC server.

  • options: An optional list of key-value pairs (channel args in gRPC Core runtime) to configure the channel.

  • credentials: A, optional ChannelCredentials instance. If set, the client will use a secure_channel for communicating with the server. Otherwise, it will use an insecure_channel.

  • compression: An optional value indicating the compression method to be used over the lifetime of the channel. This is an EXPERIMENTAL option.

Example:
>>> with SageClient("localhost:8000") as client:
>>>   sparql_query = "SELECT * WHERE { ?s ?p ?o }"
>>>   for bindings in client.query(sparql_query, "http://example.org#DBpedia")
>>>     print(bindings)
close() → None
query(sparql_query: str, default_graph_uri: str) → Iterable[Dict[str, str]]

Execute a SPARQL query using a SaGe gRPC-server.

Args:
  • sparql_query: SPARQL query to execute.

  • default_graph_uri: URI of the default RDF Graph to query.

Yields:

Set of solution mappings

Example:
>>> sparql_query = "SELECT * WHERE { ?s ?p ?o }"
>>> for bindings in client.query(sparql_query, "http://example.org#DBpedia")
>>>   print(bindings)

sage.grpc.grpc_server module

class sage.grpc.grpc_server.SageQueryService(dataset: sage.database.core.dataset.Dataset)

Bases: sage.grpc.service_pb2_grpc.SageSPARQLServicer

A SageQueryService implements a gRPC service that evaluates SPARQL queries using Web preemption

Argument: RDF dataset hosted by the gRPC server.

Query(request: service_pb2.SageQuery, context: grpc.ServicerContext) → service_pb2.SageResponse

Execute a SPARQL query using the Web preemption model

sage.grpc.grpc_server.create_bindings(bindings: List[Dict[str, str]]) → Iterable[service_pb2.BindingSet]

Create an iterator that converts a set of dict-based bindings to a set of protobuf-based bindings.

Argument: List of solutions bindings, encoded as dictionaries.

Yields: Set of solutions bindings, encoded in a Protobuf format.

sage.grpc.grpc_server.get_server(config_file: str, port=8000, workers=10) → grpc.Server

Create a SaGe SPARQL query server powered by gRPC.

Args:
  • config_file: Path to the SaGe configuration file, in YAML format.

  • port: Host port to run the gRPC server.

  • workers: Number of thread workers used by the gRPC server.

Returns:

A SaGe gRPC server built from the input configuration file.

sage.grpc.service_pb2 module

sage.grpc.service_pb2_grpc module

class sage.grpc.service_pb2_grpc.SageSPARQLServicer

Bases: object

The SaGe SPARQL query server

Query(request, context)

Execute a SPARQL query using the Web preemption model

class sage.grpc.service_pb2_grpc.SageSPARQLStub(channel)

Bases: object

The SaGe SPARQL query server

sage.grpc.service_pb2_grpc.add_SageSPARQLServicer_to_server(servicer, server)

Module contents