Connecting to a graph server

The Oracle Graph server (PGX) uses an Oracle Database as identity manager. Both username and password based as well as Kerberos based authentication is supported.

You can connect to a graph server (PGX) instance in your Python program. You must first authenticate with the server before you can create a session as illustrated in the following example:

 1import pypgx as pgx
 2from opg4py import graph_server
 3
 4base_url = "https://localhost:7007"
 5username = "scott"
 6password = "tiger"
 7
 8instance = graph_server.get_instance(base_url, username, password)
 9session = instance.create_session("python_pgx_client")
10print(session)

if your token expires, you can log in again without losing any of your session data by reauthenticating as illustrated in the following example:

1graph_server.reauthenticate(instance, "<user>", "<password>") # log in again

Refer to the section below, for the complete API reference on user authentication.

opg4py.graph_server.GraphServer

Wrapper class for oracle.pg.rdbms.GraphServer

opg4py.graph_server.generate_token(base_url, username, password)

Generates a new authentication token.

Parameters
  • base_url – the base URL in the format host [ : port][ /path] of the remote graph server.

  • username – the Database username to use for authentication.

  • password – the Database password to use for authentication.

Returns

the newly generated authentication token

opg4py.graph_server.get_embedded_instance()

Connects to an embedded graph server. An embedded graph server runs inside the client JVM.

Returns

a handle to the embedded graph server

opg4py.graph_server.get_instance(base_url, username, password, refresh_time_before_token_expiry=-1, *, kerberos_ticket_path=None)

Connects to a remote graph server.

Parameters
  • base_url (str) – the base URL in the format host [ : port][ /path] of the remote graph server. If base_url is None, the default will be used which points to embedded graph server instance.

  • username (str) – the Database username to use for authentication.

  • password (str) – the Database password to use for authentication.

  • refresh_time_before_token_expiry (int) –

    the time in seconds to refresh the token automatically before expires.

    Deprecated since version 23.1.0: moved refresh_time_before_token_expiry value to the pgx.conf (refresh_time_before_token_expiry_seconds)

  • kerberos_ticket_path (Optional[str]) – the kerberos ticket to be used for authentication.

Returns

a handle to the remote graph server

Return type

ServerInstance

opg4py.graph_server.reauthenticate(instance, username, password)

Re-authenticates an existing ServerInstance object with a remote graph server.

Parameters
  • instance – the PGX instance on which the session is going to reauthenticate.

  • username – the Database username to use for authentication.

  • password – the Database password to use for authentication.

Returns

the newly generated authentication token