g2c is a python script to convert Gremlin query to Cypher query with OpenAI API
Project description
g2c
Overview
g2c is a python script to convert Gremlin query to Cypher query with OpenAI API
Table of Contents
Installation
Just add tap and install homebrew package.
brew tap rioriost/g2c
brew install g2c
Prerequisites
- Python 3.11 or higher
- OpenAI API key enabled to call gpt-4o-mini
Usage
Execute g2c command.
g2c --help
usage: g2c [-h] [-a] [-m MODEL] [-d] (-g GREMLIN | -f FILEPATH | -u URL)
Convert Gremlin queries to Cypher queries.
options:
-h, --help show this help message and exit
-a, --age Convert to the Cypher query for Apache AGE.
-m MODEL, --model MODEL
OpenAI model to use.
-d, --dryrun Dry run with PostgreSQL. Requires a valid PostgreSQL connection string as 'PG_CONNECTION_STRING' environment variable.
-g GREMLIN, --gremlin GREMLIN
The Gremlin query to convert.
-f FILEPATH, --filepath FILEPATH
Path to the source code file (.py, .java, .cs, .txt)
-u URL, --url URL URL to the source code file (.py, .java, .cs, .txt)
The indentical usage is shown below.
with -g(--gremlin)
g2c -g 'g.V().has(“name”, “Alice”).as(“a”).V().has(“name”, “Bob”).as(“b”).select(“a”, “b”).by(“name”)'
Converted Cypher queries:
line 1, g.V().has("name", "Alice").as("a").V().has("name", "Bob").as("b").select("a", "b").by("name") ->
MATCH (a {name: "Alice"}), (b {name: "Bob"}) RETURN a.name AS a, b.name AS b
with -u(--url)
g2c -u https://raw.githubusercontent.com/nedlowe/gremlin-python-example/refs/heads/master/app.py
Converted Cypher queries:
line 42, g.V(person_id).toList() ->
MATCH (n) WHERE id(n) = $person_id RETURN n
line 42, g.V(person_id) ->
MATCH (n) WHERE id(n) = $person_id RETURN n
line 55, g.V(vertex).valueMap().toList() ->
MATCH (n) WHERE ID(n) = $vertex RETURN properties(n)
line 55, g.V(vertex).valueMap() ->
MATCH (n) WHERE ID(n) = $vertex RETURN properties(n)
......
with -f(--filepath)
g2c -f ~/Desktop/gremlin_samples.py
Converted Cypher queries:
line 1, g.V() ->
MATCH (n) RETURN n
line 2, g.E() ->
MATCH ()-[r]-() RETURN r
line 3, g.V().hasLabel('person') ->
MATCH (n:person) RETURN n
line 4, g.V().hasLabel('software') ->
MATCH (n:software) RETURN n
......
with -a(--age)
g2c -a -g "g.V().hasLabel('person').aggregate('a')"
Converted Cypher queries:
line 1, g.V().hasLabel('person').aggregate('a') ->
SELECT * FROM cypher('GRAPH_NAME', $$ MATCH (n:person) WITH collect(n) AS a RETURN a $$) AS (a agtype);
with -d(--dryrun)
g2c -d -g "g.V().hasLabel('person').aggregate('a')"
Converted Cypher queries:
line 1, g.V().hasLabel('person').aggregate('a') ->
SELECT * FROM cypher('GRAPH_NAME', $$ MATCH (n:person) WITH collect(n) AS a RETURN a $$) AS (a agtype);
[Query executed successfully]
g2c -d -g "g.V(person).property(prop_name, prop_value)"
Converted Cypher queries:
line 1, g.V(person).property(prop_name, prop_value) ->
DEALLOCATE ALL; PREPARE cypher_stored_procedure(agtype) AS SELECT * FROM cypher('GRAPH_NAME', $$ MATCH (n) WHERE ID(n) = $person SET n[$prop_name] = $prop_value RETURN n $$, $1) AS (n agtype);EXECUTE cypher_stored_procedure('{"person": 12345, "prop_name": 12345, "prop_value": 12345}');
[Error executing query: SET clause expects a property name
LINE 1: ...APH_NAME', $$ MATCH (n) WHERE ID(n) = $person SET n[$prop_na...
^]
Release Notes
0.4.3 Release
- Updated for the dependencies
0.4.2 Release
- Fixed a small bug
0.4.1 Release
- Updated for the dependencies
0.4.0 Release
- Stopped to use antlr to analyze the Cypher query, removed the dependencies to antlr and generated lexer, parser, and visitor.
- Added '--model' argument to enable switching the default model, 'gpt-4o-mini' to others such as 'o3-mini' and so on. If you have an OpenAI subscription to use smarter models, strongly recommended to use them.
- Added '--dryrun' argument to enable dry run mode. If dryrun is true, this script will try to connect to PostgreSQL with Apache AGE extension and to execute the converted Cypher query. It requires PG_CONNECTION_STRING environment variable for 'TESTING' PostgreSQL.
0.3.0 Release
- Refactored the code
- Fixed a bug to save a cache. If you're using the old versions, please delete the .g2c_cache file under your home directory.
- Added '--age' argument to convert Gremlin query to Cypher using Apache AGE
0.2.0 Release
- Changed the default behaviour to accept a Gremlin query (-g), a file (-f), or a URL (-u).
- Added feature to extract Gremlin queries from a file or URL.
- Added CacheManager and a feature to deploy a cache file to user home directory if it doesn't exist.
0.1.0 Release
- Initial release.
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file g2c-0.4.3.tar.gz.
File metadata
- Download URL: g2c-0.4.3.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.27
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51453b8a7dacb680ea53df70523073c2cb170e7fa0d6a2c0857abe69f441fda3
|
|
| MD5 |
c1d9a8dbfeae2bef54c982a92291d3b9
|
|
| BLAKE2b-256 |
7828309d115a463649c49243be79832ab4dcc52eafe52d9b210cd26e8ee5d896
|
File details
Details for the file g2c-0.4.3-py3-none-any.whl.
File metadata
- Download URL: g2c-0.4.3-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.27
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
080148b14b3ef0cd4dfa8d1c96ffee001aeb27f8b9edc29aaa90d8749a4dd66f
|
|
| MD5 |
75f505789ce3e243cd3a033703b176d7
|
|
| BLAKE2b-256 |
94ec3c9aac4f633647432505904ac3d4eb08e13aeecaae57c4c53365327976c9
|