All Products
Search
Document Center

Lindorm:Develop applications with non-Java Cassandra CQL drivers

Last Updated:Mar 30, 2026

Connect to LindormTable over Cassandra Query Language (CQL) using the official Cassandra client driver for your language: Python, C++, Node.js, or Go.

Prerequisites

Before you begin, make sure you have:

  • You have obtained the CQL connection address for LindormTable.CQL connection address

  • The official driver package for your target language installed. For a full list of supported drivers, see Cassandra client drivers.

Connect with Python

Install the driver

Install the DataStax Python driver. Version 3.x is recommended.

# Install a specific version (recommended)
pip install cassandra-driver==3.19.0

# Install the latest version
pip install cassandra-driver

Verify the installation:

python -c "import cassandra; print(cassandra.__version__)"

The command prints the installed version number, such as 3.19.0.

Connect and run queries

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import logging
import sys
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

# Initialize the cluster with the LindormTable CQL endpoint.
# No port number is needed.
cluster = Cluster(
    contact_points=["ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com"],
    auth_provider=PlainTextAuthProvider("cassandra", "****"))

session = cluster.connect()

# Create a keyspace.
session.execute(
    "CREATE KEYSPACE IF NOT EXISTS testKeyspace WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};")

# Create a table.
session.execute(
    "CREATE TABLE IF NOT EXISTS testKeyspace.testTable (id int PRIMARY KEY, name text, age int, address text);")

# Insert a row.
session.execute(
    "INSERT INTO testKeyspace.testTable (id, name, age, address) VALUES (1, 'testname', 11, 'hangzhou');")

# Query rows.
rows = session.execute("SELECT * FROM testKeyspace.testTable;")
for row in rows:
    print("Row: {}".format(row))

# Release resources.
session.shutdown()
cluster.shutdown()

Connect with C++

Download the driver

Download the DataStax C++ driver from datastax/cpp-driver.

Connect and run queries

CassFuture* connect_future = NULL;
CassCluster* cluster = cass_cluster_new();
CassSession* session = cass_session_new();

// Specify the LindormTable CQL endpoint. No port number is needed.
const char* hosts = "ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com";

cass_cluster_set_contact_points(cluster, hosts);
connect_future = cass_session_connect(session, cluster);

if (cass_future_error_code(connect_future) == CASS_OK) {
    // Execute a SELECT query.
    const char* query = "SELECT name FROM testKeyspace.testTable";
    CassStatement* statement = cass_statement_new(query, 0);
    CassFuture* result_future = cass_session_execute(session, statement);

    if (cass_future_error_code(result_future) == CASS_OK) {
        // Process the result.
        const CassResult* result = cass_future_get_result(result_future);
        const CassRow* row = cass_result_first_row(result);

        if (row) {
            const CassValue* value = cass_row_get_column_by_name(row, "name");
            const char* name;
            size_t name_length;
            cass_value_get_string(value, &name, &name_length);
            printf("release_version: '%.*s'\n", (int)name_length, name);
        }

        cass_result_free(result);
    } else {
        // Handle query errors.
        const char* message;
        size_t message_length;
        cass_future_error_message(result_future, &message, &message_length);
        fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message);
    }

    cass_statement_free(statement);
    cass_future_free(result_future);

    // Close the session and release resources.
    CassFuture* close_future = cass_session_close(session);
    cass_future_wait(close_future);
    cass_future_free(close_future);
} else {
    // Handle connection errors.
    const char* message;
    size_t message_length;
    cass_future_error_message(connect_future, &message, &message_length);
    fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length, message);
}

cass_future_free(connect_future);
cass_cluster_free(cluster);
cass_session_free(session);

Connect with Node.js

Install the driver

npm install cassandra-driver

Connect and run queries

Set localDataCenter to datacenter1. The driver returns Promises—use .then() chains or async/await interchangeably.

const cassandra = require('cassandra-driver');

// Initialize the client. No port number is needed in the endpoint.
// Set localDataCenter to 'datacenter1'.
const client = new cassandra.Client({
    contactPoints: ['ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com'],
    localDataCenter: 'datacenter1',
    credentials: { username: 'Username', password: 'Password' }
});

client.connect()
    .then(() => client.execute("CREATE KEYSPACE IF NOT EXISTS lindormtest WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '2' }"))
    .then(() => client.execute("CREATE TABLE IF NOT EXISTS lindormtest.nodejs (name text PRIMARY KEY, age int)"))
    .then(() => client.execute("INSERT INTO lindormtest.nodejs (name, age) VALUES ('lindorm', 10)"))
    .then(() => client.execute("SELECT name, age FROM lindormtest.nodejs WHERE name = 'lindorm'"))
    .then(result => {
        const row = result.first();
        console.log('Row:', row);
    })
    .finally(() => client.shutdown());

Connect with Go

Install the driver

go get github.com/gocql/gocql

Connect and run queries

package main

import (
    "fmt"
    "log"

    "github.com/gocql/gocql"
)

func main() {
    // Specify the LindormTable CQL endpoint. No port number is needed.
    cluster := gocql.NewCluster("ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com")
    cluster.Authenticator = gocql.PasswordAuthenticator{
        Username: "Username",
        Password: "Password",
    }

    session, err := cluster.CreateSession()
    if err != nil {
        log.Fatal(err)
    }
    defer session.Close()

    // Create a keyspace.
    if err := session.Query(`CREATE KEYSPACE ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}`).Exec(); err != nil {
        log.Fatal(err)
    }

    // Create a table.
    if err := session.Query(`CREATE TABLE ks.tb (cn1 text PRIMARY KEY, cn2 text, cn3 text)`).Exec(); err != nil {
        log.Fatal(err)
    }

    // Insert a row.
    if err := session.Query(`INSERT INTO ks.tb (cn1, cn2, cn3) VALUES (?, ?, ?)`,
        "v11", "v12", "v13").Exec(); err != nil {
        log.Fatal(err)
    }

    // Query a single row.
    var column1, column2 string
    if err := session.Query(`SELECT cn1, cn2 FROM ks.tb WHERE cn1 = ?`,
        "v11").Consistency(gocql.One).Scan(&column1, &column2); err != nil {
        log.Fatal(err)
    }
    fmt.Println("Row:", column1, column2)

    // Iterate over all matching rows.
    var column3 string
    iter := session.Query(`SELECT * FROM ks.tb WHERE cn1 = ?`, "v11").Iter()
    for iter.Scan(&column1, &column2, &column3) {
        fmt.Println("Row:", column1, column2, column3)
    }
    if err := iter.Close(); err != nil {
        log.Fatal(err)
    }
}