API package¶
Public API for the PGX client.
Classes found in the pypgx.api
package and its subpackages should typically
not be directly instantiated by the user. Instead, they are returned by functions,
instance methods, and in some cases, class methods.
- class pypgx.api.AllPaths(graph, java_all_paths)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
The paths from one source vertex to all other vertices.
- Parameters
graph (PgxGraph) –
- Return type
None
- destroy()¶
Destroy this object.
- Return type
None
- get_path(destination)¶
Get the path.
- Parameters
destination (pypgx.api._pgx_entity.PgxVertex) – The destination node
- Returns
The path result to the destination node
- Return type
- class pypgx.api.Analyst(session, java_analyst)¶
Bases:
object
The Analyst gives access to all built-in algorithms of PGX.
Unlike some of the other classes inside this package, the Analyst is not stateless. It creates session-bound transient data to hold the result of algorithms and keeps track of them.
- Parameters
session (PgxSession) –
- Return type
None
- adamic_adar_counting(graph, aa='adamic_adar')¶
Adamic-adar counting compares the amount of neighbors shared between vertices, this measure can be used with communities.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
aa (Union[pypgx.api._property.EdgeProperty, str]) – Edge property holding the Adamic-Adar index for each edge in the graph. Can be a string or an EdgeProperty object.
- Returns
Edge property holding the computed scores
- Return type
- all_reachable_vertices_edges(graph, src, dst, k, filter=None)¶
Find all the vertices and edges on a path between the src and target of length smaller or equal to k.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – The source vertex
dst (pypgx.api._pgx_entity.PgxVertex) – The destination vertex
k (int) – The dimension of the distances property; i.e. number of high-degree vertices.
filter (Optional[pypgx.api.filters._graph_filter.EdgeFilter]) – The filter to be used on edges when searching for a path
- Returns
The vertices on the path, the edges on the path and a map containing the distances from the source vertex for each vertex on the path
- Return type
Tuple[pypgx.api._pgx_collection.VertexSet, pypgx.api._pgx_collection.EdgeSet, pypgx.api._pgx_map.PgxMap]
- approximate_vertex_betweenness_centrality(graph, seeds, bc='approx_betweenness')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
seeds (Union[pypgx.api._pgx_collection.VertexSet, int]) – The (unique) chosen nodes to be used to compute the approximated betweenness centrality coefficients
bc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the betweenness centrality value for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- bipartite_check(graph, is_left='is_left')¶
Verify whether a graph is bipartite.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
is_left (Union[pypgx.api._property.VertexProperty, str]) – (out-argument) vertex property holding the side of each vertex in a bipartite graph (true for left, false for right).
- Returns
vertex property holding the side of each vertex in a bipartite graph (true for left, false for right).
- Return type
- center(graph, center=None)¶
Periphery/center gives an overview of the extreme distances and the corresponding vertices in a graph.
The center is comprised by the set of vertices with eccentricity equal to the radius of the graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
center (Optional[Union[pypgx.api._pgx_collection.VertexSet, str]]) – (Out argument) vertex set holding the vertices from the periphery or center of the graph
- Return type
- close()¶
Destroy without waiting for completion.
- Return type
None
- closeness_centrality(graph, cc='closeness')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
cc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the closeness centrality
- Return type
- communities_conductance_minimization(graph, max_iter=100, label='conductance_minimization')¶
Soman and Narang can find communities in a graph taking weighted edges into account.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
max_iter (int) – Maximum number of iterations that will be performed
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
label – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the communities found by the algorithm
- Returns
Partition holding the node collections corresponding to the communities found by the algorithm
- Return type
- communities_infomap(graph, rank, weight, tau=0.15, tol=0.0001, max_iter=100, label='infomap')¶
Infomap can find high quality communities in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
rank (pypgx.api._property.VertexProperty) – Vertex property holding the normalized PageRank value for each vertex
weight (pypgx.api._property.EdgeProperty) – Ridge property holding the weight of each edge in the graph
tau (float) – Damping factor
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
max_iter (int) – Maximum iteration number
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the communities found by the algorithm
- Return type
- communities_label_propagation(graph, max_iter=100, label='label_propagation')¶
Label propagation can find communities in a graph relatively fast.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
max_iter (int) – Maximum number of iterations that will be performed
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object
label – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the communities found by the algorithm
- Returns
Partition holding the node collections corresponding to the communities found by the algorithm
- Return type
- compute_high_degree_vertices(graph, k, high_degree_vertex_mapping=None, high_degree_vertices=None)¶
Compute the k vertices with the highest degrees in the graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
k (int) – Number of high-degree vertices to be computed
high_degree_vertex_mapping (Optional[Union[pypgx.api._pgx_map.PgxMap, str]]) – (out argument) map with the top k high-degree vertices and their indices
high_degree_vertices (Optional[Union[pypgx.api._pgx_collection.VertexSet, str]]) – (out argument) the high-degree vertices
- Returns
a map with the top k high-degree vertices and their indices and a vertex set containing the same vertices
- Return type
Tuple[pypgx.api._pgx_map.PgxMap, pypgx.api._pgx_collection.VertexSet]
- conductance(graph, partition, partition_idx)¶
Conductance assesses the quality of a partition in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
partition (pypgx.api._partition.PgxPartition) – Partition of the graph with the corresponding node collections
partition_idx (int) – Number of the component to be used for computing its conductance
- Return type
float
- count_triangles(graph, sort_vertices_by_degree)¶
Triangle counting gives an overview of the amount of connections between vertices in neighborhoods.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
sort_vertices_by_degree (bool) – Boolean flag for sorting the nodes by their degree as preprocessing step
- Returns
The total number of triangles found
- Return type
int
- create_distance_index(graph, high_degree_vertex_mapping, high_degree_vertices, index=None)¶
Compute an index with distances to each high-degree vertex
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
high_degree_vertex_mapping (pypgx.api._pgx_map.PgxMap) – a map with the top k high-degree vertices and their indices and a vertex
high_degree_vertices (pypgx.api._pgx_collection.VertexSet) – the high-degree vertices
index (Optional[Union[pypgx.api._property.VertexProperty, str]]) – (out-argument) the index containing the distances to each high-degree vertex for all vertices
- Returns
the index containing the distances to each high-degree vertex for all vertices
- Return type
- deepwalk_builder(min_word_frequency=1, batch_size=128, num_epochs=2, layer_size=200, learning_rate=0.025, min_learning_rate=0.0001, window_size=5, walk_length=5, walks_per_vertex=4, sample_rate=1e-05, negative_sample=10, validation_fraction=0.05, seed=None)¶
Build a DeepWalk model and return it.
- Parameters
min_word_frequency (int) – Minimum word frequency to consider before pruning
batch_size (int) – Batch size for training the model
num_epochs (int) – Number of epochs to train the model
layer_size (int) – Number of dimensions for the output vectors
learning_rate (float) – Initial learning rate
min_learning_rate (float) – Minimum learning rate
window_size (int) – Window size to consider while training the model
walk_length (int) – Length of the walks
walks_per_vertex (int) – Number of walks to consider per vertex
sample_rate (float) – Sample rate
negative_sample (int) – Number of negative samples
validation_fraction (float) – Fraction of training data on which to compute final loss
seed (Optional[int]) – Random seed for training the model
- Returns
Built DeepWalk model
- Return type
- degree_centrality(graph, dc='degree')¶
Measure the centrality of the vertices based on its degree.
This lets you see how a vertex influences its neighborhood.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
dc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Vertex property holding the computed scores
- Return type
- destroy()¶
Destroy with waiting for completion.
- Return type
None
- diameter(graph, eccentricity='eccentricity')¶
Diameter/radius gives an overview of the distances in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
eccentricity (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the eccentricity value for each vertex
- Returns
Pair holding the diameter of the graph and a node property with eccentricity value for each node
- Return type
Tuple[int, pypgx.api._property.VertexProperty]
- eigenvector_centrality(graph, tol=0.001, max_iter=100, l2_norm=False, in_edges=False, ec='eigenvector')¶
Eigenvector centrality gets the centrality of the vertices in an intrincated way using neighbors, allowing to find well-connected vertices.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
max_iter (int) – Maximum iteration number
l2_norm (bool) – Boolean flag to determine whether the algorithm will use the l2 norm (Euclidean norm) or the l1 norm (absolute value) to normalize the centrality scores
in_edges (bool) – Boolean flag to determine whether the algorithm will use the incoming or the outgoing edges in the graph for the computations
ec (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the resulting score for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- enumerate_simple_paths(graph, src, dst, k, vertices_on_path, edges_on_path, dist)¶
Enumerate simple paths between the source and destination vertex.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – The source vertex
dst (pypgx.api._pgx_entity.PgxVertex) – The destination vertex
k (int) – maximum number of iterations
vertices_on_path (pypgx.api._pgx_collection.VertexSet) – VertexSet containing all vertices to be considered while enumerating paths
edges_on_path (pypgx.api._pgx_collection.EdgeSet) – EdgeSet containing all edges to be consider while enumerating paths
dist (pypgx.api._pgx_map.PgxMap) – map containing the hop-distance from the source vertex to each vertex that is to be considered while enumerating the paths
- Returns
Triple containing containing the path lengths, a vertex-sequence containing the vertices on the paths and edge-sequence containing the edges on the paths
- Return type
Tuple[List[int], pypgx.api._pgx_collection.VertexSet, pypgx.api._pgx_collection.EdgeSet]
- fattest_path(graph, root, capacity, distance='fattest_path_distance', parent='fattest_path_parent', parent_edge='fattest_path_parent_edge')¶
Fattest path is a fast algorithm for finding a shortest path adding constraints for flowing related matters.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
root (pypgx.api._pgx_entity.PgxVertex) – Fattest path is a fast algorithm for finding a shortest path adding constraints for flowing related matters
capacity (pypgx.api._property.EdgeProperty) – Edge property holding the capacity of each edge in the graph
distance (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the capacity value of the fattest path up to the current vertex
parent (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the parent vertex of the each vertex in the fattest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
AllPaths object holding the information of the possible fattest paths from the source node
- Return type
- filtered_bfs(graph, root, navigator, init_with_inf=True, max_depth=2147483647, distance='distance', parent='parent')¶
Breadth-first search with an option to filter edges during the traversal of the graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
root (pypgx.api._pgx_entity.PgxVertex) – The source vertex from the graph for the path.
navigator (pypgx.api.filters._graph_filter.VertexFilter) – Navigator expression to be evaluated on the vertices during the graph traversal
init_with_inf (bool) – Boolean flag to set the initial distance values of the vertices. If set to true, it will initialize the distances as INF, and -1 otherwise.
max_depth (int) – Maximum depth limit for the BFS traversal
distance (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the hop distance for each reachable vertex in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the parent vertex of the each reachable vertex in the path
- Returns
Distance and parent vertex properties
- Return type
Tuple[pypgx.api._property.VertexProperty, pypgx.api._property.VertexProperty]
- filtered_dfs(graph, root, navigator, init_with_inf=True, max_depth=2147483647, distance='distance', parent='parent')¶
Depth-first search with an option to filter edges during the traversal of the graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
root (pypgx.api._pgx_entity.PgxVertex) – The source vertex from the graph for the path
navigator (pypgx.api.filters._graph_filter.VertexFilter) – Navigator expression to be evaluated on the vertices during the graph traversal
init_with_inf (bool) – Boolean flag to set the initial distance values of the vertices. If set to true, it will initialize the distances as INF, and -1 otherwise.
max_depth (int) – Maximum search depth
distance (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the hop distance for each reachable vertex in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the parent vertex of the each reachable vertex in the path
- Returns
Distance and parent vertex properties
- Return type
Tuple[pypgx.api._property.VertexProperty, pypgx.api._property.VertexProperty]
- find_cycle(graph, src=None, vertex_seq=None, edge_seq=None)¶
Find cycle looks for any loop in the graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (Optional[pypgx.api._pgx_entity.PgxVertex]) – Source vertex for the search
vertex_seq (Optional[Union[pypgx.api._pgx_collection.VertexSequence, str]]) – (Out argument) vertex sequence holding the vertices in the cycle
edge_seq (Optional[Union[pypgx.api._pgx_collection.EdgeSequence, str]]) – (Out argument) edge sequence holding the edges in the cycle
- Returns
PgxPath representing the cycle as path, if exists.
- Return type
- get_deepwalk_model_loader()¶
Return a ModelLoader that can be used for loading a DeepWalkModel.
- Returns
ModelLoader
- Return type
- get_pg2vec_model_loader()¶
Return a ModelLoader that can be used for loading a Pg2vecModel.
- Returns
ModelLoader
- Return type
- get_supervised_graphwise_model_loader()¶
Return a ModelLoader that can be used for loading a SupervisedGraphWiseModel.
- Returns
ModelLoader
- Return type
- get_unsupervised_graphwise_model_loader()¶
Return a ModelLoader that can be used for loading a UnsupervisedGraphWiseModel.
- Returns
ModelLoader
- Return type
- graphwise_conv_layer_config(num_sampled_neighbors=10, neighbor_weight_property_name=None, activation_fn='relu', weight_init_scheme='xavier_uniform', vertex_to_vertex_connection=None, edge_to_vertex_connection=None, vertex_to_edge_connection=None, edge_to_edge_connection=None)¶
Build a GraphWise conv layer configuration and return it.
- Parameters
num_sampled_neighbors (int) – Number of neighbors to sample
neighbor_weight_property_name (Optional[str]) – Neighbor weight property name.
activation_fn (str) – Activation function. Supported functions: relu, leaky_relu, tanh, linear. If this is the last layer, this setting will be ignored and replaced by the activation function of the loss function, e.g softmax or sigmoid.
weight_init_scheme (str) – Initialization scheme for the weights in the layer. Supported schemes: xavier, xavier_uniform, ones, zeros. Note that biases are always initialized with zeros.
vertex_to_vertex_connection (Optional[bool]) – Use the connection between vertices to vertices. Should be used only on heterogeneous graphs
edge_to_vertex_connection (Optional[bool]) – Use the connection between edges to vertices. Should be used only on heterogeneous graphs
vertex_to_edges_connection – Use the connection between vertices to edges. Should be used only on heterogeneous graphs
edge_to_edges_connection – Use the connection between edges to edges. Should be used only on heterogeneous graphs
vertex_to_edge_connection (Optional[bool]) –
edge_to_edge_connection (Optional[bool]) –
- Returns
Built GraphWiseConvLayerConfig
- Return type
pypgx.api.mllib._graphwise_conv_layer_config.GraphWiseConvLayerConfig
- graphwise_dgi_layer_config(corruption_function=None, readout_function='mean', discriminator='bilinear')¶
Build a GraphWise DGI layer configuration and return it.
- Parameters
corruption_function(CorruptionFunction) – Corruption Function to use
readout_function(str) – Neighbor weight property name. Supported functions: mean
discriminator(str) – discriminator function. Supported functions: bilinear
corruption_function (Optional[pypgx.api.mllib._corruption_function.CorruptionFunction]) –
readout_function (str) –
discriminator (str) –
- Returns
GraphWiseDgiLayerConfig object
- Return type
pypgx.api.mllib._graphwise_dgi_layer_config.GraphWiseDgiLayerConfig
- graphwise_pred_layer_config(hidden_dim=None, activation_fn='relu', weight_init_scheme='xavier_uniform')¶
Build a GraphWise prediction layer configuration and return it.
- Parameters
hidden_dim (Optional[int]) – Hidden dimension. If this is the last layer, this setting will be ignored and replaced by the number of classes.
activation_fn (str) – Activation function. Supported functions: relu, leaky_relu, tanh, linear. If this is the last layer, this setting will be ignored and replaced by the activation function of the loss function, e.g softmax or sigmoid.
weight_init_scheme (str) – Initialization scheme for the weights in the layer. Supportes schemes: xavier, xavier_uniform, ones, zeros. Note that biases are always initialized with zeros.
- Returns
Built GraphWisePredictionLayerConfig
- Return type
pypgx.api.mllib._graphwise_pred_layer_config.GraphWisePredictionLayerConfig
- hits(graph, max_iter=100, auth='authorities', hubs='hubs')¶
Hyperlink-Induced Topic Search (HITS) assigns ranking scores to the vertices, aimed to assess the quality of information and references in linked structures.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
max_iter (int) – Number of iterations that will be performed
auth (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the authority score for each vertex
hubs (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the hub score for each vertex
- Returns
Vertex property holding the computed scores
- Return type
Tuple[pypgx.api._property.VertexProperty, pypgx.api._property.VertexProperty]
- in_degree_centrality(graph, dc='in_degree')¶
Measure the in-degree centrality of the vertices based on its degree.
This lets you see how a vertex influences its neighborhood.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
dc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Vertex property holding the computed scores
- Return type
- in_degree_distribution(graph, dist_map=None)¶
Calculate the in-degree distribution.
In-degree distribution gives information about the incoming flows in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
dist_map (Optional[Union[pypgx.api._pgx_map.PgxMap, str]]) – (Out argument) map holding a histogram of the vertex degrees in the graph
- Returns
Map holding a histogram of the vertex degrees in the graph
- Return type
- k_core(graph, min_core=0, max_core=2147483647, kcore='kcore')¶
k-core decomposes a graph into layers revealing subgraphs with particular properties.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
min_core (int) – Minimum k-core value
max_core (int) – Maximum k-core value
kcore (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the result value
- Returns
Pair holding the maximum core found and a node property with the largest k-core value for each node.
- Return type
Tuple[int, pypgx.api._property.VertexProperty]
- limited_shortest_path_hop_dist(graph, src, dst, max_hops, high_degree_vertex_mapping, high_degree_vertices, index, path_vertices=None, path_edges=None)¶
Compute the shortest path between the source and destination vertex.
The algorithm only considers paths up to a length of k.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – The source vertex
dst (pypgx.api._pgx_entity.PgxVertex) – The destination vertex
max_hops (int) – The maximum number of edges to follow when trying to find a path
high_degree_vertex_mapping (pypgx.api._pgx_map.PgxMap) – Map with the top k high-degree vertices and their indices
high_degree_vertices (pypgx.api._pgx_collection.VertexSet) – The high-degree vertices
index (pypgx.api._property.VertexProperty) – Index containing distances to high-degree vertices
path_vertices (Optional[Union[pypgx.api._pgx_collection.VertexSequence, str]]) – (out-argument) will contain the vertices on the found path or will be empty if there is none
path_edges (Optional[Union[pypgx.api._pgx_collection.EdgeSequence, str]]) – (out-argument) will contain the vertices on the found path or will be empty if there is none
- Returns
A tuple containing the vertices in the shortest path from src to dst and the edges on the path. Both will be empty if there is no path within maxHops steps
- Return type
Tuple[pypgx.api._pgx_collection.VertexSequence, pypgx.api._pgx_collection.EdgeSequence]
- limited_shortest_path_hop_dist_filtered(graph, src, dst, max_hops, high_degree_vertex_mapping, high_degree_vertices, index, filter, path_vertices=None, path_edges=None)¶
Compute the shortest path between the source and destination vertex.
The algorithm only considers paths up to a length of k.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – The source vertex
dst (pypgx.api._pgx_entity.PgxVertex) – The destination vertex
max_hops (int) – The maximum number of edges to follow when trying to find a path
high_degree_vertex_mapping (pypgx.api._pgx_map.PgxMap) – Map with the top k high-degree vertices and their indices
high_degree_vertices (pypgx.api._pgx_collection.VertexSet) – The high-degree vertices
index (pypgx.api._property.VertexProperty) – Index containing distances to high-degree vertices
filter (pypgx.api.filters._graph_filter.EdgeFilter) – Filter to be evaluated on the edges when searching for a path
path_vertices (Optional[Union[pypgx.api._pgx_collection.VertexSequence, str]]) – (out-argument) will contain the vertices on the found path or will be empty if there is none
path_edges (Optional[Union[pypgx.api._pgx_collection.EdgeSequence, str]]) – (out-argument) will contain the vertices on the found path or will be empty if there is none
- Returns
A tuple containing the vertices in the shortest path from src to dst and the edges on the path. Both will be empty if there is no path within maxHops steps
- Return type
Tuple[pypgx.api._pgx_collection.VertexSequence, pypgx.api._pgx_collection.EdgeSequence]
- load_deepwalk_model(path, key)¶
Load an encrypted DeepWalk model.
- Parameters
path (str) – Path to model
key (Optional[str]) – The decryption key, or None if no encryption was used
- Returns
Loaded model
- Return type
- load_pg2vec_model(path, key)¶
Load an encrypted pg2vec model.
- Parameters
path (str) – Path to model
key (Optional[str]) – The decryption key, or None if no encryption was used
- Returns
Loaded model
- Return type
- load_supervised_graphwise_model(path, key)¶
Load an encrypted SupervisedGraphWise model.
- Parameters
path (str) – Path to model
key (Optional[str]) – The decryption key, or None if no encryption was used
- Returns
Loaded model
- Return type
pypgx.api.mllib._supervised_graphwise_model.SupervisedGraphWiseModel
- load_unsupervised_graphwise_model(path, key)¶
Load an encrypted UnsupervisedGraphWise model.
- Parameters
path (str) – Path to model
key (str) – The decryption key, or null if no encryption was used
- Returns
Loaded model
- Return type
pypgx.api.mllib._unsupervised_graphwise_model.UnsupervisedGraphWiseModel
- local_clustering_coefficient(graph, lcc='lcc')¶
LCC gives information about potential clustering options in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
lcc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the lcc value for each vertex
- Returns
Vertex property holding the lcc value for each vertex
- Return type
- louvain(graph, weight, max_iter=100, nbr_pass=1, tol=0.0001, community='community')¶
Louvain to detect communities in a graph
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph.
weight (pypgx.api._property.EdgeProperty) – Weights of the edges of the graph.
max_iter (int) – Maximum number of iterations that will be performed during each pass.
nbr_pass (int) – Number of passes that will be performed.
tol (float) – maximum tolerated error value, the algorithm will stop once the graph’s total modularity gain becomes smaller than this value.
community (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the community ID assigned to each vertex
- Returns
Community IDs vertex property
- Return type
- matrix_factorization_gradient_descent(bipartite_graph, weight, learning_rate=0.001, change_per_step=1.0, lbd=0.15, max_iter=100, vector_length=10, features='features')¶
- Parameters
bipartite_graph (pypgx.api._pgx_graph.BipartiteGraph) – Input graph between 1 and 5, the result will become inaccurate.
learning_rate (float) – Learning rate for the optimization process
change_per_step (float) – Parameter used to modulate the learning rate during the optimization process
lbd (float) – Penalization parameter to avoid over-fitting during optimization process
max_iter (int) – Maximum number of iterations that will be performed
vector_length (int) – Size of the feature vectors to be generated for the factorization
features (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the generated feature vectors for each vertex. This function accepts names and VertexProperty objects.
weight (pypgx.api._property.EdgeProperty) –
- Returns
Matrix factorization model holding the feature vectors found by the algorithm
- Return type
pypgx.api._matrix_factorization_model.MatrixFactorizationModel
- matrix_factorization_recommendations(bipartite_graph, user, vector_length, feature, estimated_rating=None)¶
Complement for Matrix Factorization.
The generated feature vectors will be used for making predictions in cases where the given user vertex has not been related to a particular item from the item set. Similarly to the recommendations from matrix factorization, this algorithm will perform dot products between the given user vertex and the rest of vertices in the graph, giving a score of 0 to the items that are already related to the user and to the products with other user vertices, hence returning the results of the dot products for the unrelated item vertices. The scores from those dot products can be interpreted as the predicted scores for the unrelated items given a particular user vertex.
- Parameters
bipartite_graph (pypgx.api._pgx_graph.BipartiteGraph) – Bipartite input graph
user (pypgx.api._pgx_entity.PgxVertex) – Vertex from the left (user) side of the graph
vector_length (int) – size of the feature vectors
feature (pypgx.api._property.VertexProperty) – vertex property holding the feature vectors for each vertex
estimated_rating (Optional[Union[pypgx.api._property.VertexProperty, str]]) – (out argument) vertex property holding the estimated rating score for each vertex
- Returns
vertex property holding the estimated rating score for each vertex
- Return type
- model_repository()¶
Get model repository builder for CRUD access to model stores.
- out_degree_centrality(graph, dc='out_degree')¶
Measure the out-degree centrality of the vertices based on its degree.
This lets you see how a vertex influences its neighborhood.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
dc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Vertex property holding the computed scores
- Return type
- out_degree_distribution(graph, dist_map=None)¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
dist_map (Optional[Union[pypgx.api._pgx_map.PgxMap, str]]) – (Out argument) map holding a histogram of the vertex degrees in the graph
- Returns
Map holding a histogram of the vertex degrees in the graph
- Return type
- pagerank(graph, tol=0.001, damping=0.85, max_iter=100, norm=False, rank='pagerank')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor
max_iter (int) – Maximum number of iterations that will be performed
norm (bool) – Determine whether the algorithm will take into account dangling vertices for the ranking scores.
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the PageRank value for each vertex, or name for a new property
- Returns
Vertex property holding the PageRank value for each vertex
- Return type
- pagerank_approximate(graph, tol=0.001, damping=0.85, max_iter=100, rank='approx_pagerank')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor
max_iter (int) – Maximum number of iterations that will be performed
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the PageRank value for each vertex
- Returns
Vertex property holding the PageRank value for each vertex
- Return type
- partition_conductance(graph, partition)¶
Partition conductance assesses the quality of many partitions in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
partition (pypgx.api._partition.PgxPartition) – Partition of the graph with the corresponding node collections
- Return type
Tuple[float, float]
- partition_modularity(graph, partition)¶
Modularity summarizes information about the quality of components in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
partition (pypgx.api._partition.PgxPartition) – Partition of the graph with the corresponding node collections
- Returns
Scalar (double) to store the conductance value of the given cut
- Return type
float
- periphery(graph, periphery=None)¶
Periphery/center gives an overview of the extreme distances and the corresponding vertices in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
periphery (Optional[Union[pypgx.api._pgx_collection.VertexSet, str]]) – (Out argument) vertex set holding the vertices from the periphery or center of the graph
- Returns
Vertex set holding the vertices from the periphery or center of the graph
- Return type
- personalized_pagerank(graph, v, tol=0.001, damping=0.85, max_iter=100, norm=False, rank='personalized_pagerank')¶
Personalized PageRank for a vertex of interest.
Compares and spots out important vertices in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
v (Union[pypgx.api._pgx_collection.VertexSet, pypgx.api._pgx_entity.PgxVertex]) – The chosen vertex from the graph for personalization
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor
max_iter (int) – Maximum number of iterations that will be performed
norm (bool) – Boolean flag to determine whether the algorithm will take into account dangling vertices for the ranking scores.
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the PageRank value for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- personalized_salsa(bipartite_graph, v, tol=0.001, damping=0.85, max_iter=100, rank='personalized_salsa')¶
Personalized SALSA for a vertex of interest.
Assesses the quality of information and references in linked structures.
- Parameters
bipartite_graph (pypgx.api._pgx_graph.BipartiteGraph) – Bipartite graph
v (Union[pypgx.api._pgx_collection.VertexSet, pypgx.api._pgx_entity.PgxVertex]) – The chosen vertex from the graph for personalization
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor to modulate the degree of personalization of the scores by the algorithm
max_iter (int) – Maximum number of iterations that will be performed
rank (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the normalized authority/hub ranking score for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- personalized_weighted_pagerank(graph, v, weight, tol=0.001, damping=0.85, max_iter=100, norm=False, rank='personalized_weighted_pagerank')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
v (Union[pypgx.api._pgx_collection.VertexSet, pypgx.api._pgx_entity.PgxVertex]) – The chosen vertex from the graph for personalization
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor
max_iter (int) – Maximum number of iterations that will be performed
norm (bool) – Boolean flag to determine whether the algorithm will take into account dangling vertices for the ranking scores
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the PageRank value for each vertex
- Return type
- pg2vec_builder(graphlet_id_property_name, vertex_property_names, min_word_frequency=1, batch_size=128, num_epochs=5, layer_size=200, learning_rate=0.04, min_learning_rate=0.0001, window_size=4, walk_length=8, walks_per_vertex=5, graphlet_size_property_name='graphletSize-Pg2vec', use_graphlet_size=True, validation_fraction=0.05, seed=None)¶
Build a pg2Vec model and return it.
- Parameters
graphlet_id_property_name (str) – Property name of the graphlet-id in the input graph
vertex_property_names (List[str]) – Property names to consider for pg2vec model training
min_word_frequency (int) – Minimum word frequency to consider before pruning
batch_size (int) – Batch size for training the model
num_epochs (int) – Number of epochs to train the model
layer_size (int) – Number of dimensions for the output vectors
learning_rate (float) – Initial learning rate
min_learning_rate (float) – Minimum learning rate
window_size (int) – Window size to consider while training the model
walk_length (int) – Length of the walks
walks_per_vertex (int) – Number of walks to consider per vertex
graphlet_size_property_name (str) – Property name for graphlet size
use_graphlet_size (bool) – Whether to use or not the graphlet size
validation_fraction (float) – Fraction of training data on which to compute final loss
seed (Optional[int]) – Seed
- Returns
Built Pg2Vec Model
- Return type
- prim(graph, weight, mst='mst')¶
Prim reveals tree structures with shortest paths in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
mst (Union[pypgx.api._property.EdgeProperty, str]) – Edge property holding the edges belonging to the minimum spanning tree of the graph
- Returns
Edge property holding the edges belonging to the minimum spanning tree of the graph (i.e. all the edges with in_mst=true)
- Return type
- radius(graph, eccentricity='eccentricity')¶
Radius gives an overview of the distances in a graph. it is computed as the minimum graph eccentricity.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
eccentricity (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the eccentricity value for each vertex
- Returns
Pair holding the radius of the graph and a node property with eccentricity value for each node
- Return type
Tuple[int, pypgx.api._property.VertexProperty]
- random_walk_with_restart(graph, source, length, reset_prob, visit_count=None)¶
Perform a random walk over the graph.
The walk will start at the given source vertex and will randomly visit neighboring vertices in the graph, with a probability equal to the value of reset_probability of going back to the starting point. The random walk will also go back to the starting point every time it reaches a vertex with no outgoing edges. The algorithm will stop once it reaches the specified walk length.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
source (pypgx.api._pgx_entity.PgxVertex) – Starting point of the random walk
length (int) – Length (number of steps) of the random walk
reset_prob (float) – Probability value for resetting the random walk
visit_count (Optional[pypgx.api._pgx_map.PgxMap]) – (out argument) map holding the number of visits during the random walk for each vertex in the graph
- Returns
map holding the number of visits during the random walk for each vertex in the graph
- Return type
- reachability(graph, src, dst, max_hops, ignore_edge_direction)¶
Reachability is a fast way to check if two vertices are reachable from each other.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source vertex for the search
dst (pypgx.api._pgx_entity.PgxVertex) – Destination vertex for the search
max_hops (int) – Maximum hop distance between the source and destination vertices
ignore_edge_direction (bool) – Boolean flag for ignoring the direction of the edges during the search
- Returns
The number of hops between the vertices. It will return -1 if the vertices are not connected or are not reachable given the condition of the maximum hop distance allowed.
- Return type
int
- salsa(bipartite_graph, tol=0.001, max_iter=100, rank='salsa')¶
Stochastic Approach for Link-Structure Analysis (SALSA) computes ranking scores.
It assesses the quality of information and references in linked structures.
- Parameters
bipartite_graph (pypgx.api._pgx_graph.BipartiteGraph) – Bipartite graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
max_iter (int) – Maximum number of iterations that will be performed
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the value for each vertex in the graph
- Returns
Vertex property holding the computed scores
- Return type
- scc_kosaraju(graph, label='scc_kosaraju')¶
Kosaraju finds strongly connected components in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the components found by the algorithm
- Return type
- scc_tarjan(graph, label='scc_tarjan')¶
Tarjan finds strongly connected components in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the degree centrality value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the components found by the algorithm
- Return type
- shortest_path_bellman_ford(graph, src, weight, distance='bellman_ford_distance', parent='bellman_ford_parent', parent_edge='bellman_ford_parent_edge')¶
Bellman-Ford finds multiple shortest paths at the same time.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
distance (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the distance to the source vertex for each vertex in the graph
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
AllPaths holding the information of the possible shortest paths from the source node
- Return type
- shortest_path_bellman_ford_reversed(graph, src, weight, distance='bellman_ford_distance', parent='bellman_ford_parent', parent_edge='bellman_ford_parent_edge')¶
Reversed Bellman-Ford finds multiple shortest paths at the same time.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
distance (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the distance to the source vertex for each vertex in the graph
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path.
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path.
- Returns
AllPaths holding the information of the possible shortest paths from the source node.
- Return type
- shortest_path_bidirectional_dijkstra(graph, src, dst, weight, parent='bidirectional_dijkstra_parent', parent_edge='bidirectional_dijkstra_parent_edge')¶
Bidirectional dijkstra is a fast algorithm for finding a shortest path in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
dst (pypgx.api._pgx_entity.PgxVertex) – Destination node
weight (pypgx.api._property.EdgeProperty) – Edge property holding the (positive) weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
PgxPath holding the information of the shortest path, if it exists
- Return type
- shortest_path_dijkstra(graph, src, dst, weight, parent='dijkstra_parent', parent_edge='dijkstra_parent_edge')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
dst (pypgx.api._pgx_entity.PgxVertex) – Destination node
weight (pypgx.api._property.EdgeProperty) – Edge property holding the (positive) weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
PgxPath holding the information of the shortest path, if it exists
- Return type
- shortest_path_filtered_bidirectional_dijkstra(graph, src, dst, weight, filter_expression, parent='bidirectional_dijkstra_parent', parent_edge='bidirectional_dijkstra_parent_edge')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
dst (pypgx.api._pgx_entity.PgxVertex) – Destination node
weight (pypgx.api._property.EdgeProperty) – Edge property holding the (positive) weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
filter_expression (pypgx.api.filters._graph_filter.EdgeFilter) – graphFilter object for filtering
- Returns
PgxPath holding the information of the shortest path, if it exists
- Return type
- shortest_path_filtered_dijkstra(graph, src, dst, weight, filter_expression, parent='dijkstra_parent', parent_edge='dijkstra_parent_edge')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
dst (pypgx.api._pgx_entity.PgxVertex) – Destination node
weight (pypgx.api._property.EdgeProperty) – Edge property holding the (positive) weight of each edge in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
filter_expression (pypgx.api.filters._graph_filter.EdgeFilter) – GraphFilter object for filtering
- Returns
PgxPath holding the information of the shortest path, if it exists
- Return type
- shortest_path_hop_distance(graph, src, distance='hop_dist_distance', parent='hop_dist_parent', parent_edge='hop_dist_edge')¶
Hop distance can give a relatively fast insight on the distances in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
distance (Union[pypgx.api._property.VertexProperty, str]) – Out argument) vertex property holding the distance to the source vertex for each vertex in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
AllPaths holding the information of the possible shortest paths from the source node
- Return type
- shortest_path_hop_distance_reversed(graph, src, distance='hop_dist_distance', parent='hop_dist_parent', parent_edge='hop_dist_edge')¶
Backwards hop distance can give a relatively fast insight on the distances in a graph.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
src (pypgx.api._pgx_entity.PgxVertex) – Source node
distance (Union[pypgx.api._property.VertexProperty, str]) – Out argument) vertex property holding the distance to the source vertex for each vertex in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the parent vertex of the each vertex in the shortest path
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the edge ID linking the current vertex in the path with the previous vertex in the path
- Returns
AllPaths holding the information of the possible shortest paths from the source node
- Return type
- supervised_graphwise_builder(vertex_target_property_name, vertex_input_property_names=[], edge_input_property_names=[], target_vertex_labels=[], loss_fn='softmax_cross_entropy', batch_gen='standard', batch_gen_params=[], pred_layer_config=None, conv_layer_config=None, batch_size=128, num_epochs=3, learning_rate=0.01, layer_size=128, class_weights=None, seed=None, weight_decay=0.0)¶
Build a SupervisedGraphWise model and return it.
- Parameters
vertex_target_property_name (str) – Target property name
vertex_input_property_names (List[str]) – Vertices Input feature names
edge_input_property_names (List[str]) – Edges Input feature names
target_vertex_labels (List[str]) – Set the target vertex labels for the algorithm. Only the related vertices need to have the target property. Training and inference will be done on the vertices with those labels
loss_fn (Union[pypgx.api.mllib._loss_function.LossFunction, str]) – Loss function. Supported: String (‘softmax_cross_entropy’, ‘sigmoid_cross_entropy’) or LossFunction object
batch_gen (str) – Batch generator. Supported: ‘standard’, ‘stratified_oversampling’
batch_gen_params (List[Any]) – List of parameters passed to the batch generator
pred_layer_config (Optional[Iterable[pypgx.api.mllib._graphwise_pred_layer_config.GraphWisePredictionLayerConfig]]) – Prediction layer configuration as list of PredLayerConfig, or default if None
conv_layer_config (Optional[Iterable[pypgx.api.mllib._graphwise_conv_layer_config.GraphWiseConvLayerConfig]]) – Conv layer configuration as list of ConvLayerConfig, or default if None
batch_size (int) – Batch size for training the model
num_epochs (int) – Number of epochs to train the model
learning_rate (float) – Learning rate
layer_size (int) – Number of dimensions for the output vectors
class_weights (Optional[Union[Mapping[str, float], Mapping[float, float]]]) – Class weights to be used in the loss function. The loss for the corresponding class will be multiplied by the factor given in this map. If null, uniform class weights will be used.
seed (Optional[int]) – Seed
weight_decay (float) – Weight decay
- Returns
Built SupervisedGraphWise model
- Return type
pypgx.api.mllib._supervised_graphwise_model.SupervisedGraphWiseModel
- topological_schedule(graph, vs, topo_sched='topo_sched')¶
Topological schedule gives an order of visit for the reachable vertices from the source.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
vs (pypgx.api._pgx_collection.VertexSet) – Set of vertices to be used as the starting points for the scheduling order
topo_sched (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the scheduled order of each vertex
- Returns
Vertex property holding the scheduled order of each vertex.
- Return type
- topological_sort(graph, topo_sort='topo_sort')¶
Topological sort gives an order of visit for vertices in directed acyclic graphs.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
topo_sort (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the topological order of each vertex
- Return type
- unsupervised_graphwise_builder(vertex_input_property_names=[], edge_input_property_names=[], target_vertex_labels=[], loss_fn='sigmoid_cross_entropy', conv_layer_config=None, batch_size=128, num_epochs=3, learning_rate=0.001, layer_size=128, seed=None, dgi_layer_config=None, weight_decay=0.0)¶
Build a UnsupervisedGraphWise model and return it.
- Parameters
vertex_input_property_names (List[str]) – Vertices Input feature names
edge_input_property_names (List[str]) – Edges Input feature names
target_vertex_labels (List[str]) – Set the target vertex labels for the algorithm. Only the related vertices need to have the target property. Training and inference will be done on the vertices with those labels
loss_fn (str) – Loss function. Supported: sigmoid_cross_entropy
conv_layer_config (Optional[Iterable[pypgx.api.mllib._graphwise_conv_layer_config.GraphWiseConvLayerConfig]]) – Conv layer configuration as list of ConvLayerConfig, or default if None
batch_size (int) – Batch size for training the model
num_epochs (int) – Number of epochs to train the model
learning_rate (float) – Learning rate
layer_size (int) – Number of dimensions for the output vectors
seed (Optional[int]) – Seed
dgi_layer_config (Optional[pypgx.api.mllib._graphwise_dgi_layer_config.GraphWiseDgiLayerConfig]) – Dgi layer configuration as DgiLayerConfig object, or default if None
weight_decay (float) – weight decay
- Returns
Built UnsupervisedGraphWise model
- Return type
pypgx.api.mllib._unsupervised_graphwise_model.UnsupervisedGraphWiseModel
- vertex_betweenness_centrality(graph, bc='betweenness')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
bc (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the betweenness centrality value for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- wcc(graph, label='wcc')¶
Identify weakly connected components.
This can be useful for clustering graph data.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
label (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the value for each vertex in the graph. Can be a string or a VertexProperty object.
- Returns
Partition holding the node collections corresponding to the components found by the algorithm.
- Return type
- weighted_closeness_centrality(graph, weight, cc='weighted_closeness')¶
Measure the centrality of the vertices based on weighted distances, allowing to find well-connected vertices.
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
cc (Union[pypgx.api._property.VertexProperty, str]) – (Out argument) vertex property holding the closeness centrality value for each vertex
- Returns
Vertex property holding the computed scores
- Return type
- weighted_pagerank(graph, weight, tol=0.001, damping=0.85, max_iter=100, norm=False, rank='weighted_pagerank')¶
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
weight (pypgx.api._property.EdgeProperty) – Edge property holding the weight of each edge in the graph
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor
max_iter (int) – Maximum number of iterations that will be performed
rank (Union[pypgx.api._property.VertexProperty, str]) – Vertex property holding the PageRank value for each vertex
norm (bool) –
- Returns
Vertex property holding the computed the peageRank value
- Return type
- whom_to_follow(graph, v, top_k=100, size_circle_of_trust=500, tol=0.001, damping=0.85, max_iter=100, salsa_tol=0.001, salsa_max_iter=100, hubs=None, auth=None)¶
Whom-to-follow (WTF) is a recommendation algorithm.
It returns two vertex sequences: one of similar users (hubs) and a second one with users to follow (auth).
- Parameters
graph (pypgx.api._pgx_graph.PgxGraph) – Input graph
v (pypgx.api._pgx_entity.PgxVertex) – The chosen vertex from the graph for personalization of the recommendations
top_k (int) – The maximum number of recommendations that will be returned
size_circle_of_trust (int) – The maximum size of the circle of trust
tol (float) – Maximum tolerated error value. The algorithm will stop once the sum of the error values of all vertices becomes smaller than this value.
damping (float) – Damping factor for the Pagerank stage
max_iter (int) – Maximum number of iterations that will be performed for the Pagerank stage
salsa_tol (float) – Maximum tolerated error value for the SALSA stage
salsa_max_iter (int) – Maximum number of iterations that will be performed for the SALSA stage
hubs (Optional[Union[pypgx.api._pgx_collection.VertexSequence, str]]) – (Out argument) vertex sequence holding the top rated hub vertices (similar users) for the recommendations
auth (Optional[Union[pypgx.api._pgx_collection.VertexSequence, str]]) – (Out argument) vertex sequence holding the top rated authority vertices (users to follow) for the recommendations
- Returns
Vertex properties holding hubs and auth
- Return type
Tuple[pypgx.api._pgx_collection.VertexSequence, pypgx.api._pgx_collection.VertexSequence]
- class pypgx.api.BipartiteGraph(session, java_graph)¶
Bases:
pypgx.api._pgx_graph.PgxGraph
A bipartite PgxGraph.
- Parameters
session (PgxSession) –
- Return type
None
- get_is_left_property()¶
Get the ‘is Left’ vertex property of the graph.
- Return type
- class pypgx.api.CompiledProgram(session, java_program)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A compiled Green-Marl program.
Constructor arguments:
- Parameters
session (PgxSession) – Pgx Session
java_program (oracle.pgx.api.CompiledProgram) – Java compiledProgram
- Return type
None
- destroy()¶
Free resources on the server taken up by this Program.
- Return type
None
- get_return_type()¶
Get the return type of the compiled program.
- Return type
str
- run(*argv)¶
Run the compiled program with the given parameters.
If the Green-Marl procedure of this compiled program looks like this: procedure pagerank(G: Graph, e double, max int, nodePorp){…}
- Parameters
argv (Any) – All the arguments required by specified procedure
- Returns
Result of analysis as an AnalysisResult as a dict
- Return type
Dict[str, Optional[int]]
- class pypgx.api.EdgeBuilder(session, java_edge_builder, id_type)¶
Bases:
pypgx.api._graph_builder.GraphBuilder
An edge builder for defining edges added with the
GraphBuilder
.- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- property id: int¶
Get the id of the element (vertex or edge) this builder belongs to.
- is_ignored()¶
Whether this edge builder ignores method calls (True) or if it performs calls as usual (False. Some issues, such as incompatible changes in a ChangeSet, can be configured to be ignored. In that case, additional method calls on the returned edge builder object will be ignored.
- Return type
bool
- set_label(label)¶
Set the new value of the label.
- Parameters
label (str) – The new value of the label
- Returns
The EdgeBuilder object
- Return type
- set_property(key, value)¶
Set the property value of this edge with the given key to the given value.
The first time this method is called, the type of value defines the type of the property.
- Parameters
key (str) – The property key
value (Any) – The value of the vertex property
- Returns
The EdgeBuilder object
- Return type
- class pypgx.api.EdgeCollection(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.PgxCollection
A collection of edges.
- Parameters
graph (PgxGraph) –
- Return type
None
- add(e)¶
Add one or multiple edges to the collection.
- Parameters
e (Union[pypgx.api._pgx_entity.PgxEdge, int, Iterable[Union[pypgx.api._pgx_entity.PgxEdge, int]]]) – Edge or edge id. Can also be an iterable of edge/edge ids.
- add_all(edges)¶
Add multiple vertices to the collection.
- Parameters
edges (Iterable[Union[pypgx.api._pgx_entity.PgxEdge, int]]) – Iterable of edges/edges ids
- Return type
None
- contains(e)¶
Check if the collection contains edge e.
- Parameters
e (Union[pypgx.api._pgx_entity.PgxEdge, int]) – PgxEdge object or id:
- Returns
Boolean
- Return type
bool
- remove(e)¶
Remove one or multiple edges from the collection.
- Parameters
e (Union[pypgx.api._pgx_entity.PgxEdge, int, Iterable[Union[pypgx.api._pgx_entity.PgxEdge, int]]]) – Edges or edges id. Can also be an iterable of edges/edges ids.
- remove_all(edges)¶
Remove multiple edges from the collection.
- Parameters
edges (Iterable[Union[pypgx.api._pgx_entity.PgxEdge, int]]) – Iterable of edges/edges ids
- class pypgx.api.EdgeModifier(session, java_edge_modifier, id_type='integer')¶
Bases:
pypgx.api._graph_change_set.GraphChangeSet
,pypgx.api._graph_builder.EdgeBuilder
A class to modify existing edges of a graph.
- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- set_label(label)¶
Set the new value of the label.
- Parameters
label (str) – The label to be set.
- Returns
self
- Return type
- set_property(key, value)¶
Set the property value of this edge with the given key to the given value.
- Parameters
key (str) – A string with the name of the property to set.
value (Any) – The value to which this property shall be set.
- Returns
self
- Return type
- class pypgx.api.EdgeSequence(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.EdgeCollection
An ordered sequence of edges which may contain duplicates.
- Parameters
graph (PgxGraph) –
- Return type
None
- class pypgx.api.EdgeSet(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.EdgeCollection
An unordered set of edges (no duplicates).
- Parameters
graph (PgxGraph) –
- Return type
None
- class pypgx.api.FlashbackSynchronizer(java_flashback_synchronizer)¶
Bases:
pypgx.api._synchronizer.Synchronizer
Synchronizes a PGX graph with an Oracle Database using Flashback queries.
- Return type
None
- apply()¶
Apply the changes to the underlying PGX graph.
- fetch()¶
Fetch the changes from the external data source.
You can call this multiple times to accumulate deltas. The deltas reset once you call apply().
- get_graph_delta()¶
Synchronize changes from the external data source and return the new snapshot of the graph with the fetched changes applied.
- class pypgx.api.GraphAlterationBuilder(java_graph_alteration_builder)¶
Bases:
object
Builder to describe the alterations (graph schema modification) to perform to a graph.
It is for example possible to add or remove vertex and edge providers.
- Return type
None
- add_edge_provider(path_to_edge_provider_config)¶
Add an edge provider for which the configuration is in a file at the specified path.
- Parameters
path_to_edge_provider_config (str) – the path to the JSON configuration of the edge provider
- Returns
a GraphAlterationBuilder instance containing the added edge provider.
- Return type
- add_empty_edge_provider(provider_name, source_provider, dest_provider, label=None, key_type=None, key_column=None, create_key_mapping=None, properties=None)¶
Add an empty edge provider
- Parameters
provider_name (str) – the name of the edge provider to add
source_provider (str) – the name of the vertex provider for the source of the edges
dest_provider (str) – the name of the vertex provider for the destination of the edges
label (Optional[str]) – the label to associate to the provider
key_type (Optional[str]) – the key type
key_column (Optional[Union[str, int]]) – the key column name or index
create_key_mapping (Optional[bool]) – boolean indicating if the provider key mapping should be created
properties (Optional[List[Union[Tuple[str, str], Tuple[str, str, int], pypgx.api._graph_property_config.GraphPropertyConfig]]]) – the property configurations, these can either of the following forms:
- Return type
None
a length 2 tuple (name, type), a length 3 tuple (name, type, dimension) or a GraphPropertyConfig object :return:
- add_empty_vertex_provider(provider_name, label=None, key_type=None, key_column=None, create_key_mapping=None, properties=None)¶
Add an empty vertex provider
- Parameters
provider_name (str) – the name of the vertex provider to add
label (Optional[str]) – the label to associate to the provider
key_type (Optional[str]) – the key type
key_column (Optional[Union[str, int]]) – the key column name or index
create_key_mapping (Optional[bool]) – boolean indicating if the provider key mapping should be created
properties (Optional[List[Union[Tuple[str, str], Tuple[str, str, int], pypgx.api._graph_property_config.GraphPropertyConfig]]]) – the property configurations, these can either of the following forms:
- Return type
None
a length 2 tuple (name, type), a length 3 tuple (name, type, dimension) or a GraphPropertyConfig object :return:
- add_vertex_provider(path_to_vertex_provider_config)¶
Add a vertex provider for which the configuration is in a file at the specified path.
- Parameters
path_to_vertex_provider_config (str) – the path to the JSON configuration of the vertex provider.
- Returns
a GraphAlterationBuilder instance with the added vertex provider.
- Return type
- build(new_graph_name=None)¶
Create a new graph that is the result of the alteration of the current graph.
- Parameters
new_graph_name (Optional[str]) – name of the new graph to create.
- Returns
a PgxGraph instance of the current alteration builder.
- Return type
- build_new_snapshot()¶
Create a new snapshot for the current graph that is the result of the alteration of the current snapshot.
- Returns
a PgxGraph instance of the current alteration builder.
- Return type
- cascade_edge_provider_removals(cascade_edge_provider_removals)¶
Specify if the edge providers associated to a vertex provider (the vertex provider is either the source or destination provider for that edge provider) being removed should be automatically removed too or not. By default, edge providers are not automatically removed whenever an associated vertex is removed. In that setting, if the associated edge providers are not specifically removed, an exception will be thrown to indicate that issue.
- Parameters
cascade_edge_provider_removals (bool) – whether or not to automatically remove associated edge providers of removed vertex providers.
- Returns
a GraphAlterationBuilder instance with new changes.
- Return type
- remove_edge_provider(edge_provider_name)¶
Remove the edge provider that has the given name.
- Parameters
edge_provider_name (str) – the name of the provider to remove.
- Returns
a GraphAlterationBuilder instance with the edge_provider removed.
- Return type
- remove_vertex_provider(vertex_provider_name)¶
Remove the vertex provider that has the given name. Also removes the associated edge providers if True was specified when calling cascade_edge_provider_removals(boolean).
- Parameters
vertex_provider_name (str) – the name of the provider to remove.
- Returns
a GraphAlterationBuilder instance with the vertex_provider removed.
- Return type
- set_data_source_version(data_source_version)¶
Set the version information for the built graph or snapshot.
- Parameters
data_source_version (str) – the version information.
- Return type
None
- class pypgx.api.GraphBuilder(session, java_graph_builder, id_type)¶
Bases:
object
A graph builder for constructing a
PgxGraph
.- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- add_edge(src, dst, edge_id=None)¶
- Parameters
src (Union[pypgx.api._graph_builder.VertexBuilder, int]) – Source vertexBuilder or id
dst (Union[pypgx.api._graph_builder.VertexBuilder, int]) – Destination VertexBuilder or ID
edge_id (Optional[int]) – the ID of the new edge
- Return type
- add_vertex(vertex=None)¶
Add the vertex with the given id to the graph builder.
If the vertex doesn’t exist it is added, if it exists a builder for that vertex is returned Throws an UnsupportedOperationException if vertex ID generation strategy is set to IdGenerationStrategy.AUTO_GENERATED.
- Parameters
vertex (Optional[Union[str, int]]) – The ID of the new vertex
- Returns
A vertexBuilder instance
- Return type
- build(name=None)¶
- Parameters
name (Optional[str]) – The new name of the graph. If None, a name is generated.
- Returns
PgxGraph object
- Return type
- get_config_parameter(parameter)¶
Retrieve the value for the given config parameter
- Parameters
parameter (str) – the config parameter to get the value for
- Returns
the value for the given config parameter
- Return type
Union[bool, str]
- reset_edge(edge)¶
Reset any change for the given edge.
- Parameters
edge (Union[pypgx.api._graph_builder.EdgeBuilder, int]) – The id or the EdgeBuilder object to reset
- Returns
self
- reset_vertex(vertex)¶
Reset any change for the given vertex.
- Parameters
vertex (Union[pypgx.api._graph_builder.VertexBuilder, str, int]) – The id or the vertexBuilder object to reset
- Returns
self
- set_config_parameter(parameter, value)¶
Set the given configuration parameter to the given value
- Parameters
parameter (str) – the config parameter to set
value (Union[bool, str]) – the new value for the config parameter
- Return type
None
- set_data_source_version(version)¶
Set the version information for the built graph or snapshot.
- Parameters
version (str) –
- Return type
None
- set_retain_edge_ids(retain_edge_ids)¶
Control whether to retain the vertex ids provided in this graph builder are to be retained in the final graph. If True retain the vertex ids, if False use internally generated edge ids.
- Parameters
retain_edge_ids (bool) – Whether or not to retain edge ids
- Returns
self
- Return type
- set_retain_ids(retain_ids)¶
Control for both vertex and edge ids whether to retain them in the final graph.
- Parameters
retain_ids (bool) – Whether or not to retain vertex and edge ids
- Returns
self
- Return type
- set_retain_vertex_ids(retain_vertex_ids)¶
Control whether to retain the vertex ids provided in this graph builder are to be retained in the final graph. If True retain the vertex ids, if False use internally generated vertex ids of type Integer.
- Parameters
retain_vertex_ids (bool) – Whether or not to retain vertex ids
- Returns
self
- Return type
- class pypgx.api.GraphChangeSet(session, java_graph_change_set, id_type='integer')¶
Bases:
pypgx.api._graph_builder.GraphBuilder
Class which stores changes of a particular graph.
- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- add_edge(src_vertex, dst_vertex, edge_id=None)¶
Add an edge with the given edge ID and the given source and destination vertices.
- Parameters
src_vertex (Union[int, pypgx.api._graph_builder.VertexBuilder]) – source vertexBuilder or id.
dst_vertex (Union[int, pypgx.api._graph_builder.VertexBuilder]) – Destination VertexBuilder or ID.
edge_id (Optional[int]) – the ID of the new edge. Optional. Defaults to ‘None’.
- Returns
An ‘EdgeBuilder’ instance containing the added edge.
- Return type
- add_vertex(vertex_id)¶
Add the vertex with the given id to the graph builder.
- Parameters
vertex_id (Union[str, int]) – The vertex id of the vertex to add.
- Returns
A ‘VertexBuilder’ instance containing the added vertex.
- Return type
- build_new_snapshot()¶
Build a new snapshot of the graph out of this GraphChangeSet.
The resulting PgxGraph is a new snapshot of the PgxGraph object this was created from.
- Returns
A new object of type ‘PgxGraph’
- Return type
- remove_edge(edge_id)¶
Remove an edge from the graph.
- Parameters
edge_id (int) – The edge id of the edge to remove.
- Returns
self
- Return type
- remove_vertex(vertex_id)¶
Remove a vertex from the graph.
- Parameters
vertex_id (Union[int, str]) – The vertex id of the vertex to remove.
- Returns
self
- Return type
- reset_edge(edge_id)¶
Reset any change for the edge with the given ID.
- Parameters
edge_id (int) – The edge id of the edge to reset.
- Returns
self
- Return type
- reset_vertex(vertex)¶
Reset any change for the referenced vertex.
- Parameters
vertex (Union[int, str]) – Either an instance of ‘VertexBuilder’ or a vertex id.
- Returns
self
- Return type
- set_add_existing_edge_policy(add_existing_edge_policy)¶
Set the policy on what to do when an edge is added that already exists
- Parameters
add_existing_edge_policy (str) – the new policy
- Returns
this graph builder
- Return type
- set_add_existing_vertex_policy(add_existing_vertex_policy)¶
Set the policy on what to do when a vertex is added that already exists
- Parameters
add_existing_vertex_policy (str) – the new policy
- Returns
this graph builder
- Return type
- set_invalid_change_policy(invalid_change_policy)¶
Set the policy on what to do when an invalid action is added
- Parameters
invalid_change_policy (str) – the new policy
- Returns
this graph builder
- Return type
- set_required_conversion_policy(required_conversion_policy)¶
Set the policy on what to do when an invalid type is encountered
- Parameters
required_conversion_policy (str) – the new policy
- Returns
this graph builder
- Return type
- set_retain_edge_ids(retain_edge_ids)¶
Control whether the edge ids provided in this graph builder are to be retained in the final graph.
- Parameters
retain_edge_ids (bool) – A boolean value.
- Returns
self
- Return type
- set_retain_ids(retain_ids)¶
Control for both vertex and edge ids whether to retain them in the final graph.
- Parameters
retain_ids (bool) – A boolean value.
- Returns
self
- Return type
- set_retain_vertex_ids(retain_vertex_ids)¶
Control whether to retain the vertex ids provided in this graph builder are to be retained in the final graph.
- Parameters
retain_vertex_ids (bool) – A boolean value.
- Returns
self
- Return type
- update_edge(edge_id)¶
Return an ‘EdgeModifier’ with which you can update edge properties and the edge label.
- Parameters
edge_id (int) – The edge id of the edge to be updated
- Returns
An ‘EdgeModifier’
- Return type
- update_vertex(vertex_id)¶
Return a ‘VertexModifier’ with which you can update vertex properties.
- Parameters
vertex_id (Union[int, str]) – The vertex id of the vertex to be updated
- Returns
A ‘VertexModifier’
- Return type
- class pypgx.api.GraphConfig(java_graph_config)¶
Bases:
object
A class for representing graph configurations.
- Variables
is_file_format (bool) – whether the format is a file-based format
has_vertices_and_edges_separated_file_format (bool) – whether given format has vertices and edges separated in different files
is_single_file_format (bool) – whether given format has vertices and edges combined in same file
is_multiple_file_format (bool) – whether given format has vertices and edges separated in different files
supports_edge_label (bool) – whether given format supports edge label
supports_vertex_labels (bool) – whether given format supports vertex labels
supports_vector_properties (bool) – whether given format supports vector properties
supports_property_column (bool) – whether given format supports property columns
name (str) – the graph name of this graph configuration. Note: for file-based graph configurations, this is the file name of the URI this configuration points to.
num_vertex_properties (int) – the number of vertex properties in this graph configuration
num_edge_properties (int) – the number of edge properties in this graph configuration
format (str) – Graph data format. The possible formats are in the table below.
- Return type
None
Format string
Description
PGB
PGX Binary File Format (formerly EBIN)
EDGE_LIST
Edge List file format
TWO_TABLES
Two-Tables format (vertices, edges)
ADJ_LIST
Adjacency List File Format
FLAT_FILE
Flat File Format
GRAPHML
GraphML File Format
PG
Property Graph (PG) Database Format
RDF
Resource Description Framework (RDF) Database Format
CSV
Comma-Separated Values (CSV) Format
- property edge_id_type: Optional[str]¶
Get the type of the edge ID.
- Returns
a str indicating the type of the vertex ID, one of “INTEGER”, “LONG” or “STRING”, or None
- Return type
str or None
- property edge_property_types: Dict[str, str]¶
Get the edge property types as a dictionary.
- Returns
dict mapping property names to their types
- Return type
dict of str: str
- property edge_props: List[str]¶
Get the edge property names as a list.
- Return type
list of str
- property vertex_id_type: Optional[str]¶
Get the type of the vertex ID.
- Returns
a str indicating the type of the vertex ID, one of “INTEGER”, “LONG” or “STRING”, or None
- Return type
str or None
- property vertex_property_types: Dict[str, str]¶
Get the vertex property types as a dictionary.
- Returns
dict mapping property names to their types
- Return type
dict of str: str
- property vertex_props: List[str]¶
Get the vertex property names as a list.
- Return type
list of str
- class pypgx.api.GraphConfigFactory(java_graph_config_factory)¶
Bases:
object
A factory class for creating graph configs.
- Return type
None
- static for_any_format()¶
Return a new factory to parse any graph config from various input sources.
- static for_file_formats()¶
Return a new graph config factory to parse file-based graph configs from various input sources.
- static for_partitioned()¶
Return a new graph config factory to parse partitioned graph config.
- static for_property_graph_hbase()¶
Return a new graph config factory to create graph configs targeting the Apache HBase database in the property graph format.
- static for_property_graph_nosql()¶
Return a new graph config factory to create graph configs targeting the Oracle NoSQL database in the property graph format.
- static for_property_graph_rdbms()¶
Return a new graph config factory to create graph configs targeting the Oracle RDBMS database in the property graph format.
- static for_rdf()¶
Return a new RDF graph config factory.
- static for_two_tables_rdbms()¶
Return a new graph config factory to create graph configs targeting the Oracle RDBMS database in the two-tables format.
- static for_two_tables_text()¶
Return a new graph config factory to create graph configs targeting files in the two-tables format.
- from_file_path(path)¶
Parse a configuration object given as path to a JSON file.
Relative paths found in JSON are resolved relative to given file.
- Parameters
path (str) – The path to the JSON file
- Return type
- from_input_stream(stream)¶
Parse a configuration object given an input stream.
- Parameters
stream – A JAVA ‘InputStream’ object from where to read the configuration
- Return type
- from_json(json)¶
Parse a configuration object given a JSON string.
- Parameters
json (str) – The input JSON string
- Return type
- from_path(path)¶
Parse a configuration object given a path.
- Parameters
path (str) – The path from where to parse the configuration.
- Return type
- from_properties(properties)¶
Parse a configuration object from a properties object.
- Parameters
properties – A JAVA ‘Properties’ object
- Return type
- static init(want_strict_mode=True)¶
Setter function for the ‘strictMode’ class variable.
- Parameters
want_strict_mode (bool) – A boolean value which will be assigned to ‘strictMode’ (Default value = True)
- Return type
None
- class pypgx.api.GraphMetaData(java_graph_meta_data=None, vertex_id_type=None, edge_id_type=None)¶
Bases:
object
Meta information about PgxGraph.
- Parameters
vertex_id_type (Optional[str]) –
edge_id_type (Optional[str]) –
- Return type
None
- get_config()¶
Get the graph configuration object used to specify the data source of this graph.
- Returns
Returns the ‘GraphConfig’ object of this ‘GraphMetaData’ object.
- Return type
Optional[pypgx.api._graph_config.GraphConfig]
- get_creation_request_timestamp()¶
Get the timestamp (milliseconds since Jan 1st 1970) when this graph was requested to be created.
- Returns
A long value containing the timestamp.
- Return type
int
- get_creation_timestamp()¶
Get the timestamp (milliseconds since Jan 1st 1970) when this graph finished creation.
- Returns
A long value containing the timestamp.
- Return type
int
- get_data_source_version()¶
Get the format-specific version identifier provided by the data-source.
- Returns
A string containing the version.
- Return type
str
- get_memory_mb()¶
Get the estimated number of memory this graph (including its properties) consumes in memory (in megabytes).
- Returns
A long value containing the estimated amount of memory.
- Return type
int
- get_num_edges()¶
Get the number of edges.
- Returns
A long value containing the number of edges.
- Return type
int
- get_num_vertices()¶
Get the number of vertices.
- Returns
A long value containing the number of vertices.
- Return type
int
- hash_code()¶
Return the hash code of this object.
- Returns
An int value containing the hash code.
- Return type
int
- is_directed()¶
Return if the graph is directed.
- Returns
‘True’ if the graph is directed and ‘False’ otherwise.
- Return type
bool
- is_partitioned()¶
Return if the graph is partitioned or not.
- Returns
‘True’ if the graph is partitioned and ‘False’ otherwise.
- Return type
bool
- set_config(config)¶
Set a new ‘GraphConfig’.
- Parameters
config (pypgx.api._graph_config.GraphConfig) – An object of type ‘GraphConfig’.
- Return type
None
- set_creation_request_timestamp(creation_request_timestamp)¶
Set a new creation-request timestamp.
- Parameters
creation_request_timestamp (int) – A long value containing the new creation-request timestamp.
- Return type
None
- set_creation_timestamp(creation_timestamp)¶
Set a new creation timestamp.
- Parameters
creation_timestamp (int) – A long value containing the new creation timestamp.
- Return type
None
- set_data_source_version(data_source_version)¶
Set a new data source version.
- Parameters
data_source_version (str) – A string containing the new version.
- Return type
None
- set_directed(directed)¶
Assign a new truth value to the ‘directed’ variable.
- Parameters
directed (bool) – A boolean value
- Return type
None
- set_memory_mb(memory_mb)¶
Set a new amount of memory usage.
- Parameters
memory_mb (int) – A long value containing the new amount of memory.
- Return type
None
- set_num_edges(num_edges)¶
Set a new amount of edges.
- Parameters
num_edges (int) – A long value containing the new amount of edges.
- Return type
None
- set_num_vertices(num_vertices)¶
Set a new amount of vertices.
- Parameters
num_vertices (int) – A long value containing the new amount of edges.
- Return type
None
- class pypgx.api.GraphPropertyConfig(name=None, property_type=None, dimension=None, formats=None, default=None, column=None, stores=None, max_distinct_strings_per_pool=None, string_pooling_strategy=None, aggregate=None, field=None, group_key=None, drop_after_loading=None)¶
Bases:
object
A class for representing graph property configurations.
- Parameters
name (str) –
property_type (Optional[str]) –
dimension (Optional[int]) –
formats (Optional[List[str]]) –
default (Optional[Any]) –
column (Optional[Union[str, int]]) –
stores (Optional[List[Mapping[str, str]]]) –
max_distinct_strings_per_pool (Optional[int]) –
string_pooling_strategy (Optional[str]) –
aggregate (Optional[str]) –
field (Optional[str]) –
group_key (Optional[str]) –
drop_after_loading (Optional[bool]) –
- Return type
None
- get_aggregate()¶
Which aggregation function to use, aggregation always happens by vertex key
- Returns
aggregation function to use
- Return type
str
- get_column()¶
Get name or index (starting from 1) of the column holding the property data. If it is not specified, the loader will try to use the property name as column name (for CSV format only)
- Returns
column of property
- Return type
Union[int, str]
- static get_config_fields()¶
Return the config fields
- Returns
list of config fields
- Return type
List[str]
- get_default()¶
Get default value to be assigned to this property if datasource does not provide it. In case of date type: string is expected to be formatted with yyyy-MM-dd HH:mm:ss. If no default is present, non-existent properties will contain default Java types (primitives) or empty string or 01.01.1970 00:00.
- Returns
default of property
- Return type
Any
- get_dimension()¶
Get dimension of property
- Returns
dimension of property
- Return type
int
- get_field()¶
Get name of the JSON field holding the property data. Nesting is denoted by dot - separation. Field names containing dots are possible, in this case the dots need to be escaped using backslashes to resolve ambiguities. Only the exactly specified object are loaded, if they are non existent, the default value is used
- Returns
name of the JSON field
- Return type
str
- get_format()¶
Get list of formats of property
- Returns
list of formats of property
- Return type
List[str]
- get_group_key()¶
Can only be used if the property / key is part of the grouping expression
- Returns
group key
- Return type
str
- get_max_distinct_strings_per_pool()¶
Get amount of distinct strings per property after which to stop pooling. If the limit is reached an exception is thrown. If set to null, the default value from the global PGX configuration will be used.
- Returns
amount of distinct strings per property after which to stop pooling
- Return type
int
- get_name()¶
Get name of property
- Returns
name of property
- Return type
str
- get_parsed_default_value()¶
Get the parsed default value guaranteed to match the property type (with the exception of type node/edge). In case a default is not specified, the default default value is returned.
- Returns
the parsed default value
- Return type
Any
- get_source_column()¶
Return column if indicated, otherwise return the property name
- Returns
the source column
- Return type
Union[int, str]
- get_stores()¶
Get list of storage identifiers that indicate where this property resides.
- Returns
list of storage identifiers
- Return type
List[Mapping[str, str]]
- get_string_pooling_strategy()¶
Get which string pooling strategy to use. If set to null, the default value from the global PGX configuration will be used.
- Returns
string pooling strategy to use
- Return type
str
- get_type()¶
Get type of property
- Returns
type of proeprty
- Return type
str
- static get_value_from_environment(key)¶
Look up a value by a key from java properties and the system environment. Looks up the provided key first in the java system properties prefixed with SYSTEM_PROPERTY_PREFIX and returns the value if present. If it is not present, looks it up in the system environment prefixed with ENV_VARIABLE_PREFIX and returns this one if present. Returns None if the key is neither found in the properties nor in the environment.
- Parameters
key (str) – the key to look up
- Returns
the found value or None if the key is not available
- Return type
str
- has_default_value(field)¶
Check if field has a default value.
- Parameters
field (str) – the field
- Returns
True, if value for given field is the default value
- Return type
bool
- is_drop_after_loading()¶
Whether helper properties are only used for aggregation, which are dropped after loading
- Returns
True, if helper properties are dropped after loading
- Return type
bool
- is_empty()¶
Check if it’s empty.
- Returns
True, if the Map ‘values’ is empty.
- Return type
bool
- is_external()¶
Whether the property is external
- Returns
True if the property is external, False otherwise
- Return type
bool
- is_in_memory()¶
Whether the property is in memory
- Returns
True if the property is in memory, False otherwise
- Return type
bool
- is_string_pool_enabled()¶
Whether the string pool is enabled
- Returns
True if the the string pool is enabled, False otherwise
- Return type
bool
- set_serializable(serializable)¶
Set this config to be serializable
- Parameters
serializable (bool) – True if serializable, False otherwise
- Returns
- Return type
None
- class pypgx.api.MatrixFactorizationModel(graph, java_mfm, features)¶
Bases:
object
Object that holds the state for repeatedly returning estimated ratings.
- Parameters
graph (PgxGraph) –
- Return type
None
- get_estimated_ratings(v)¶
Return estimated ratings for a specific vertex.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, str, int]) – The vertex to get estimated ratings for.
- Returns
The VertexProperty containing the estimated ratings.
- Return type
float
- class pypgx.api.MergingStrategyBuilder(java_mutation_strategy_builder)¶
Bases:
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
A class for defining a merging strategy on a graph.
- Return type
None
- set_keep_user_defined_edge_keys(keep_user_defined_edge_keys)¶
If set to True, the user-defined edge keys are kept as far as possible.
If multiple edges A and B are merged into one edge, a new key is generated for this edge.
- Parameters
keep_user_defined_edge_keys (bool) – whether to keep user-defined edge keys
- Returns
the MergingStrategyBuilder itself
- Return type
- set_label_merging_strategy(label_merging_function)¶
Define a merging function for the edge labels.
By default (without calling this), the labels will be merged using the “max” function
- Parameters
label_merging_function (str) – available functions are: “min” and “max”
- Returns
the MergingStrategyBuilder itself
- Return type
- set_property_merging_strategy(prop, merging_function)¶
Define a merging function for the given edge property.
All properties, where no merging_function was defined will be merged using the “max” function.
This strategy can be used to merge the properties of multi-edges. PGX allows the user to define a merging_function for every property.
- Parameters
prop (Union[str, pypgx.api._pgx_id.PgxId, pypgx.api._property.EdgeProperty]) – a property name, PgxId, or EdgeProperty
merging_function (str) – available functions are: “min”, “max”, and “sum”
- Returns
the MergingStrategyBuilder itself
- Return type
- class pypgx.api.MutationStrategyBuilder(java_mutation_strategy_builder)¶
Bases:
object
A class for defining a mutation strategy on a graph.
- Return type
None
- build()¶
Build the MutationSrategy object with the chosen parameters.
Parameters that were not set, are instantiated with default values.
- Returns
a MutationStrategy instance with the chosen parameters
- Return type
pypgx.api._mutation_strategy.MutationStrategy
- drop_edge_properties(edge_properties)¶
- Set edge properties that will be dropped after the mutation.
By default (without calling this) all edgeProperties will be kept.
- Parameters
edge_properties (List[pypgx.api._property.EdgeProperty]) – list of EdgeProperty objects to drop
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- drop_edge_property(edge_property)¶
Set an edge property that will be dropped after the mutation.
By default (without calling this), all edge properties will be kept.
- Parameters
edge_property (pypgx.api._property.EdgeProperty) – EdgeProperty object to drop
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- drop_vertex_properties(vertex_properties)¶
Set vertex properties that will be dropped after the mutation.
By default (without calling this), all edge properties will be kept.
- Parameters
vertex_properties (List[pypgx.api._property.VertexProperty]) – list of VertexProperty objects to drop
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- drop_vertex_property(vertex_property)¶
Set a vertex property that will be dropped after the mutation.
By default (without calling this), all vertex properties will be kept.
- Parameters
vertex_property (pypgx.api._property.VertexProperty) – VertexProperty object to drop
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_copy_mode(copy_mode)¶
Define whether the mutation should occur on the original graph or on a copy.
If set to True, the mutation will occur on the original graph without creating a new instance. If set to False, a new graph instance will be created. The default copy mode is False.
- Parameters
copy_mode (bool) – whether to mutate the original graph or create a new one
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_kept_edge_properties(props_to_keep)¶
Set edge properties that will be kept after the mutation.
By default (without calling this), all edge properties will be kept.
- Parameters
props_to_keep (List[pypgx.api._property.EdgeProperty]) – list of EdgeProperty objects to keep
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_kept_vertex_properties(props_to_keep)¶
Set vertex properties that will be kept after the mutation.
By default (without calling this), all vertex properties will be kept.
- Parameters
props_to_keep (List[pypgx.api._property.VertexProperty]) – list of VertexProperty objects to keep
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_multi_edges(keep_multi_edges)¶
Define if multi edges should be kept in the result.
By default (without calling this), multi edges will be removed.
- Parameters
copy_multi_edges – whether to keep or remove multi edges in the result
keep_multi_edges (bool) –
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_new_graph_name(new_graph_name)¶
Set a new graph name. If None, a new graph name will be generated.
- Parameters
new_graph_name (Optional[str]) – a new graph name
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_self_edges(keep_self_edges)¶
Define if self edges should be kept in the result.
By default (without calling this), self edges will be removed.
- Parameters
copy_self_edges – whether to keep or remove self edges in the result
keep_self_edges (bool) –
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- set_trivial_vertices(keep_trivial_vertices)¶
Define if isolated nodes should be kept in the result.
By default (without calling this), isolated nodes will be kept.
- Parameters
keep_trivial_vertices (bool) – whether to keep or remove trivial vertices in the result
- Returns
the MutationStrategyBuilder instance itself
- Return type
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
- class pypgx.api.Namespace(java_namespace)¶
Bases:
object
Represents a namespace for objects (e.g. graphs, properties) in PGX.
Note
This class is just a thin wrapper and does not check if the input is actually a java namespace.
- Return type
None
- get_java_namespace()¶
Get the java namespace object.
- Return type
oracle.pgx.api.Namespace
- class pypgx.api.PgqlResultSet(graph, java_pgql_result_set)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
Result set of a pattern matching query.
Note: retrieving results from the server is not thread-safe.
- Parameters
graph (Optional[PgxGraph]) –
- Return type
None
- absolute(row)¶
Move the cursor to the given row number in this ResultSet object.
If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set. The first row is 1, so absolute(1) moves the cursor to the first row.
If the row number is negative, the cursor moves to the given row number with respect to the end of the result set. So absolute(-1) moves the cursor to the last row.
- Parameters
row (int) – Row to move to
- Returns
True if the cursor is moved to a position in the ResultSet object; False if the cursor is moved before the first or after the last row
- Return type
bool
- after_last()¶
Place the cursor after the last row
- Return type
None
- before_first()¶
Set the cursor before the first row
- Return type
None
- close()¶
Free resources on the server taken up by this frame.
- Return type
None
- first()¶
Move the cursor to the first row in the result set
- Returns
True if the cursor points to a valid row; False if the result set does not have any results
- Return type
bool
- get(element)¶
Get the value of the designated element by element index or name
- Parameters
element (Union[str, int]) – Integer or string representing index or name
- Returns
Content of cell
- Return type
Any
- get_boolean(element)¶
Get the value of the designated element by element index or name as a Boolean
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Boolean
- Return type
bool
- get_date(element)¶
Get the value of the designated element by element index or name as a datetime Date
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.date
- Return type
datetime.date
- get_double(element)¶
Get the value of the designated element by element index or name as a Float
This method is for precision, as a Java floats and doubles have different precisions
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Float
- Return type
float
- get_edge(element)¶
Get the value of the designated element by element index or name as a PgxEdge
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
PgxEdge
- Return type
- get_float(element)¶
Get the value of the designated element by element index or name as a Float
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Float
- Return type
float
- get_integer(element)¶
Get the value of the designated element by element index or name as an Integer
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Integer
- Return type
int
- get_legacy_datetime(element)¶
Get the value of the designated element by element index or name as a Datetime. Works with most time and date type cells. If the date is not specified, default is set to to Jan 1 1970.
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_list(element)¶
Get the value of the designated element by element index or name as a List
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
List
- Return type
Optional[List[str]]
- get_long(element)¶
Get the value of the designated element by element index or name as a Long
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
Long
- Return type
int
- get_point2d(element)¶
Get the value of the designated element by element index or name as a 2D tuple
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
(X, Y)
- Return type
Tuple[float, float]
- get_row(row)¶
Get row from result_set. This method may change result_set cursor.
- Parameters
row (int) – Row index
- Return type
Any
- get_slice(start, stop, step=1)¶
Get slice from result_set. This method may change result_set cursor.
- Parameters
start (int) – Start index
stop (int) – Stop index
step (int) – Step size
- Return type
List[list]
- get_string(element)¶
Get the value of the designated element by element index or name as a String
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
String
- Return type
str
- get_time(element)¶
Get the value of the designated element by element index or name as a datetime Time
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.time
- Return type
datetime.time
- get_time_with_timezone(element)¶
Get the value of the designated element by element index or name as a datetime Time that includes timezone
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.time
- Return type
datetime.time
- get_timestamp(element)¶
Get the value of the designated element by element index or name as a Datetime
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_timestamp_with_timezone(element)¶
Get the value of the designated element by element index or name as a Datetime
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
datetime.datetime
- Return type
datetime.datetime
- get_vertex(element)¶
Get the value of the designated element by element index or name as a PgxVertex
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
PgxVertex
- Return type
- get_vertex_labels(element)¶
Get the value of the designated element by element index or name a list of labels
- Parameters
element (Union[str, int]) – Integer or String representing index or name
- Returns
list
- Return type
List[str]
- last()¶
Move the cursor to the first row in the result set
- Returns
True if the cursor points to a valid row; False if the result set does not have any results
- Return type
bool
- next()¶
Move the cursor forward one row from its current position
- Returns
True if the cursor points to a valid row; False if the new cursor is positioned after the last row
- Return type
bool
- previous()¶
Move the cursor to the previous row from its current position
- Returns
True if the cursor points to a valid row; False if the new cursor is positioned before the first row
- Return type
bool
- print(file=None, num_results=1000, start=0)¶
Print the result set.
- Parameters
file (Optional[TextIO]) – File to which results are printed (default is
sys.stdout
)num_results (int) – Number of results to be printed
start (int) – Index of the first result to be printed
- Return type
None
- relative(rows)¶
Move the cursor a relative number of row with respect to the current position. A negative number will move the cursor backwards.
Note: Calling relative(1) is equal to next() and relative(-1) is equal to previous. Calling relative(0) is possible when the cursor is positioned at a row, not when it is positioned before the first or after the last row. However, relative(0) will not update the position of the cursor.
- Parameters
rows (int) – Relative number of rows to move from current position
- Returns
True if the cursor is moved to a position in the ResultSet object; False if the cursor is moved before the first or after the last row
- Return type
bool
- to_frame()¶
Copy the content of this result set into a new PgxFrames
- Returns
a new PgxFrame containing the content of the result set
- Return type
- to_pandas()¶
Convert to pandas DataFrame.
This method may change result_set cursor.
This method requires pandas.
- Returns
PgqlResultSet as a Pandas Dataframe
- class pypgx.api.Pgx(java_pgx_class)¶
Bases:
object
Main entry point for PGX applications.
- Return type
None
- create_session(source=None, base_url=None)¶
Create and return a session.
- Parameters
source (Optional[str]) – The session source string. Default value is “pgx_python”.
base_url (Optional[str]) – The base URL in the format host [ : port][ /path] of the PGX server REST end-point. If base_url is None, the default will be used which points to embedded PGX instance.
- Return type
- get_instance(base_url=None, token=None)¶
Get a handle to a PGX instance.
- Parameters
base_url (Optional[str]) – The base URL in the format host [ : port][ /path] of the PGX server REST end-point. If base_url is None, the default will be used which points to embedded PGX instance.
token (Optional[str]) – The access token
- Return type
- set_default_url(url)¶
Set the default base URL used by invocations of get_instance().
The new default URL affects sub-sequent calls of getInstance().
- Parameters
url (str) – New URL
- Return type
None
- class pypgx.api.PgxCollection(graph, java_collection)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
Superclass for Pgx collections.
- Parameters
graph (Optional[PgxGraph]) –
- Return type
None
- add_all_elements(source)¶
Add elements to an existing collection.
- Parameters
source (Iterable[Union[pypgx.api._pgx_entity.PgxEdge, pypgx.api._pgx_entity.PgxVertex]]) – Elements to add
- Return type
None
- clear()¶
Clear an existing collection.
- Returns
None
- Return type
None
- clone(name=None)¶
Clone and rename existing collection.
- Parameters
name (Optional[str]) – New name of the collection. If none, the old name is not changed.
- Return type
- close()¶
Request destruction of this object. After this method returns, the behavior of any method of this class becomes undefined.
- Return type
None
- destroy()¶
Request destruction of this object.
After this method returns, the behavior of any method of this class becomes undefined.
- Returns
None
- Return type
None
- get_id()¶
Return the string representation of an internal identifier for this collection. Only meant for internal usage.
- Returns
a string representation of the internal identifier of this collection
- Return type
str
- get_pgx_id()¶
Return an internal identifier for this collection. Only meant for internal usage.
- Returns
the internal identifier of this collection
- Return type
- remove_all_elements(source)¶
Remove elements from an existing collection.
- Parameters
source (Iterable[Union[pypgx.api._pgx_entity.PgxEdge, pypgx.api._pgx_entity.PgxVertex]]) – Elements to remove
- Return type
None
- property size: int¶
Get the number of elements in this collection.
- to_mutable(name=None)¶
Create a mutable copy of an existing collection.
- Parameters
name (Optional[str]) – New name of the collection. If none, the old name is not changed.
- Return type
- class pypgx.api.PgxEdge(graph, java_edge)¶
Bases:
pypgx.api._pgx_entity.PgxEntity
An edge of a
PgxGraph
.- Return type
None
- property label: str¶
Return the edge label.
- property vertices: Tuple[pypgx.api._pgx_entity.PgxVertex, pypgx.api._pgx_entity.PgxVertex]¶
Return the source and the destination vertex.
- class pypgx.api.PgxEntity(graph, java_entity)¶
Bases:
object
An abstraction of vertex and edge.
- Parameters
graph (PgxGraph) –
- Return type
None
- get_property(property_name)¶
Get a property by name.
- Parameters
property_name (str) – Property name
- Return type
Any
- property id¶
Get the entity id.
- set_property(property_name, value)¶
Set an entity property.
- Parameters
property_name (str) – Property name
value (Any) – New value
- Return type
None
- class pypgx.api.PgxGraph(session, java_graph)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A reference to a graph on the server side.
Operations on instances of this class are executed on the server side onto the referenced graph. Note that a session can have multiple objects referencing the same graph: the result of any operation mutating the graph on any of those references will be visible on all of them.
- Parameters
session (PgxSession) –
- Return type
None
- add_redaction_rule(redaction_rule_config, authorization_type, *names)¶
Add a redaction rule for authorization_type names.
Possible authorization types are: [‘user’, ‘role’]
- Parameters
authorization_type (str) – the authorization type of the rule to be added
names (str) – the names of the users or roles for which the rule should be added
redaction_rule_config (pypgx.api.redaction._redaction_rule_config.PgxRedactionRuleConfig) –
- Return type
None
- alter_graph()¶
Create a graph alteration builder to define the graph schema alterations to perform on the graph.
- Returns
an empty graph alteration builder
- Return type
- bipartite_sub_graph_from_in_degree(vertex_properties=True, edge_properties=True, name=None, is_left_name=None, in_place=False)¶
Create a bipartite version of this graph with all vertices of in-degree = 0 being the left set.
- Parameters
vertex_properties (Union[List[pypgx.api._property.VertexProperty], bool]) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (bool) – List of edge properties belonging to graph specified to be kept in the new graph
name (Optional[str]) – New graph name
is_left_name (Optional[str]) – Name of the boolean isLeft vertex property of the new graph. If None, a name will be generated.
in_place (bool) – Whether to create a new copy (False) or overwrite this graph (True)
- Return type
- bipartite_sub_graph_from_left_set(vset, vertex_properties=True, edge_properties=True, name=None, is_left_name=None)¶
Create a bipartite version of this graph with the given vertex set being the left set.
- Parameters
vset (Union[str, pypgx.api._pgx_collection.VertexSet]) – Vertex set representing the left side
vertex_properties (Union[List[pypgx.api._property.VertexProperty], bool]) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (bool) – List of edge properties belonging to graph specified to be kept in the new graph
name (Optional[str]) – name of the new graph. If None, a name will be generated.
is_left_name (Optional[str]) – Name of the boolean isLeft vertex property of the new graph. If None, a name will be generated.
- Return type
- clone(vertex_properties=True, edge_properties=True, name=None)¶
Return a copy of this graph.
- Parameters
vertex_properties (bool) – List of vertex properties belonging to graph specified to be cloned as well
edge_properties (bool) – List of edge properties belonging to graph specified to be cloned as well
name (Optional[str]) – Name of the new graph
- Return type
- clone_and_execute_pgql(pgql_query)¶
Create a deep copy of the graph, and execute on it the pgql query.
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
A cloned PgxGraph with the pgql query executed
- Return type
- throws InterruptedException if the caller thread gets interrupted while waiting for
completion.
- throws ExecutionException if any exception occurred during asynchronous execution.
The actual exception will be nested.
- close()¶
Destroy without waiting for completion.
- Return type
None
- combine_edge_properties_into_vector_property(properties, name=None)¶
Take a list of scalar edge properties of same type and create a new edge vector property by combining them.
The dimension of the vector property will be equals to the number of properties.
- Parameters
properties (List[Union[pypgx.api._property.EdgeProperty, str]]) – List of scalar edge properties
name (Optional[str]) – Name for the vector property. If not null, vector property will be named. If that results in a name conflict, the returned future will complete exceptionally.
- Return type
- combine_vertex_properties_into_vector_property(properties, name=None)¶
Take a list of scalar vertex properties of same type and create a new vertex vector property by combining them.
The dimension of the vector property will be equals to the number of properties.
- Parameters
properties (List[Union[pypgx.api._property.VertexProperty, str]]) – List of scalar vertex properties
name (Optional[str]) – Name for the vector property. If not null, vector property will be named. If that results in a name conflict, the returned future will complete exceptionally.
- Return type
- property config: pypgx.api._graph_config.GraphConfig¶
Get the GraphConfig object.
- create_all_paths(src, cost, dist, parent, parent_edge)¶
Create an AllPaths object representing all the shortest paths from a single source to all the possible destinations (shortest regarding the given edge costs).
- Parameters
src (Union[str, pypgx.api._pgx_entity.PgxVertex]) – Source vertex of the path
cost (Optional[Union[str, pypgx.api._property.EdgeProperty]]) – Property holding the edge costs. If None, the resulting cost will equal the hop distance
dist (Union[pypgx.api._property.VertexProperty, str]) – Property holding the distance to the source vertex for each vertex in the graph
parent (Union[pypgx.api._property.VertexProperty, str]) – Property holding the parent vertices of all the shortest paths For example, if the shortest path is A -> B -> C, then parent[C] -> B and parent[B] -> A
parent_edge (Union[pypgx.api._property.VertexProperty, str]) – Property holding the parent edges for each vertex of the shortest path
- Returns
The AllPaths object
- Return type
- create_change_set(vertex_id_generation_strategy='user_ids', edge_id_generation_strategy='auto_generated')¶
Create a change set for updating the graph.
Uses auto generated IDs for the edges.
Note
This is currently not supported for undirected graphs.
- Returns
an empty change set
- Return type
- Parameters
vertex_id_generation_strategy (str) –
edge_id_generation_strategy (str) –
- create_components(components, num_components)¶
Create a Partition object holding a collection of vertex sets, one for each component.
- Parameters
components (Union[pypgx.api._property.VertexProperty, str]) – Vertex property mapping each vertex to its component ID. Note that only component IDs in the range of [0..numComponents-1] are allowed. The returned future will complete exceptionally with an IllegalArgumentException if an invalid component ID is encountered. Gaps are supported: certain IDs not being associated with any vertices will yield to empty components.
num_components (int) – How many different components the components property contains
- Returns
The Partition object
- Return type
- create_edge_property(data_type, name=None)¶
Create a session-bound edge property.
- Parameters
data_type (str) – Type of the vector property to create
name (Optional[str]) – Name of vector property to be created
- Return type
- create_edge_sequence(name=None)¶
Create a new edge sequence.
- Parameters
name (Optional[str]) – Sequence name
- Return type
- create_edge_set(name=None)¶
Create a new edge set.
- Parameters
name (Optional[str]) – Edge set name
- Return type
- create_edge_vector_property(data_type, dim, name=None)¶
Create a session-bound vector property.
- Parameters
data_type (str) – Type of the vector property to create
dim (int) – Dimension of vector property to be created
name (Optional[str]) – Name of vector property to be created
- Return type
- create_map(key_type, val_type, name=None)¶
Create a session-bound map.
Possible types are: [‘integer’,’long’,’double’,’boolean’,’string’,’vertex’,’edge’, ‘local_date’,’time’,’timestamp’,’time_with_timezone’,’timestamp_with_timezone’]
- Parameters
key_type (str) – Property type of the keys that are going to be stored inside the map
val_type (str) – Property type of the values that are going to be stored inside the map
name (Optional[str]) – Map name
- Return type
- create_merging_strategy_builder()¶
Create a new MergingStrategyBuilder that can be used to build a new MutationStrategy to simplify this graph.
- create_path(src, dst, cost, parent, parent_edge)¶
- Parameters
src (pypgx.api._pgx_entity.PgxVertex) – Source vertex of the path
dst (pypgx.api._pgx_entity.PgxVertex) – Destination vertex of the path
cost (pypgx.api._property.EdgeProperty) – Property holding the edge costs. If null, the resulting cost will equal the hop distance.
parent (pypgx.api._property.VertexProperty) – Property holding the parent vertices for each vertex of the shortest path. For example, if the shortest path is A -> B -> C, then parent[C] -> B and parent[B] -> A.
parent_edge (pypgx.api._property.VertexProperty) – Property holding the parent edges for each vertex of the shortest path
- Returns
The PgxPath object
- Return type
- create_picking_strategy_builder()¶
Create a new PickingStrategyBuilder that can be used to build a new PickingStrategy to simplify this graph.
- create_scalar(data_type, name=None)¶
Create a new Scalar.
- Parameters
data_type (str) – Scalar type
name (Optional[str]) – Name of the scalar to be created
- Return type
- create_synchronizer(synchronizer_class='oracle.pgx.api.FlashbackSynchronizer', connection=None, invalid_change_policy=None)¶
Create a synchronizer object which can be used to keep this graph in sync with changes happening in its original data source. Only partitioned graphs with all providers loaded from Oracle Database are supported.
- Possible invalid_change_policy types are: [‘ignore’, ‘ignore_and_log’,
‘ignore_and_log_once’, ‘error’]
- Parameters
synchronizer_class (str) – string representing java class including package, currently ‘oracle.pgx.api.FlashbackSynchronize’ is the only existent option
connection (Optional[Any]) – the connection object to the RDBMS (# TODO : GM-28504)
invalid_change_policy (Optional[str]) – sets the OnInvalidChange parameter to the Synchronizer ChangeSet
- Returns
a synchronizer
- Return type
- create_vector_scalar(data_type, dimension=0, name=None)¶
Create a new vertex property.
- Parameters
data_type (str) – Property type
dimension (int) – the dimension of the vector property
name (Optional[str]) – Name of the scalar to be created
- Return type
- create_vertex_property(data_type, name=None)¶
Create a new vertex property.
- Parameters
data_type (str) – Property type
name (Optional[str]) – Name of the property to be created
- Return type
- create_vertex_sequence(name=None)¶
Create a new vertex sequence.
- Parameters
name (Optional[str]) – Sequence name
- Return type
- create_vertex_set(name=None)¶
Create a new vertex set.
- Parameters
name (Optional[str]) – Set name
- Return type
- create_vertex_vector_property(data_type, dim, name=None)¶
Create a session-bound vertex vector property.
- Parameters
data_type (str) – Type of the vector property to create
dim (int) – Dimension of vector property to be created
name (Optional[str]) – Name of vector property to be created
- Return type
- destroy()¶
Destroy the graph with all its properties.
After this operation, neither the graph nor its properties can be used anymore within this session.
Note
if you have multiple
PgxGraph
objects referencing the same graph (e.g. because you calledPgxSession.get_graph()
multiple times with the same argument), they will ALL become invalid after calling this method; therefore, subsequent operations on ANY of them will result in an exception.- Return type
None
- destroy_edge_property_if_exists(name)¶
Destroy a specific edge property if it exists.
- Parameters
name (str) – Property name
- Return type
None
- destroy_vertex_property_if_exists(name)¶
Destroy a specific vertex property if it exists.
- Parameters
name (str) – Property name
- Return type
None
- execute_pgql(pgql_query)¶
(BETA) Blocking version of cloneAndExecutePgqlAsync(String).
Calls cloneAndExecutePgqlAsync(String) and waits for the returned PgxFuture to complete.
throws InterruptedException if the caller thread gets interrupted while waiting for completion.
throws ExecutionException if any exception occurred during asynchronous execution. The actual exception will be nested.
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
The query result set as PgqlResultSet object
- Return type
Optional[pypgx.api._pgql_result_set.PgqlResultSet]
- expand_with_pgql(pgql_queries, new_graph_name=None, pg_view_name=None, as_snapshot=False)¶
Expand this graph with data matching one or more PGQL queries. Given a list of either queries or prepared queries (with arguments), this will load all data matching at least on of the queries and merge it with the data from this graph.
- Parameters
pgql_queries (Union[str, pypgx.api._graph_offloading.PreparedPgqlQuery, List[Union[str, pypgx.api._graph_offloading.PreparedPgqlQuery]]]) – One or more PGQL queries (or prepared queries).
new_graph_name (Optional[str]) – An optional name for the new graph.
pg_view_name (Optional[str]) – The PG View name from which to load the data.
scn – The SCN as of which the data should be loaded (optional).
as_snapshot (bool) – Expand as a new snapshot, instead of new graph?
- Returns
The graph containing data both from this graph and the external source.
- Return type
- explain_pgql(pgql_query)¶
Explain the execution plan of a pattern matching query.
Note: Different PGX versions may return different execution plans.
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
The query plan
- Return type
pypgx.api._operation.Operation
- filter(graph_filter, vertex_properties=True, edge_properties=True, name=None)¶
Create a subgraph of this graph.
To create the subgraph, a given filter expression is used to determine which parts of the graph will be part of the subgraph.
- Parameters
graph_filter (Union[str, pypgx.api.filters._graph_filter.VertexFilter, pypgx.api.filters._graph_filter.EdgeFilter]) – Object representing a filter expression that is applied to create the subgraph
vertex_properties (bool) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (bool) – List of edge properties belonging to graph specified to be kept in the new graph
name (Optional[str]) – Filtered graph name
- Return type
- get_collections()¶
Retrieve all currently allocated collections associated with the graph.
- Return type
Dict[str, pypgx.api._pgx_collection.PgxCollection]
- get_edge(eid)¶
Get an edge with a specified id.
- Parameters
eid (int) – edge id
- Return type
- get_edge_label()¶
Get the edge labels belonging to this graph.
- Return type
- get_edge_properties()¶
Get the set of edge properties belonging to this graph.
This list might contain transient, private and published properties.
- Return type
- get_edge_property(name)¶
Get an edge property by name.
- Parameters
name (str) – Property name
- Return type
Optional[pypgx.api._property.EdgeProperty]
- get_edges(filter_expr=None, name=None)¶
Create a new edge set containing vertices according to the given filter expression.
- Parameters
filter_expr (Optional[Union[str, pypgx.api.filters._graph_filter.EdgeFilter]]) – EdgeFilter object with the filter expression. If None all the vertices are returned.
name (Optional[str]) – the name of the collection to be created. If None, a name will be generated.
- Return type
- get_id()¶
Get the Graph id.
- Returns
A string representation of the id of this graph.
- Return type
str
- get_meta_data()¶
Get the GraphMetaData object.
- Returns
A ‘GraphMetaData’ object of this graph.
- Return type
- get_or_create_edge_property(name, data_type=None, dim=0)¶
Get or create an edge property.
- Parameters
name (str) – Property name
data_type (Optional[str]) – Property type
dim (int) – Dimension of vector property to be created
- Return type
- get_or_create_edge_vector_property(data_type, dim, name=None)¶
Get or create a session-bound edge property.
- Parameters
data_type (str) – Type of the vector property to create
dim (int) – Dimension of vector property to be created
name (Optional[str]) – Name of vector property to be created
- Return type
- get_or_create_vertex_property(name, data_type=None, dim=0)¶
Get or create a vertex property.
- Parameters
name (str) – Property name
data_type (Optional[str]) – Property type
dim (int) – Dimension of vector property to be created
- Return type
- get_or_create_vertex_vector_property(data_type, dim, name=None)¶
Get or create a session-bound vertex vector property.
- Parameters
data_type (str) – Type of the vector property to create
dim (int) – Dimension of vector property to be created
name (Optional[str]) – Name of vector property to be created
- Return type
- get_permission()¶
Return permission object for the graph.
- get_pgx_id()¶
Get the Graph id.
- Returns
The id of this graph.
- Return type
- get_random_edge()¶
Get a edge vertex from the graph.
- Return type
- get_random_vertex()¶
Get a random vertex from the graph.
- Return type
- get_redaction_rules(authorization_type, name)¶
Get the redaction rules for an authorization_type name.
Possible authorization types are: [‘user’, ‘role’]
- Parameters
authorization_type (str) – the authorization type of the rules to be returned
name (str) – the name of the user or role for which the rules should be returned
- Returns
a list of redaction rules for the given name of type authorization_type
- Return type
List[pypgx.api.redaction._redaction_rule_config.PgxRedactionRuleConfig]
- get_vertex(vid)¶
Get a vertex with a specified id.
- Parameters
vid (Union[str, int]) – Vertex id
- Returns
pgxVertex object
- Return type
- get_vertex_labels()¶
Get the vertex labels belonging to this graph.
- Return type
- get_vertex_properties()¶
Get the set of vertex properties belonging to this graph.
This list might contain transient, private and published properties.
- Return type
- get_vertex_property(name)¶
Get a vertex property by name.
- Parameters
name (str) – Property name
- Return type
Optional[pypgx.api._property.VertexProperty]
- get_vertices(filter_expr=None, name=None)¶
Create a new vertex set containing vertices according to the given filter expression.
- Parameters
filter_expr (Optional[Union[str, pypgx.api.filters._graph_filter.VertexFilter]]) – VertexFilter object with the filter expression if None all the vertices are returned
name (Optional[str]) – The name of the collection to be created. If None, a name will be generated.
- Return type
- grant_permission(permission_entity, pgx_resource_permission)¶
Grant a permission on this graph to the given entity.
Possible PGXResourcePermission types are: [‘none’, ‘read’, ‘write’, ‘export’, ‘manage’] Possible PermissionEntity objects are: PgxUser and PgxRole.
Cannont grant ‘manage’.
- Parameters
permission_entity (pypgx.api.auth._permission_entity.PermissionEntity) – the entity the rule is granted to
pgx_resource_permission (str) – the permission type
- Return type
None
- has_edge(eid)¶
Check if the edge with id vid is in the graph.
- Parameters
eid (int) – Edge id
- Return type
bool
- has_edge_label()¶
Return True if the graph has edge labels, False if not.
- Return type
bool
- has_vertex(vid)¶
Check if the vertex with id vid is in the graph.
- Parameters
vid (int) – vertex id
- Return type
bool
- has_vertex_labels()¶
Return True if the graph has vertex labels, False if not.
- Return type
bool
- is_bipartite(is_left)¶
Check whether a given graph is a bipartite graph.
A graph is considered a bipartite graph if all nodes can be divided in a ‘left’ and a ‘right’ side where edges only go from nodes on the ‘left’ side to nodes on the ‘right’ side.
- Parameters
is_left (Union[pypgx.api._property.VertexProperty, str]) – Boolean vertex property that - if the method returns true - will contain for each node whether it is on the ‘left’ side of the bipartite graph. If the method returns False, the content is undefined.
- Return type
int
- property is_fresh: bool¶
Check whether an in-memory representation of a graph is fresh.
- is_pinned()¶
For a published graph, indicates if the graph is pinned. A pinned graph will stay published even if no session is using it.
- Return type
bool
- property is_published: bool¶
Check if this graph is published with snapshots.
- is_published_with_snapshots()¶
Check if this graph is published with snapshots.
- Returns
True if this graph is published, false otherwise
- Return type
bool
- property pgx_instance: pypgx.api._server_instance.ServerInstance¶
Get the server instance.
- pick_random_vertex()¶
Select a random vertex from the graph.
- Returns
The PgxVertex object
- Return type
- pin()¶
For a published graph, pin the graph so that it stays published even if no sessions uses it. This call pins the graph lineage, which ensures that at least the latest available snapshot stays published when no session uses the graph.
- Return type
None
- prepare_pgql(pgql_query)¶
Prepare a PGQL query.
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
A prepared statement object
- Return type
- publish(vertex_properties=None, edge_properties=None)¶
Publish the graph so it can be shared between sessions.
This moves the graph name from the private into the public namespace.
- Parameters
vertex_properties (Optional[Union[List[pypgx.api._property.VertexProperty], bool]]) – List of vertex properties belonging to graph specified to be published as well
edge_properties (Optional[Union[List[pypgx.api._property.EdgeProperty], bool]]) – List of edge properties belonging to graph specified by graph to be published as well
- Return type
None
- publish_with_snapshots()¶
Publish the graph and all its snapshots so they can be shared between sessions.
- Return type
None
- query_pgql(query)¶
Submit a pattern matching select only query.
- Parameters
query (str) – Query string in PGQL
- Returns
PgqlResultSet with the result
- Return type
- remove_redaction_rule(redaction_rule_config, authorization_type, *names)¶
Remove a redaction rule for authorization_type names.
Possible authorization types are: [‘user’, ‘role’]
- Parameters
authorization_type (str) – the authorization type of the rule to be removed
names (str) – the names of the users or roles for which the rule should be removed
redaction_rule_config (pypgx.api.redaction._redaction_rule_config.PgxRedactionRuleConfig) –
- Return type
None
- rename(name)¶
Rename this graph.
- Parameters
name (str) – New name
- Return type
None
- revoke_permission(permission_entity)¶
Revoke all permissions on this graph from the given entity.
Possible PermissionEntity objects are: PgxUser and PgxRole.
- Parameters
permission_entity (pypgx.api.auth._permission_entity.PermissionEntity) – the entity for which all permissions will be revoked
- Return type
None
- simplify(vertex_properties=True, edge_properties=True, keep_multi_edges=False, keep_self_edges=False, keep_trivial_vertices=False, in_place=False, name=None)¶
Create a simplified version of a graph.
Note that the returned graph and properties are transient and therefore session bound. They can be explicitly destroyed and get automatically freed once the session dies.
- Parameters
vertex_properties (Union[bool, List[pypgx.api._property.VertexProperty]]) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (Union[bool, List[pypgx.api._property.EdgeProperty]]) – List of edge properties belonging to graph specified to be kept in the new graph
keep_multi_edges (bool) – Defines if multi-edges should be kept in the result
keep_self_edges (bool) – Defines if self-edges should be kept in the result
keep_trivial_vertices (bool) – Defines if isolated nodes should be kept in the result
in_place (bool) – If the operation should be done in place of if a new graph has to be created
name (Optional[str]) – New graph name. If None, a name will be generated. Only relevant if a new graph is to be created.
- Return type
- simplify_with_strategy(mutation_strategy)¶
Create a simplified version of a graph using a custom mutation strategy.
Note that the returned graph and properties are transient and therefore session bound. They can be explicitly destroyed and get automatically freed once the session dies.
- Parameters
mutation_strategy (pypgx.api._mutation_strategy.MutationStrategy) – Defines a custom strategy for dealing with multi-edges.
- Return type
- sort_by_degree(vertex_properties=True, edge_properties=True, ascending=True, in_degree=True, in_place=False, name=None)¶
Create a sorted version of a graph and all its properties.
The returned graph is sorted such that the node numbering is ordered by the degree of the nodes. Note that the returned graph and properties are transient.
- Parameters
vertex_properties (Union[List[pypgx.api._property.VertexProperty], bool]) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (Union[List[pypgx.api._property.EdgeProperty], bool]) – List of edge properties belonging to graph specified to be kept in the new graph
ascending (bool) – Sorting order
in_degree (bool) – If in_degree should be used for sorting. Otherwise use out degree.
in_place (bool) – If the sorting should be done in place or a new graph should be created
name (Optional[str]) – New graph name
- Return type
- sparsify(sparsification, vertex_properties=True, edge_properties=True, name=None)¶
Sparsify the given graph and returns a new graph with less edges.
- Parameters
sparsification (float) – The sparsification coefficient. Must be between 0.0 and 1.0..
vertex_properties (bool) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (bool) – List of edge properties belonging to graph specified to be kept in the new graph
name (Optional[str]) – Filtered graph name
- Return type
- store(format, path, num_partitions=None, vertex_properties=True, edge_properties=True, overwrite=False)¶
Store graph in a file.
- Parameters
format (str) – One of [‘pgb’, ‘edge_list’, ‘two_tables’, ‘adj_list’, ‘flat_file’, ‘graphml’, ‘pg’, ‘rdf’, ‘csv’]
path (str) – Path to which graph will be stored
num_partitions (Optional[int]) – The number of partitions that should be created, when exporting to multiple files
vertex_properties (bool) – The collection of vertex properties to store together with the graph data. If not specified all the vertex properties are stored
edge_properties (bool) – The collection of edge properties to store together with the graph data. If not specified all the vertex properties are stored
overwrite (bool) – Overwrite if existing
- Return type
- transpose(vertex_properties=True, edge_properties=True, edge_label_mapping=None, in_place=False, name=None)¶
Create a transpose of this graph.
A transpose of a directed graph is another directed graph on the same set of vertices with all of the edges reversed. If this graph contains an edge (u,v) then the return graph will contain an edge (v,u) and vice versa. If this graph is undirected (isDirected() returns false), this operation has no effect and will either return a copy or act as identity function depending on the mode parameter.
- Parameters
vertex_properties (bool) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (bool) – List of edge properties belonging to graph specified to be kept in the new graph
edge_label_mapping (Optional[Mapping[str, str]]) – Can be used to rename edge labels. For example, an edge (John,Mary) labeled “fatherOf” can be transformed to be labeled “hasFather” on the transpose graph’s edge (Mary,John) by passing in a dict like object {“fatherOf”:”hasFather”}.
in_place (bool) – If the transpose should be done in place or a new graph should be created
name (Optional[str]) – New graph name
- Return type
- undirect(vertex_properties=True, edge_properties=True, keep_multi_edges=True, keep_self_edges=True, keep_trivial_vertices=True, in_place=False, name=None)¶
Create an undirected version of the graph.
An undirected graph has some restrictions. Some algorithms are only supported on directed graphs or are not yet supported for undirected graphs. Further, PGX does not support storing undirected graphs nor reading from undirected formats. Since the edges do not have a direction anymore, the behavior of pgxEdge.source() or pgxEdge.destination() can be ambiguous. In order to provide deterministic results, PGX will always return the vertex with the smaller internal id as source and the other as destination vertex.
- Parameters
vertex_properties (Union[bool, List[pypgx.api._property.VertexProperty]]) – List of vertex properties belonging to graph specified to be kept in the new graph
edge_properties (Union[bool, List[pypgx.api._property.EdgeProperty]]) – List of edge properties belonging to graph specified to be kept in the new graph
keep_multi_edges (bool) – Defines if multi-edges should be kept in the result
keep_self_edges (bool) – Defines if self-edges should be kept in the result
keep_trivial_vertices (bool) – Defines if isolated nodes should be kept in the result
in_place (bool) – If the operation should be done in place of if a new graph has to be created
name (Optional[str]) – New graph name
- Return type
- undirect_with_strategy(mutation_strategy)¶
Create an undirected version of the graph using a custom mutation strategy.
An undirected graph has some restrictions. Some algorithms are only supported on directed graphs or are not yet supported for undirected graphs. Further, PGX does not support storing undirected graphs nor reading from undirected formats. Since the edges do not have a direction anymore, the behavior of pgxEdge.source() or pgxEdge.destination() can be ambiguous. In order to provide deterministic results, PGX will always return the vertex with the smaller internal id as source and the other as destination vertex.
- Parameters
mutation_strategy (pypgx.api._mutation_strategy.MutationStrategy) – Defines a custom strategy for dealing with multi-edges.
- Return type
- unpin()¶
For a published graph, unpin the graph so that if no snapshot of the graph is used by any session or pinned, the graph and all its snapshots can be removed.
- Return type
None
- class pypgx.api.PgxMap(graph, java_map)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A map is a collection of key-value pairs.
- Parameters
graph (Optional[PgxGraph]) –
- Return type
None
- contains_key(key)¶
Return True if this map contains the given key.
- Parameters
key – Key of the entry
- Return type
bool
- destroy()¶
Destroy this map.
- Return type
None
- entries()¶
Return an entry set.
- Return type
dict
- get(key)¶
Get the entry with the specified key.
- Parameters
key – Key of the entry
- Returns
Value
- Return type
Any
- keys()¶
Return a key set.
- Return type
list
- put(key, value)¶
Set the value for a key in the map specified by the given name.
- Parameters
key – Key of the entry
value – New value
- Return type
None
- remove(key)¶
Remove the entry specified by the given key from the map with the given name.
Returns true if the map did contain an entry with the given key, false otherwise.
- Parameters
key – Key of the entry
- Returns
True if the map contained the key
- Return type
bool
- property size: int¶
Map size.
- class pypgx.api.PgxPartition(graph, java_partition, property)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A vertex partition of a graph. Each partition is a set of vertices.
- Return type
None
- destroy()¶
Destroy the partition object.
- Return type
None
- get_components_property()¶
Return the property that contains for each vertex, its associated component ID.
- Return type
- get_partition_by_index(idx)¶
Get a partition by index.
- Parameters
idx (int) – The index. Must be between 0 and size() - 1.
- Returns
The set of vertices representing the partition
- Return type
- get_partition_by_vertex(v)¶
Get the partition a particular vertex belongs to.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The vertex
- Returns
The set of vertices representing the partition the given vertex belongs to
- Return type
- get_partition_index_of_vertex(v)¶
Get a partition by index.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The index. Must be between 0 and size() - 1.
- Returns
The set of vertices representing the partition
- Return type
Any
- class pypgx.api.PgxPath(graph, java_path)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A path from a source to a destination vertex in a
PgxGraph
.- Parameters
graph (PgxGraph) –
- Return type
None
- destroy()¶
Destroy this path.
- Return type
None
- property edges: List[pypgx.api._pgx_entity.PgxEdge]¶
Return a list of edges in the path.
- property path: List[Tuple[pypgx.api._pgx_entity.PgxVertex, Optional[pypgx.api._pgx_entity.PgxEdge]]]¶
Return path as a list of (vertex,edge) tuples.
- property vertices: List[pypgx.api._pgx_entity.PgxVertex]¶
Return a list of vertices in the path.
- class pypgx.api.PgxSession(java_session)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A PGX session represents an active user connected to a ServerInstance.
Every session gets a workspace assigned on the server, which can be used to read graph data, create transient data or custom algorithms for the sake of graph analysis. Once a session gets destroyed, all data in the session workspace is freed.
- Variables
LATEST_SNAPSHOT – The timestamp of the most recent snapshot, used to easily move to the newest snapshot (see
set_snapshot()
)- Return type
None
- close()¶
Close this session object.
- Return type
None
- compile_program(path, overwrite=False)¶
Compile a Green-Marl program for parallel execution with all optimizations enabled.
- Parameters
path (str) – Path to program
overwrite (bool) – If the procedure in the given code already exists, overwrite if true, throw an exception otherwise
- Return type
- compile_program_code(code, overwrite=False)¶
Compile a Green-Marl program (if it is supported by the corresponding PyPGX distribution). Otherwise compile a Java program.
- Parameters
code (str) – The Green-Marl/Java code to compile
overwrite (bool) – If the procedure in the given code already exists, overwrite if true, throw an exception otherwise
- Return type
- create_analyst()¶
Create and return a new analyst.
- Returns
An analyst object
- Return type
- create_frame(schema, column_data, frame_name)¶
Create a frame with the specified data
- Parameters
schema (List[Tuple[str, str]]) – List of tuples (columnName, columnType)
column_data (Dict[str, List]) – Map of iterables, columnName -> columnData
frame_name (str) – Name of the frame
- Returns
A frame builder initialized with the given schema
- Return type
- create_frame_builder(schema)¶
Create a frame builder initialized with the given schema
- Parameters
schema (List[Tuple[str, str]]) – List of tuples (columnName, columnType)
- Returns
A frame builder initialized with the given schema
- Return type
- create_graph_builder(id_type='integer', vertex_id_generation_strategy='user_ids', edge_id_generation_strategy='auto_generated')¶
Create a graph builder with the given vertex ID type and Ids Mode.
- Parameters
id_type (str) – The type of the vertex ID
vertex_id_generation_strategy (str) – The vertices Id generation strategy to be used
edge_id_generation_strategy (str) – The edges Id generation strategy to be used
- Return type
- create_map(key_type, value_type, name=None)¶
Create a map.
Possible types are: [‘integer’,’long’,’double’,’boolean’,’string’,’vertex’,’edge’, ‘local_date’,’time’,’timestamp’,’time_with_timezone’,’timestamp_with_timezone’]
- Parameters
key_type (str) – Property type of the keys that are going to be stored inside the map
value_type (str) – Property type of the values that are going to be stored inside the map
name (Optional[str]) – Map name
- Returns
A named PgxMap of key content type key_type and value content type value_type
- Return type
- create_sequence(content_type, name=None)¶
Create a sequence of scalars.
Possible types are: [‘integer’,’long’,’double’,’boolean’,’string’,’vertex’,’edge’, ‘local_date’,’time’,’timestamp’,’time_with_timezone’,’timestamp_with_timezone’]
- Parameters
content_type (str) – Property type of the elements in the sequence
name (Optional[str]) – Sequence name
- Returns
A named ScalarSequence of content type content_type
- Return type
- create_set(content_type, name=None)¶
Create a set of scalars.
Possible types are: [‘integer’,’long’,’double’,’boolean’,’string’,’vertex’,’edge’, ‘local_date’,’time’,’timestamp’,’time_with_timezone’,’timestamp_with_timezone’]
- Parameters
content_type (str) – content type of the set
name (Optional[str]) – the set’s name
- Returns
A named ScalarSet of content type content_type
- Return type
- describe_graph_file(file_path)¶
Describe the graph contained in the file at the given path.
- Parameters
file_path (str) – Graph file path
- Returns
The configuration which can be used to load the graph
- Return type
- describe_graph_files(files_path)¶
Describe the graph contained in the files at the given paths.
- Parameters
files_path (str) – Paths to the files
- Returns
The configuration which can be used to load the graph
- destroy()¶
Destroy this session object.
- Return type
None
- edge_provider_from_frame(provider_name, source_provider, destination_provider, frame, source_vertex_column='src', destination_vertex_column='dst')¶
Create an edge provider from a PgxFrame to later build a PgxGraph
- Parameters
provider_name (str) – edge provider name
source_provider (str) – vertex source provider name
destination_provider (str) – vertex destination provider name
frame (pypgx.api.frames._pgx_frame.PgxFrame) – PgxFrame to use
source_vertex_column (str) – column to use as source keys. Defaults to “src”
destination_vertex_column (str) – column to use as destination keys. Defaults to “dst”
- Returns
the EdgeFrameDeclaration object
- Return type
pypgx.api.frames._edge_frame_declaration.EdgeFrameDeclaration
- execute_pgql(pgql_query)¶
Submit any query with a ON-clause.
The ON-clause indicates the graph on which the query will be executed. The graph name in the ON-clause is evaluated with the same semantics as PgxSession.getGraphAsync(String).
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
The query result set
- Return type
Optional[pypgx.api._pgql_result_set.PgqlResultSet]
throws InterruptedException if the caller thread gets interrupted while waiting for completion. throws ExecutionException if any exception occurred during asynchronous execution. The actual exception will be nested.
- explain_pgql(pgql_query)¶
Explain the execution plan of a pattern matching query.
Note: Different PGX versions may return different execution plans.
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
The query plan
- Return type
pypgx.api._operation.Operation
- get_available_compiled_program_ids()¶
Get the set of available compiled program IDs.
- Return type
Set[str]
- get_available_snapshots(snapshot)¶
Return a list of all available snapshots of the given input graph.
- Parameters
snapshot (pypgx.api._pgx_graph.PgxGraph) – A ‘PgxGraph’ object for which the available snapshots shall be retrieved
- Returns
A list of ‘GraphMetaData’ objects, each corresponding to a snapshot of the input graph
- Return type
- get_compiled_program(id)¶
Get a compiled program by ID.
- Parameters
id (str) – The id of the compiled program
- Return type
- get_graph(name, namespace=None)¶
Find and return a graph with name name within the given namespace loaded inside PGX.
The search for the snapshot to return is done according to the following rules:
if namespace is private, than the search occurs on already referenced snapshots of the graph with name name and the most recent snapshot is returned
if namespace is public, then the search occurs on published graphs and the most recent snapshot of the published graph with name name is returned
if namespace is None, then the private namespace is searched first and, if no snapshot is found, the public namespace is then searched
Multiple calls of this method with the same parameters will return different
PgxGraph
objects referencing the same graph, with the server keeping track of how many references a session has to each graph.Therefore, a graph is released within the server either if:
all the references are moved to another graph (e.g. via
set_snapshot()
)the
PgxGraph.destroy()
method is called on one reference. Note that this invalidates all references
- get_graphs(namespace=None)¶
Return a collection of graph names accessible under the given namespace.
- Parameters
namespace (Optional[pypgx.api._namespace.Namespace]) – The namespace where to look up the graphs
- Return type
List[str]
- get_idle_timeout()¶
Get the idle timeout of this session
- Returns
the idle timeout in seconds
- Return type
int
- get_name()¶
Get the identifier of the current session.
- Returns
identifier of this session
- Return type
str
- get_pgql_result_set(id)¶
Get a PGQL result set by ID.
- Parameters
id (str) – The PGQL result set ID
- Returns
The requested PGQL result set or None if no such result set exists for this session
- Return type
Optional[pypgx.api._pgql_result_set.PgqlResultSet]
- get_session_context()¶
Get the context describing the current session.
- Returns
context of this session
- Return type
pypgx.api._session_context.SessionContext
- get_source()¶
Get the current session source
- Returns
session source
- Return type
str
- get_task_timeout()¶
Get the task timeout of this session
- Returns
the task timeout in seconds
- Return type
int
- graph_from_frames(graph_name, vertex_providers, edge_providers, partitioned=True)¶
Create PgxGraph from vertex providers and edge providers.
partitioned must be set to True if multiple vertex or edge providers are given
- Parameters
graph_name (str) – graph name
vertex_providers (List[pypgx.api.frames._vertex_frame_declaration.VertexFrameDeclaration]) – list of vertex providers
edge_providers (List[pypgx.api.frames._edge_frame_declaration.EdgeFrameDeclaration]) – list of edge providers
partitioned (bool) – whether the graph is partitioned or not. Defaults to True
- Returns
the PgxGraph object
- Return type
- pandas_to_pgx_frame(pandas_dataframe, frame_name)¶
Create a frame from a pandas dataframe.
Duplicate columns will be renamed. Mixed column types are not supported.
This method requires pandas.
- Parameters
pandas_dataframe – The Pandas dataframe to use
frame_name (str) – Name of the frame
- Returns
the frame created
- Return type
- prepare_pgql(pgql_query)¶
Prepare a pattern matching query with a ON-clause.
The ON-clause indicates the graph on which the query will be executed. The graph name in the ON-clause is evaluated with the same semantics as getGraph(String).
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
A prepared statement object
- Return type
- query_pgql(pgql_query)¶
Submit a pattern matching query with a ON-clause.
The ON-clause indicates the graph on which the query will be executed. The graph name in the ON-clause is evaluated with the same semantics as PgxSession.getGraph(String).
- Parameters
pgql_query (str) – Query string in PGQL
- Returns
The query result set
- Return type
Optional[pypgx.api._pgql_result_set.PgqlResultSet]
throws InterruptedException if the caller thread gets interrupted while waiting for completion. throws ExecutionException if any exception occurred during asynchronous execution. The actual exception will be nested.
- read_frame()¶
Create a new frame reader with which it is possible to parameterize the loading of the row frame.
- Returns
A frame reader object with which it is possible to parameterize the loading
- Return type
- read_graph_as_of(config, meta_data=None, creation_timestamp=None, new_graph_name=None)¶
Read a graph and its properties of a specific version (metaData or creationTimestamp) into memory.
The creationTimestamp must be a valid version of the graph.
- Parameters
config (pypgx.api._graph_config.GraphConfig) – The graph config
meta_data (Optional[pypgx.api._graph_meta_data.GraphMetaData]) – The metaData object returned by get_available_snapshots(GraphConfig) identifying the version
creation_timestamp (Optional[int]) – The creation timestamp (milliseconds since jan 1st 1970) identifying the version to be checked out
new_graph_name (Optional[str]) – How the graph should be named. If None, a name will be generated.
- Returns
The PgxGraph object
- Return type
- read_graph_by_name(graph_name, graph_source)¶
- Parameters
graph_name (str) – Name of graph
graph_source (str) – Source of graph
- Return type
- read_graph_file(file_path, file_format=None, graph_name=None)¶
- Parameters
file_path (str) – File path
file_format (Optional[str]) – File format of graph
graph_name (Optional[str]) – Name of graph
- Return type
- read_graph_files(file_paths, edge_file_paths=None, file_format=None, graph_name=None)¶
Load the graph contained in the files at the given paths.
- Parameters
file_paths (Union[str, Iterable[str]]) – Paths to the vertex files
edge_file_paths (Optional[Union[str, Iterable[str]]]) – Path to the edge file
file_format (Optional[str]) – File format
graph_name (Optional[str]) – Loaded graph name
- Return type
- read_graph_with_properties(config, max_age=9223372036854775807, max_age_time_unit='days', block_if_full=False, update_if_not_fresh=True, graph_name=None)¶
Read a graph and its properties, specified in the graph config, into memory.
- Parameters
config (Union[str, pathlib.PurePath, Dict[str, Any], pypgx.api._graph_config.GraphConfig]) – The graph config
max_age (int) – If another snapshot of the given graph already exists, the age of the latest existing snapshot will be compared to the given maxAge. If the latest snapshot is in the given range, it will be returned, otherwise a new snapshot will be created.
max_age_time_unit (str) – The time unit of the maxAge parameter
block_if_full (bool) – If true and a new snapshot needs to be created but no more snapshots are allowed by the server configuration, the returned future will not complete until space becomes available. Iterable full and this flag is false, the returned future will complete exceptionally instead.
update_if_not_fresh (bool) – If a newer data version exists in the backing data source (see PgxGraph.is_fresh()), this flag tells whether to read it and create another snapshot inside PGX. If the “snapshots_source” field of config is SnapshotsSource.REFRESH, the returned graph may have multiple snapshots, depending on whether previous reads with the same config occurred; otherwise, if the “snapshots_source” field is SnapshotsSource.CHANGE_SET, only the most recent snapshot (either pre-existing or freshly read) will be visible.
graph_name (Optional[str]) – How the graph should be named. If null, a name will be generated. If a graph with that name already exists, the returned future will complete exceptionally.
- Return type
- read_subgraph_from_pg_view(view, queries=None, config=None)¶
Load a graph from PG Views.
- Parameters
view (str) – The name of the PG View.
queries (Union[None, str, pypgx.api._graph_offloading.PreparedPgqlQuery, List[Union[str, pypgx.api._graph_offloading.PreparedPgqlQuery]]]) – A query or queries used to specify which data is to be loaded.
config (Optional[pypgx.api._graph_config.GraphConfig]) – An optional config used to describe how data should be loaded.
- Returns
The graph.
- Return type
- register_keystore(keystore_path, keystore_password)¶
Register a keystore.
- Parameters
keystore_path (str) – The path to the keystore which shall be registered
keystore_password (str) – The password of the provided keystore
- Return type
None
- property server_instance: pypgx.api._server_instance.ServerInstance¶
Get the server instance.
- Returns
The server instance
- set_snapshot(graph, meta_data=None, creation_timestamp=None, force_delete_properties=False)¶
Set a graph to a specific snapshot.
You can use this method to jump back and forth in time between various snapshots of the same graph. If successful, the given graph will point to the requested snapshot after the returned future completes.
- Parameters
graph (Union[str, pypgx.api._pgx_graph.PgxGraph]) – Input graph
meta_data (Optional[pypgx.api._graph_meta_data.GraphMetaData]) – A GraphMetaData object used to identify the snapshot
creation_timestamp (Optional[int]) – The metaData object returned by (GraphConfig) identifying the version to be checked out
force_delete_properties (bool) – Graphs with transient properties cannot be checked out to a different version. If this flag is set to true, the checked out graph will no longer contain any transient properties. If false, the returned future will complete exceptionally with an UnsupportedOperationException as its cause.
- Return type
None
- vertex_provider_from_frame(provider_name, frame, vertex_key_column='id')¶
Create a vertex provider from a PgxFrame to later build a PgxGraph
- Parameters
provider_name (str) – vertex provider name
frame (pypgx.api.frames._pgx_frame.PgxFrame) – PgxFrame to use
vertex_key_column (str) – column to use as keys. Defaults to “id”
- Returns
the VertexFrameDeclaration object
- Return type
pypgx.api.frames._vertex_frame_declaration.VertexFrameDeclaration
- class pypgx.api.PgxVertex(graph, java_vertex)¶
Bases:
pypgx.api._pgx_entity.PgxEntity
A vertex of a
PgxGraph
.- Parameters
graph (PgxGraph) –
- Return type
None
- get_neighbors(direction, remove_duplicates=False)¶
Return all neighbors of this vertex: all vertices with an edge to or from this vertex.
- Parameters
direction (str) – One of (“outgoing”,”incoming”,”both”)
remove_duplicates (bool) – If removeDuplicates is set to true, the resulting collection does not contain any duplicates. Otherwise, if this vertex is connected ‘N’ times to a vertex ‘X’, vertex ‘X’ also appears ‘N’ times in the results. This method does not guarantee any ordering in the result. This method never returns null.
- Return type
- property in_edges: List[pypgx.api._pgx_entity.PgxEdge]¶
Return a list of ingoing edges.
- property in_neighbors: List[pypgx.api._pgx_entity.PgxVertex]¶
Return all incoming neighbors of this vertex: all vertices with an edge to this vertex.
If the graph is a multi-graph and if a vertex ‘A’ has multiple edges to this vertex, then ‘A’ will appear multiple times in the result, i.e. once per edge from ‘A’ to this vertex. This method does not guarantee any ordering in the result.
- property labels: List[str]¶
Get the vertex labels.
- property out_edges: List[pypgx.api._pgx_entity.PgxEdge]¶
Return a list of outgoing edges.
- property out_neighbors: List[pypgx.api._pgx_entity.PgxVertex]¶
Return all outgoing neighbors of this vertex, i.e., all nodes this vertex has an edge to.
If the graph is a multi-graph and if the vertex has multiple edges to a vertex ‘A’, then ‘A’ will appear multiple times in the result, i.e., once per edge to ‘A’. This method does not guarantee any ordering in the result. This method never returns null.
- class pypgx.api.PickingStrategyBuilder(java_mutation_strategy_builder)¶
Bases:
pypgx.api._mutation_strategy_builder.MutationStrategyBuilder
A class for defining a picking strategy on a graph.
- Return type
None
- set_pick_by_edge_id(picking_function)¶
If there are multiple edges between two vertices, the edge that satisfies the picking_function will be picked.
- Parameters
picking_function (str) – available functions are: “min” and “max”
- Returns
the PickingStrategyBuilder itself
- Return type
- set_pick_by_label(picking_function)¶
If there are multiple edges between two vertices, the edge whose label satisfies the picking_function will be picked.
- Parameters
picking_function (str) – available functions are: “min” and “max”
- Returns
the PickingStrategyBuilder itself
- Return type
- set_pick_by_property(prop, picking_function)¶
If there are multiple edges between two vertices, the edge that satisfies the picking_function will be picked.
For instance, pick the edge where property_1 is MAX. Note, if two or more properties could be chosen according to the picking_function, only one of them is picked.
- Parameters
prop (Union[str, pypgx.api._pgx_id.PgxId, pypgx.api._property.EdgeProperty]) – a property name, PgxId, or EdgeProperty
picking_function (str) – available functions are: “min” and “max”
- Returns
the PickingStrategyBuilder itself
- Return type
- class pypgx.api.PreparedPgqlQuery(query, arguments=None)¶
Bases:
object
Configuration for a prepared PGQL query, together with its arguments. This holds a string-representation for a prepared PGQL statement, together with all of its arguments.
- Parameters
query (str) –
arguments (List[pypgx.api._graph_offloading.PreparedPgqlQueryArgument]) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryBooleanArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A boolean argument for a prepared PGQL query.
- Parameters
value (bool) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryDateArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A date argument for a prepared PGQL query.
- Parameters
value (datetime.date) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryDoubleArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A double argument for a prepared PGQL query.
- Parameters
value (float) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryFloatArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A float argument for a prepared PGQL query.
- Parameters
value (float) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryIntegerArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
An integer argument for a prepared PGQL query.
- Parameters
value (int) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryLongArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A long argument for a prepared PGQL query.
- Parameters
value (int) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryStringArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A string argument for a prepared PGQL query.
- Parameters
value (str) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryTimeArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A time argument for a prepared PGQL query.
- Parameters
value (datetime.time) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryTimeWithTimezoneArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A time (with timezone) argument for a prepared PGQL query.
- Parameters
value (datetime.time) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryTimestampArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A timestamp (date and time) argument for a prepared PGQL query.
- Parameters
value (datetime.datetime) –
- Return type
None
- class pypgx.api.PreparedPgqlQueryTimestampWithTimezoneArgument(value)¶
Bases:
pypgx.api._graph_offloading.PreparedPgqlQueryArgument
A timestamp (date and time, with timezone) argument for a prepared PGQL query.
- Parameters
value (datetime.datetime) –
- Return type
None
- class pypgx.api.PreparedStatement(java_prepared_statement)¶
Bases:
object
An object that represents a precompiled PGQL statement.
A PGQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.
- Return type
None
- close()¶
Release this Statement’s resources. Calling the method close on a Statement object that is already closed has no effect.
Note: When a Statement is closed, its associated ResultSet objects are also closed.
- Return type
None
- execute()¶
Execute the PGQL statement in this PreparedStatement object, which may be any kind of PGQL statement.
- Returns
A boolean to indicate the form of the first result: true in case of a SELECT query, false otherwise. In case of a SELECT query you must call the method getResultSet to retrieve the result.
- Return type
bool
Throws: PgqlException - if a server-side error occurs or this method is called on a closed Statement
- execute_async()¶
Execute the PGQL statement in this PreparedStatement object, which may be any kind of PGQL statement.
- Returns
A boolean to indicate the form of the first result: true in case of a SELECT query, false otherwise
- Return type
bool
In case of a SELECT query you must call the method getResultSet to retrieve the result.
Throws: PgqlException - if a server-side error occurs or this method is called on a closed Statement
- execute_query()¶
Blocking version of execute_query_async().
Calls execute_query_async() and waits for the returned results to complete.
Throws PgqlException if the caller thread gets interrupted while waiting for completion or if any exception occurred during asynchronous execution. The actual exception will be nested.
- Return type
- execute_query_async()¶
Execute the PGQL query in this PgxPreparedStatement object and returns the PgqlResultSet object generated by the query.
- Returns
A PgqlResultSet object that contains the data produced by the query; never null
- Return type
- get_result_set()¶
Retrieve the current result as a PgqlResultSet object.
This method should be called only once per result.
- Returns
Current result as a ResultSet object or null if the query is not a SELECT query
- Return type
Throws: PgqlException - if a server-side error occurs or this method is called on a closed Statement
- get_result_set_async()¶
Retrieve the current result as a PgqlResultSet object.
This method should be called only once per result.
- Returns
Current result as a ResultSet object or null if the query is not a SELECT query
- Return type
Throws: PgqlException - if a server-side error occurs or this method is called on a closed Statement
- set_array(parameter_index, x)¶
Set the designated parameter to the given array value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (Sequence) – The parameter value
- Return type
None
- set_boolean(parameter_index, x)¶
Set the designated parameter to the given boolean value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (bool) – The parameter value
- Return type
None
- set_date(parameter_index, x)¶
Set the designated parameter to the given date value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (datetime.date) – The parameter value
- Return type
None
- set_double(parameter_index, x)¶
Set the designated parameter to the given double value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (float) – The parameter value
- Return type
None
- set_int(parameter_index, x)¶
Set the designated parameter to the given int value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (int) – The parameter value
- Return type
None
- set_long(parameter_index, x)¶
Set the designated parameter to the given long value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (int) – The parameter value
- Return type
None
- set_string(parameter_index, x)¶
Set the designated parameter to the given string value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (str) – The parameter value
- Return type
None
- set_time(parameter_index, x)¶
Set the designated parameter to the given time value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (datetime.time) – The parameter value
- Return type
None
- set_time_with_timezone(parameter_index, x)¶
Set the designated parameter to the given time with timezone value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (datetime.time) – The parameter value
- Return type
None
- set_timestamp(parameter_index, x)¶
Set the designated parameter to the given timestamp value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (datetime.datetime) – The parameter value
- Return type
None
- set_timestamp_with_timezone(parameter_index, x)¶
Set the designated parameter to the given timestamp with timezone value.
- Parameters
parameter_index (int) – The first parameter is 1, the second is 2, …
x (datetime.datetime) – The parameter value
- Return type
None
- class pypgx.api.Scalar(graph, java_scalar)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
A scalar value.
- Parameters
graph (PgxGraph) –
- Return type
None
- destroy()¶
Free resources on the server taken up by this Scalar.
- Return type
None
- get()¶
Get scalar value.
- Return type
Any
- get_dimension()¶
Get the scalar’s dimension.
- Return type
int
- set(value)¶
Set the scalar value.
- Parameters
value – Value to be assigned
- Return type
None
- class pypgx.api.ScalarCollection(java_scalar_collection)¶
Bases:
pypgx.api._pgx_collection.PgxCollection
A collection of scalars.
- Return type
None
- add(items)¶
Add one or multiple elements to the collection.
- Parameters
items – An element of the predefined type. Can also be an iterable of the same type.
- Return type
None
- contains(element)¶
Check whether the element is in the collection.
- Return type
bool
- remove(items)¶
Remove one or multiple elements from the collection.
- Parameters
items – An element of the predefined type. Can also be an iterable of the same type.
- Return type
None
- class pypgx.api.ScalarSequence(java_scalar_collection)¶
Bases:
pypgx.api._pgx_collection.ScalarCollection
An ordered sequence of scalars which may contain duplicates.
- Return type
None
- class pypgx.api.ScalarSet(java_scalar_collection)¶
Bases:
pypgx.api._pgx_collection.ScalarCollection
An unordered set of scalars that does not contain duplicates.
- Return type
None
- class pypgx.api.ServerInstance(java_server_instance)¶
Bases:
object
A PGX server instance.
- Return type
None
- create_session(source, idle_timeout=None, task_timeout=None, time_unit='milliseconds')¶
- Parameters
source (str) – A descriptive string identifying the client
idle_timeout (Optional[int]) – If not null, tries to overwrite server default idle timeout
task_timeout (Optional[int]) – If not null, tries to overwrite server default task timeout
time_unit (str) – Time unit of idleTimeout and taskTimeout (‘days’, ‘hours’, ‘microseconds’, ‘milliseconds’, ‘minutes’, ‘nanoseconds’, ‘seconds’)
- Returns
PgxSession
- Return type
- free_cached_memory()¶
Free cached PGX memory and return the freed memory in MB. This may be done after closing a graph in order to free up resources. Note that memory might not be freed immediately on the system.
- Return type
int
- get_pgx_config()¶
Get the PGX config.
- Returns
Dict containing current config
- Return type
Dict[str, Any]
- get_pgx_user_roles()¶
Get PGX user roles
- Return type
Set[str]
- get_pgx_username()¶
Get PGX username
- Return type
str
- get_server_state()¶
Return the server state.
- Returns
Server state as a dict
- Return type
Dict[str, Any]
- get_session(session_id)¶
Get a session by ID.
- Parameters
session_id (str) – Id of the session
- Returns
PgxSession
- Return type
- get_version()¶
Get the PGX extended version of this instance.
- Returns
VersionInfo object
- Return type
- is_engine_ready()¶
Boolean of whether or not the engine is ready to accept new requests
- Return type
bool
- is_engine_running()¶
Boolean of whether or not the engine is running
- Return type
bool
- is_graph_preloading_done()¶
Boolean of whether or not the preloading of the graphs has completed
- Return type
bool
- kill_session(session_id)¶
Kill a session.
- Parameters
session_id (str) – Session id
- Return type
None
- set_session_max_memory_size(session, size, unit)¶
Set the maximum memory limit for the given session.
- Parameters
session (PgxSession) – on which session to apply the memory limit
size (int) – memory limit to be set relative to the provided memory_unit
unit (str) – the memory_unit to use for the given size
- Return type
None
Only supports megabyte, gigabyte, terabyte Requires SERVER_MANAGE permission
- set_token(token)¶
Set the current auth token for this ServerInstance. Note depending on the RealmClient implementation used, this might not be supported or have no effect.
- Parameters
token (str) – the new auth token
- Return type
None
- shutdown_engine()¶
Force the engine to stop and clean up resources
- Return type
None
- shutdown_engine_now()¶
Force the engine to stop and clean up resources. Currently running tasks are interrupted. New incoming requests get rejected. Throws an exception when current tasks didn’t finish after a short grace period.
- Return type
None
- start_engine(config=None)¶
Start the PGX engine.
- Parameters
config (Optional[Union[str, Mapping[str, Any]]]) – path to json file or dict-like containing the PGX config
- Return type
None
- unpin_graph(graph_name)¶
Unpin the specified published graph so that if no session uses any of its snapshot, it can be removed.
- Parameters
graph_name (str) – name of the published graph to unpin
- Return type
None
- update_pgx_config(config)¶
Replace the current PGX config with the given configuration.
This only affects static permissions (i.e. non-graph) and redaction rules for pre-loaded graphs. Existing permissions on graphs and frames will not be changed.
- Parameters
config (Union[str, Mapping[str, Any]]) – path to json file or dict-like PGX config containing the new authorization config
- Return type
None
- class pypgx.api.Synchronizer(java_synchronizer)¶
Bases:
object
A class for synchronizing changes in an external data source with a PGX graph.
- Return type
None
- apply()¶
Apply the changes to the underlying PGX graph.
- fetch()¶
Fetch the changes from the external data source.
You can call this multiple times to accumulate deltas. The deltas reset once you call apply().
- get_graph_delta()¶
Get the description of the delta between current snapshot and the fetched changes.
Can be used to make a decision for when to apply the delta.
- class pypgx.api.VertexBuilder(session, java_vertex_builder, id_type)¶
Bases:
pypgx.api._graph_builder.GraphBuilder
A vertex builder for defining vertices added with the
GraphBuilder
.- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- add_label(label)¶
Add the given label to this vertex.
- Parameters
label (str) – The label to be added.
- Returns
The VertexProperty object
- Return type
- property id: Union[str, int]¶
Get the id of the element (vertex or edge) this builder belongs to.
- is_ignored()¶
Whether this vertex builder ignores method calls (True) or if it performs calls as usual (False. Some issues, such as incompatible changes in a ChangeSet, can be configured to be ignored. In that case, additional method calls on the returned vertex builder object will be ignored.
- Return type
bool
- set_property(key, value)¶
Set the property value of this vertex with the given key to the given value.
The first time this method is called, the type of value defines the type of the property.
- Parameters
key (str) – The property key
value (Any) – The value of the vertex property
- Returns
The VertexProperty object
- Return type
- class pypgx.api.VertexCollection(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.PgxCollection
A collection of vertices.
- Parameters
graph (PgxGraph) –
- Return type
None
- add(v)¶
Add one or multiple vertices to the collection.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, int, str, Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]]) – Vertex or vertex id. Can also be an iterable of vertices/Vetrices ids
- Return type
None
- add_all(vertices)¶
Add multiple vertices to the collection.
- Parameters
vertices (Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]) – Iterable of vertices/Vertices ids
- Return type
None
- contains(v)¶
Check if the collection contains vertex v.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – PgxVertex object or id
- Return type
bool
- remove(v)¶
Remove one or multiple vertices from the collection.
- Parameters
v (Union[pypgx.api._pgx_entity.PgxVertex, int, str, Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]]) – Vertex or vertex id. Can also be an iterable of vertices/Vetrices ids.
- Return type
None
- remove_all(vertices)¶
Remove multiple vertices from the collection.
- Parameters
vertices (Iterable[Union[pypgx.api._pgx_entity.PgxVertex, int, str]]) – Iterable of vertices/Vetrices ids
- class pypgx.api.VertexModifier(session, java_vertex_modifier, id_type='integer')¶
Bases:
pypgx.api._graph_change_set.GraphChangeSet
,pypgx.api._graph_builder.VertexBuilder
A class to modify existing vertices of a graph.
- Parameters
session (PgxSession) –
id_type (str) –
- Return type
None
- add_label(label)¶
Add the given label to this vertex.
- Parameters
label (str) – The label to add.
- Returns
self
- Return type
- get_id()¶
Get the id of the element (vertex or edge) this builder belongs to.
- Returns
The id of this builder.
- Return type
int
- remove_label(label)¶
Remove the given label from the vertex.
- Parameters
label (str) – The label to remove.
- Returns
self
- Return type
- set_property(key, value)¶
Set the property value of this vertex with the given key to the given value.
- Parameters
key (str) – A string with the name of the property to set.
value (Any) – The value to which this property shall be set.
- Returns
self
- Return type
- class pypgx.api.VertexSequence(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.VertexCollection
An ordered sequence of vertices which may contain duplicates.
- Parameters
graph (PgxGraph) –
- Return type
None
- class pypgx.api.VertexSet(graph, java_collection)¶
Bases:
pypgx.api._pgx_collection.VertexCollection
An unordered set of vertices (no duplicates).
- Parameters
graph (PgxGraph) –
- Return type
None
- class pypgx.api.VertexProperty(graph, java_prop)¶
Bases:
pypgx.api._property.PgxProperty
A vertex property of a
PgxGraph
.- Parameters
graph (PgxGraph) –
- Return type
None
- clone(name=None)¶
Create a copy of this property.
- Parameters
name (Optional[str]) – name of copy to be created. If None, guaranteed unique name will be generated.
- Returns
property result
- Return type
this class
- close()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- destroy()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- expand()¶
If this is a vector property, expands this property into a list of scalar properties of same type.
The first property will contain the first element of the vector, the second property the second element and so on.
- Return type
Union[pypgx.api._property.PgxProperty, List[pypgx.api._property.PgxProperty]]
- fill(value)¶
Fill this property with a given value.
- Parameters
value (Any) – The value
- Return type
None
- get(key)¶
Get a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The vertex (or vertex ID) whose property to get
- Return type
Any
- get_bottom_k_values(k)¶
Get the bottom k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- get_property_id()¶
Get an internal identifier for this property.
Only meant for internal usage.
- Returns
the internal identifier of this property
- Return type
- get_top_k_values(k)¶
Get the top k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Returns
list of k key-value tuples where the keys vertices/edges and the values are property values, sorted in ascending order
- Return type
- get_values()¶
Get the values of this property as a list.
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- property is_published: bool¶
Check if this property is published.
- Returns
True if this property is published, False otherwise.
- Return type
bool
- is_vector_property()¶
Return True if it is a vector property, False otherwise
- Return type
bool
- publish()¶
Publish the property into a shared graph so it can be shared between sessions.
- Returns
None
- Return type
None
- rename(name)¶
Rename this property.
- Parameters
name (str) – New name
- Returns
None
- Return type
None
- set(key, value)¶
Set a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The key (vertex/edge) whose property to set
value (Any) – The property value
- Return type
None
- set_values(values)¶
Set the labels values.
- Parameters
values (PgxMap) – pgxmap with ids and values
- Return type
None
- wrap(property_value, property_type)¶
Take a property value and wraps it pgx entities if applicable
- Parameters
property_value (Any) – property value
property_type (str) – A valid property type.
- Return type
Any
- class pypgx.api.EdgeProperty(graph, java_prop)¶
Bases:
pypgx.api._property.PgxProperty
An edge property of a
PgxGraph
.- Parameters
graph (PgxGraph) –
- Return type
None
- clone(name=None)¶
Create a copy of this property.
- Parameters
name (Optional[str]) – name of copy to be created. If None, guaranteed unique name will be generated.
- Returns
property result
- Return type
this class
- close()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- destroy()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- expand()¶
If this is a vector property, expands this property into a list of scalar properties of same type.
The first property will contain the first element of the vector, the second property the second element and so on.
- Return type
Union[pypgx.api._property.PgxProperty, List[pypgx.api._property.PgxProperty]]
- fill(value)¶
Fill this property with a given value.
- Parameters
value (Any) – The value
- Return type
None
- get(key)¶
Get a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxEdge, int]) – The edge (or edge ID) whose property to get
- Return type
Any
- get_bottom_k_values(k)¶
Get the bottom k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- get_property_id()¶
Get an internal identifier for this property.
Only meant for internal usage.
- Returns
the internal identifier of this property
- Return type
- get_top_k_values(k)¶
Get the top k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Returns
list of k key-value tuples where the keys vertices/edges and the values are property values, sorted in ascending order
- Return type
- get_values()¶
Get the values of this property as a list.
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- property is_published: bool¶
Check if this property is published.
- Returns
True if this property is published, False otherwise.
- Return type
bool
- is_vector_property()¶
Return True if it is a vector property, False otherwise
- Return type
bool
- publish()¶
Publish the property into a shared graph so it can be shared between sessions.
- Returns
None
- Return type
None
- rename(name)¶
Rename this property.
- Parameters
name (str) – New name
- Returns
None
- Return type
None
- set(key, value)¶
Set a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxEdge, int]) – The key (vertex/edge) whose property to set
value (Any) – The property value
- Return type
None
- set_values(values)¶
Set the labels values.
- Parameters
values (PgxMap) – pgxmap with ids and values
- Return type
None
- wrap(property_value, property_type)¶
Take a property value and wraps it pgx entities if applicable
- Parameters
property_value (Any) – property value
property_type (str) – A valid property type.
- Return type
Any
- class pypgx.api.VertexLabels(graph, java_labels)¶
Bases:
pypgx.api._property.VertexProperty
Class for storing labels for vertices.
A vertex can have multiple labels. In effect this is a
VertexProperty
where a set of strings is associated to each vertex.- Parameters
graph (PgxGraph) –
- Return type
None
- clone(name=None)¶
Create a copy of this property.
- Parameters
name (Optional[str]) – name of copy to be created. If None, guaranteed unique name will be generated.
- Returns
property result
- Return type
this class
- close()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- destroy()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- expand()¶
If this is a vector property, expands this property into a list of scalar properties of same type.
The first property will contain the first element of the vector, the second property the second element and so on.
- Return type
Union[pypgx.api._property.PgxProperty, List[pypgx.api._property.PgxProperty]]
- fill(value)¶
Fill this property with a given value.
- Parameters
value (Any) – The value
- Return type
None
- get(key)¶
Get a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The vertex (or vertex ID) whose property to get
- Return type
Any
- get_bottom_k_values(k)¶
Get the bottom k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- get_property_id()¶
Get an internal identifier for this property.
Only meant for internal usage.
- Returns
the internal identifier of this property
- Return type
- get_top_k_values(k)¶
Get the top k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Returns
list of k key-value tuples where the keys vertices/edges and the values are property values, sorted in ascending order
- Return type
- get_values()¶
Get the values of this label as a list.
- Returns
a list of key-value tuples, where each key is a vertex and each key is the set of labels assigned to that vertex
- Return type
list of tuple(PgxVertex, set of str)
- property is_published: bool¶
Check if this property is published.
- Returns
True if this property is published, False otherwise.
- Return type
bool
- is_vector_property()¶
Return True if it is a vector property, False otherwise
- Return type
bool
- publish()¶
Publish the property into a shared graph so it can be shared between sessions.
- Returns
None
- Return type
None
- rename(name)¶
Rename this property.
- Parameters
name (str) – New name
- Returns
None
- Return type
None
- set(key, value)¶
Set a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxVertex, int, str]) – The key (vertex/edge) whose property to set
value (Any) – The property value
- Return type
None
- set_values(values)¶
Set the labels values.
- Parameters
values (PgxMap) – pgxmap with ids and values
- Return type
None
- wrap(property_value, property_type)¶
Take a property value and wraps it pgx entities if applicable
- Parameters
property_value (Any) – property value
property_type (str) – A valid property type.
- Return type
Any
- class pypgx.api.EdgeLabel(graph, java_label)¶
Bases:
pypgx.api._property.EdgeProperty
Class for storing a label type edge property.
- Parameters
graph (PgxGraph) –
- Return type
None
- clone(name=None)¶
Create a copy of this property.
- Parameters
name (Optional[str]) – name of copy to be created. If None, guaranteed unique name will be generated.
- Returns
property result
- Return type
this class
- close()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- destroy()¶
Free resources on the server taken up by this Property.
- Returns
None
- Return type
None
- expand()¶
If this is a vector property, expands this property into a list of scalar properties of same type.
The first property will contain the first element of the vector, the second property the second element and so on.
- Return type
Union[pypgx.api._property.PgxProperty, List[pypgx.api._property.PgxProperty]]
- fill(value)¶
Fill this property with a given value.
- Parameters
value (Any) – The value
- Return type
None
- get(key)¶
Get a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxEdge, int]) – The edge (or edge ID) whose property to get
- Return type
Any
- get_bottom_k_values(k)¶
Get the bottom k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- get_property_id()¶
Get an internal identifier for this property.
Only meant for internal usage.
- Returns
the internal identifier of this property
- Return type
- get_top_k_values(k)¶
Get the top k vertex/edge value pairs according to their value.
- Parameters
k (int) – How many top values to retrieve, must be in the range between 0 and number of nodes/edges (inclusive)
- Returns
list of k key-value tuples where the keys vertices/edges and the values are property values, sorted in ascending order
- Return type
- get_values()¶
Get the values of this property as a list.
- Return type
List[Tuple[pypgx.api._pgx_entity.PgxEntity, Any]]
- property is_published: bool¶
Check if this property is published.
- Returns
True if this property is published, False otherwise.
- Return type
bool
- is_vector_property()¶
Return True if it is a vector property, False otherwise
- Return type
bool
- publish()¶
Publish the property into a shared graph so it can be shared between sessions.
- Returns
None
- Return type
None
- rename(name)¶
Rename this property.
- Parameters
name (str) – New name
- Returns
None
- Return type
None
- set(key, value)¶
Set a property value.
- Parameters
key (Union[pypgx.api._pgx_entity.PgxEdge, int]) – The key (vertex/edge) whose property to set
value (Any) – The property value
- Return type
None
- set_values(values)¶
Set the labels values.
- Parameters
values (PgxMap) – pgxmap with ids and values
- Return type
None
- wrap(property_value, property_type)¶
Take a property value and wraps it pgx entities if applicable
- Parameters
property_value (Any) – property value
property_type (str) – A valid property type.
- Return type
Any
- class pypgx.api._pgx_id.PgxId(java_pgx_id)¶
Bases:
pypgx.api._pgx_context_manager.PgxContextManager
Internal identifier class to uniquely identify PGX objects.
Do not create PgxId objects yourself but use appropriate generator methods.
- Return type
None
- static from_string(value)¶
Parse value as a UUID and generate a PgxId object from it.
If value does not represent a valid UUID, IllegalArgumentException is thrown by the JVM.
- Parameters
value (str) – input UUID
- Return type
- class pypgx.api._version_info.VersionInfo(version_info)¶
Bases:
object
Class that holds version information about PGX.
- Variables
release_version (str) – The PGX release version.
api_version (str) – The PGX API version (e.g. “3.13.0”).
pgql_version (str) – The PGQL version.
server_type (str) – The type of server (“sm” or “distributed”).
build (str) – The date PGX was built, in ISO-8601 format.
commit (str) – The full hash of the commit from which PGX was built.
- Return type
None