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
The prepare_pgql(<pgql_query>).execute() Python API creates a property graph in the graph server (PGX). Note that when using this API, the graph is not persisted in the database, it is only created in the graph server (PGX). If you wish to persist a graph in the database, then you can create the graph in the database (see Quick Starts for Using PGQL Property Graphs) and then load the graph into graph server (PGX).
-
Launch the Python client:
./bin/opg4py --base_url https://localhost:7007 --user customer_360 -
Define and execute the
CREATE PROPERTY GRAPHstatement as shown:statement = ( "CREATE PROPERTY GRAPH "+ "<graph_name>" + " " + "VERTEX TABLES ( " + "bank_accounts " + "KEY(id) " + "LABEL Account PROPERTIES (id) " + ")" + "EDGE TABLES ( " + "bank_transfers " + "KEY (txn_id) " + "SOURCE KEY (src_acct_id) REFERENCES bank_accounts (id) " + "DESTINATION KEY (dst_acct_id) REFERENCES bank_accounts (id) " + "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_graphmethod:>>> graph = session.get_graph("<graph_name>") >>> graph PgxGraph(name:<graph_variable>, v: 1000, e: 5001, directed: True, memory(Mb): 0)