1

The documentation on the Azure site for CosmoDB & Gremlin & Python[1][2][3] use bad practices - tons of code duplication and concatenating strings to form queries, rather than using native python.

However, when trying to use the native SDK, there's a 2 year old bug that prevents it due to serialization errors[4].

What's the best way to use Gremlin & Python with CosmosDB? Should I give up on Gremlin altogether - and if so, what's the alternative solution?

[1] https://learn.microsoft.com/en-us/samples/azure-samples/azure-cosmos-db-graph-python-getting-started/azure-cosmos-db-graph-python-getting-started/

[2] https://learn.microsoft.com/en-us/azure/cosmos-db/create-graph-pytho

[3] https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started

[4] https://github.com/Azure/azure-cosmos-dotnet-v2/issues/439

aronchick
  • 6,786
  • 9
  • 48
  • 75

1 Answers1

2

Without pure bytecode support as you noted here the story for Python usage for CosmosDB with Gremlin is not so good. There are some mechanisms for translating bytecode to script representations like GroovyTranslator for Java and Translator for Javascript. For example, in Javascript you could do:

const script = new Translator('g').translate(g.V().out('created').getBytecode());

and then submit that script to CosmosDB (example for Java is here). Not great but arguably better than embedding fat strings of Gremlin into your code. Unfortunately, there is no support for this functionality in Python at this time. I've created an issue in JIRA to track it (TINKERPOP-2366 - Python and TINKERPOP-2367 - .NET) as I've seen this question come up in different forms with reasonable consistency.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135