Session object

class graphscope.Session(**kwargs)[source]

A class for interacting with GraphScope graph computation service cluster.

A Session object encapsulates the environment in which Operation objects are executed/evaluated.

A session may own resources. It is important to release these resources when they are no longer required. To do this, invoke the close() method on the session.

A Session can register itself as default session with as_default(), and all operations after that will use the default session. Session deregister itself as a default session when closed.

The following example demonstrates its usage:

>>> import graphscope as gs

>>> # use session object explicitly
>>> s = gs.session()
>>> g = s.load_from('xxx')
>>> r = s.sssp(g, 4)
>>> s.close()

>>> # or use a session as default
>>> s = gs.session().as_default()
>>> g = gs.load_from('xxx')
>>> r = gs.sssp(g, 4)
>>> s.close()

We support setup a service cluster and create a RPC session in following ways:

  • GraphScope graph computation service run in cluster managed by kubernetes.

    >>> s = graphscope.session()

    Also, Session provides several keyword params for users to define the cluster. You may use the param k8s_gs_image to specify the image for all engine pod, and param k8s_engine_cpu or k8s_engine_mem to specify the resources. More, you can find all params detail in __init__() method.

    >>> s = graphscope.session(
    ...         k8s_gs_image="",
    ...         k8s_vineyard_cpu=0.1,
    ...         k8s_vineyard_mem="256Mi",
    ...         k8s_vineyard_shared_mem="4Gi",
    ...         k8s_engine_cpu=0.1,
    ...         k8s_engine_mem="256Mi")
  • or all params can be provided by a json configuration file or configuration dict.

    >>> s = graphscope.session(config='/tmp/config.json')
    >>> # Or
    >>> s = graphscope.session(config={'k8s_engine_cpu': 5, 'k8s_engine_mem': '5Gi'})
__init__(config=None, num_workers=2, k8s_namespace=None, k8s_service_type='NodePort', k8s_gs_image='', k8s_etcd_image='', k8s_gie_graph_manager_image='', k8s_zookeeper_image='zookeeper:3.4.14', k8s_image_pull_policy='IfNotPresent', k8s_image_pull_secrets=[], k8s_coordinator_cpu=1.0, k8s_coordinator_mem='4Gi', k8s_vineyard_cpu=0.5, k8s_vineyard_mem='512Mi', k8s_vineyard_shared_mem='4Gi', k8s_engine_cpu=0.5, k8s_engine_mem='4Gi', k8s_waiting_for_delete=False, timeout_seconds=600, **kw)[source]

Construct a new GraphScope session.

  • config (dict or str, optional) – The configuration dict or file about how to launch the GraphScope instance. For str, it will identify it as a path and read the configuration file to build a session if file exist. If not specified, the global default configuration DEFAULT_CONFIG_FILE will be used, which get value of GS_CONFIG_PATH in environment. Note that it will overwrite explicit parameters. Defaults to None.

  • num_workers (int, optional) – The number of workers to launch GraphScope engine. Defaults to 2.

  • k8s_namespace (str, optional) – Contains the namespace to create all resource inside. If param missing or the namespace not exist, a random namespace will be created and deleted when service stopping. Defaults to None.

  • k8s_service_type (str, optional) – Type determines how the GraphScope service is exposed. Valid options are NodePort, and LoadBalancer. Defaults to NodePort.

  • k8s_gs_image (str, optional) – The GraphScope engine’s image.

  • k8s_etcd_image (str, optional) – The image of etcd, which used by vineyard.

  • k8s_image_pull_policy (str, optional) – Kubernetes image pull policy. Defaults to “IfNotPresent”.

  • k8s_image_pull_secrets (list[str], optional) – A list of secret name used to authorize pull image.

  • k8s_gie_graph_manager_image (str, optional) – The GraphScope interactive engine’s graph manager image.

  • k8s_zookeeper_image (str, optional) – The image of zookeeper, which used by GIE graph manager.

  • k8s_vineyard_cpu (float, optional) – Minimum number of CPU cores request for vineyard container. Defaults to 0.5.

  • k8s_vineyard_mem (str, optional) – Minimum number of memory request for vineyard container. Defaults to ‘512Mi’.

  • k8s_vineyard_shared_mem (str, optional) – Init size of vineyard shared memory. Defaults to ‘4Gi’.

  • k8s_engine_cpu (float, optional) – Minimum number of CPU cores request for engine container. Defaults to 0.5.

  • k8s_engine_mem (str, optional) – Minimum number of memory request for engine container. Defaults to ‘4Gi’.

  • k8s_coordinator_cpu (float, optional) – Minimum number of CPU cores request for coordinator pod. Defaults to 1.0.

  • k8s_coordinator_mem (str, optional) – Minimum number of memory request for coordinator pod. Defaults to ‘4Gi’.

  • timeout_seconds (int, optional) – For waiting service ready (or waiting for delete if k8s_waiting_for_delete is True). Also, after seconds of client disconnect, coordinator will clean up this graphscope instance. Defaults to 600.

  • k8s_waiting_for_delete (bool, optional) – Waiting for service delete or not. Defaults to False.

  • **kw (dict, optional) –

    Other optional parameters will be put to **kw. - k8s_minikube_vm_driver (bool, optional):

    If your kubernetes cluster deployed on inner virtual machine (such as minikube with param –vm-driver is not None), you can specify k8s_minikube_vm_driver is True.

    • k8s_client_config (dict, optional):

      Provide configurable parameters for connecting to remote k8s, which strongly relies on the kube_config.new_client_from_config function. eg: {“config_file”: “~/.kube/config”, “context”: None, “persist_config”: True} config_file: Name of the kube-config file. context: set the active context. If is set to None, current_context from config file will be used. persist_config: If True, config file will be updated when changed(e.g GCP token refresh).

    • log_level: Deprecated.

      Move this param as a global configuration. Set via graphscope.set_option(log_level=’DEBUG’)

    • show_log: Deprecated.

      Move this param as a global configuration.Set via graphscope.set_option(show_log=True)


TypeError – If the given argument combination is invalid and cannot be used to create a GraphScope session.


Obtain a context manager that make this object as default session.

This method is used when a Session is constructed, which will immediately install self as a default session.


ValueError – If default session exist in current context.


A context manager using this session as the default session.


Closes this session.

This method frees all resources associated with the session.


Get configuration of the session.


Get a interactive engine handler to execute gremlin queries.




InvalidArgumentErrorgraph is not a property graph or unloaded.



property info

Show all resources info associated with session in json format.

learning(graph, nodes=None, edges=None, gen_labels=None)[source]

Start a graph learning engine.

  • nodes (list) – The node types that will be used for gnn training.

  • edges (list) – The edge types that will be used for gnn training.

  • gen_labels (list) – Extra node and edge labels on original graph for gnn training.


An instance of graphscope.learning.Graph

that could be feed to the learning engine.

Return type


load_from(*args, **kwargs)[source]

Load a graph within the session. See more information in graphscope.load_from().

Session Functions


alias of graphscope.client.session.Session


Returns the default session for the current context.


Set the value of specified options.


Get the value of specified option.