swh.graph.http_rpc_server module

A proxy HTTP server for swh-graph, talking to the Java code via py4j, and using FIFO as a transport to stream integers between the two languages.

class swh.graph.http_rpc_server.GraphServerApp(*args, middlewares=(), **kwargs)[source]

Bases: RPCServerApp

async swh.graph.http_rpc_server.index(request)[source]
class swh.graph.http_rpc_server.GraphView(*args, **kwargs)[source]

Bases: View

Base class for views working on the graph, with utility functions

get_direction()[source]

Validate HTTP query parameter direction

get_edges()[source]

Validate HTTP query parameter edges, i.e., edge restrictions

get_return_types()[source]

Validate HTTP query parameter ‘return types’, i.e, a set of types which we will filter the query results with

get_max_matching_nodes()[source]

Validate HTTP query parameter max_matching_nodes, i.e., number of results

get_max_edges()[source]

Validate HTTP query parameter ‘max_edges’, i.e., the limit of the number of edges that can be visited

async check_swhid(swhid)[source]

Validate that the given SWHID exists in the graph

class swh.graph.http_rpc_server.StreamingGraphView(*args, **kwargs)[source]

Bases: GraphView

Base class for views streaming their response line by line.

content_type = 'text/plain'
response_streamer(*args, **kwargs)[source]

Context manager to prepare then close a StreamResponse

async get()[source]
async prepare_response()[source]

This can be overridden with some setup to be run before the response actually starts streaming.

async stream_response()[source]

Override this to perform the response streaming. Implementations of this should await self.stream_line(line) to write each line.

async stream_line(line)[source]

Write a line in the response stream.

class swh.graph.http_rpc_server.StatsView(*args, **kwargs)[source]

Bases: GraphView

View showing some statistics on the graph

async get()[source]
class swh.graph.http_rpc_server.SimpleTraversalView(*args, **kwargs)[source]

Bases: StreamingGraphView

Base class for views of simple traversals

async prepare_response()[source]

This can be overridden with some setup to be run before the response actually starts streaming.

configure_request()[source]
async stream_response()[source]

Override this to perform the response streaming. Implementations of this should await self.stream_line(line) to write each line.

rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.LeavesView(*args, **kwargs)[source]

Bases: SimpleTraversalView

configure_request()[source]
rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.NeighborsView(*args, **kwargs)[source]

Bases: SimpleTraversalView

configure_request()[source]
rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.VisitNodesView(*args, **kwargs)[source]

Bases: SimpleTraversalView

rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.VisitEdgesView(*args, **kwargs)[source]

Bases: SimpleTraversalView

configure_request()[source]
async stream_response()[source]

Override this to perform the response streaming. Implementations of this should await self.stream_line(line) to write each line.

rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.CountView(*args, **kwargs)[source]

Bases: GraphView

Base class for counting views.

count_type: Optional[str] = None
async get()[source]
configure_request()[source]
class swh.graph.http_rpc_server.CountNeighborsView(*args, **kwargs)[source]

Bases: CountView

configure_request()[source]
rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.CountLeavesView(*args, **kwargs)[source]

Bases: CountView

configure_request()[source]
rpc_client: TraversalServiceStub
class swh.graph.http_rpc_server.CountVisitNodesView(*args, **kwargs)[source]

Bases: CountView

rpc_client: TraversalServiceStub
swh.graph.http_rpc_server.make_app(config=None)[source]

Create an aiohttp server for the HTTP RPC frontend to the swh-graph API.

It may either connect to an existing grpc server (cls=”remote”) or spawn a local grpc server (cls=”local”).

config is expected to be a dict like:

graph:
  cls: "local"
  grpc_server:
    port: 50091
  http_rpc_server:
    debug: true

or:

graph:
  cls: "remote"
  url: "localhost:50091"
  http_rpc_server:
    debug: true

See:

swh.graph.http_rpc_server.make_app_from_configfile()[source]

Load configuration and then build application to run