0
votes

Microsoft didn't publish Python graph examples for CosmosDB (yet) - and I don't think that client.QueryDocuments() is the right method to execute Gremlin statements - see below:

client = document_client.DocumentClient(endpoint, masterkey)
collection_link = 'dbs/' + database + '/colls/' + collection
collection = client.ReadCollection(collection_link)
print('Collection with id \'{0}\' was found'.format(collection['id'])

gremlin = 'g.V().count()'
docs = client.QueryDocuments(collection_link, gremlin)
print(docs)

The result is not a JSON of executed Gremlin statement (the count of nodes in the graph) - it is

< pydocumentdb.query_iterable.QueryIterable object at 0x05341EFF>

Am I missing the right function in Python CosmosDB SDK, or is it simply not there?

1

1 Answers

0
votes

You cannot use the DocumentClient to execute graph queries against Cosmos in any language except for C# currently. However, Cosmos does expose a gremlin server endpoint which you can hit using any valid Gremlin client. I'm not very familiar with what's out there in the Python world but some quick googling turned up two different open source Python Gremlin clients which may give you the functionality that you need:

https://github.com/davebshow/gremlinclient

https://github.com/windj007/python-gremlin-rest

More information about connecting to and using the Gremlin Server endpoint are available in the Microsoft docs