6.8.5 Python APIs for Executing CREATE PROPERTY GRAPH Statements

You can create a property graph by executing the CREATE PROPERTY GRAPH statement through the Python API.

Creating a Property Graph Using the Python Client

  • Launch the Python client:
    ./bin/opg4py --base_url https://localhost:7007 --user customer_360
  • Define and execute the CREATE PROPERTY GRAPH statement as shown:
    statement = (
           "CREATE PROPERTY GRAPH "+ "<graph_name>" + " " +
           "VERTEX TABLES ( " +
           "bank_accounts " +
           "KEY(acct_id) " +
           "LABEL Account PROPERTIES (acct_id) " +
           ")" +
           "EDGE TABLES ( " +
           "bank_txns " +
           "KEY (txn_id) " +
           "SOURCE KEY (from_acct_id) REFERENCES bank_accounts " +
           "DESTINATION KEY (to_acct_id) REFERENCES bank_accounts " +
           "LABEL Transfer PROPERTIES(amount) " +
           ")")
    >>> session.prepare_pgql(statement).execute()

    where <graph_name> is the name of the graph.

    The graph gets created and you can verify through the get_graph method:
    >>> graph = session.get_graph("<graph_name>")
    >>> graph
    PgxGraph(name:<graph_variable>, v: 1000, e: 5001, directed: True, memory(Mb): 0)