Azure Cosmos DB Gremlin API SDKs
This document provides an overview and guide to using the various Software Development Kits (SDKs) available for interacting with Azure Cosmos DB through its Gremlin API. The Gremlin API allows you to model and query your data as a graph, leveraging the power of Apache TinkerPop Gremlin traversal language.
Overview
Azure Cosmos DB is a globally distributed, multi-model database service. The Gremlin API exposes a graph database experience within Cosmos DB. To effectively integrate graph database functionality into your applications, you can utilize the official SDKs provided for various programming languages.
These SDKs abstract away the complexities of HTTP requests and offer a more idiomatic way to interact with your graph data. They provide methods for creating vertices, edges, updating properties, and executing Gremlin queries.
Available SDKs
We support a range of popular programming languages. Choose the SDK that best fits your application's technology stack:
Java SDK
Integrate Gremlin API functionality seamlessly into your Java applications. This SDK provides a robust API for graph operations.
Learn More & Download.NET SDK
A comprehensive SDK for developers working with the .NET ecosystem. Leverage the power of Gremlin within your C# or F# applications.
Learn More & DownloadPython SDK
Easily add graph database capabilities to your Python projects. The SDK simplifies common graph traversal and manipulation tasks.
Learn More & DownloadNode.js SDK
Build server-side applications with Node.js that interact with your Cosmos DB graph. This SDK is designed for asynchronous operations.
Learn More & DownloadGetting Started
To get started with any of the SDKs, you'll typically need to:
- Create an Azure Cosmos DB Account with the Gremlin API enabled.
- Obtain Connection Details such as the Gremlin endpoint and primary key from your Cosmos DB account portal.
- Install the SDK using your language's package manager (e.g., Maven for Java, NuGet for .NET, pip for Python, npm for Node.js).
- Initialize the Graph Client in your application using the connection details.
- Begin executing Gremlin queries or using the provided graph manipulation methods.
Example (Conceptual - Python)
Here's a simplified conceptual example of how you might use the Python SDK:
# This is a conceptual example and may require specific library imports and configurations.
from azure.cosmos.gremlin import GremlinClient # Hypothetical import
# Replace with your actual Cosmos DB Gremlin endpoint and key
endpoint = "https://your-cosmos-db-account.gremlin.cosmos.azure.com:443/"
key = "YOUR_PRIMARY_KEY"
database_name = "yourDatabaseName"
graph_name = "yourGraphName"
try:
# Initialize the Gremlin client
client = GremlinClient(endpoint, key)
# Connect to the graph
graph = client.graph(database_name, graph_name)
# Example Gremlin query: Add a vertex
vertex_data = {
"id": "person1",
"label": "person",
"properties": {
"name": "Alice",
"age": 30
}
}
added_vertex = graph.add_v(vertex_data)
print(f"Added vertex: {added_vertex}")
# Example Gremlin query: Traverse to find vertices by label
people = list(graph.V().hasLabel("person").toList())
print("Found people:")
for person in people:
print(f"- {person['properties']['name']}")
except Exception as e:
print(f"An error occurred: {e}")
Further Resources
- Official Gremlin API Documentation
- Apache TinkerPop Gremlin Language Reference
- Azure Cosmos DB Portal
Explore the specific SDK documentation for detailed API references, advanced usage patterns, and troubleshooting guides.