18.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
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 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 (acct_id) " + "DESTINATION KEY (to_acct_id) REFERENCES bank_accounts (acct_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 theget_graph
method:>>> graph = session.get_graph("<graph_name>") >>> graph PgxGraph(name:<graph_variable>, v: 1000, e: 5001, directed: True, memory(Mb): 0)
Parent topic: Executing PGQL Queries Against the Graph Server (PGX)