A.12.5.1 Creating a Property Graph Using the Python Client
You can create a property graph using the CREATE PROPERTY GRAPH
statement in Python.
Creating a Property Graph Using the Python Client
- Launch the Python client as
shown:
./bin/opg4py --no_connect
- Create a PGQL connection to connect to the database as
shown:
>>> pgql_conn = opg4py.pgql.get_connection(<user>, <password>, <jdbc_url>) PgqlConnection(schema: GRAPHUSER, graph: None)
- Create a PGQL statement as
shown:
>>> pgql_statement = pgql_conn.create_statement() PgqlStatement(java_pgql_statement: oracle.pg.rdbms.pgql.PgqlStatement)
- Define and execute the
CREATE PROPERTY GRAPH
statement as shown:pgql = """ CREATE PROPERTY GRAPH <graph_name> VERTEX TABLES ( bank_accounts LABEL accounts PROPERTIES ALL COLUMNS ) EDGE TABLES ( bank_txns SOURCE KEY (from_acct_id) REFERENCES bank_accounts (acct_id) DESTINATION KEY (to_acct_id) REFERENCES bank_accounts (acct_id) LABEL transfers PROPERTIES ALL COLUMNS ) OPTIONS ( PG_SCHEMA ) """
where <graph_name> is the name of the graph.
pgql_statement.execute(pgql)
The graph gets created.
Parent topic: Using the Python Client to Execute PGQL Queries