Created
September 6, 2024 19:43
-
-
Save JessicaGreben/8877d1b961234b16d11282c8c804a1e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://pypi.org/project/gremlinpython/ | |
from gremlin_python.process.anonymous_traversal import traversal | |
from gremlin_python.process.traversal import IO | |
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection | |
import ssl | |
import datetime | |
import sys | |
if __name__ == '__main__': | |
host = 'wss://<replace with db hostname from UI>:4000' | |
remoteConn = DriverRemoteConnection( | |
host+"/gremlin", | |
'g', | |
username="<replace with api key ID>", | |
password="<replace with api key secret>", | |
) | |
g = traversal().with_remote(remoteConn) | |
try: | |
# Add a new vertex. | |
x = f"foo-{datetime.datetime.now()}" | |
g.add_v('foo').property(x,'aerospike').iterate() | |
except Exception as e: | |
print(f"Exception: {e}") | |
try: | |
# Read back the new vertex. | |
result = g.V().has(x,'aerospike').element_map().to_list() | |
print("Success! Read back the vertex:", result) | |
except Exception as e: | |
print(f"Exception: {e}") | |
remoteConn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment