Database Reference
In-Depth Information
client.Connect("127.0.0.1");
client.CreateSchema();
client.LoadData();
client.PrinResults();
client.Close();
}
}
}
Python
Though there are several Python drivers out there, the current driver that fully sup-
ports the CQL 3 Binary Protocol is the driver distributed by DataStax. To install
the Python driver, ensure that you have pip already installed on your system and
run pip install cassandra-driver .
To start the example, we will first create an empty class with a cluster and a
session variable. We will also need to import our required package. Listing 9.15
outlines how to import the required packages and create our sample class.
Listing 9.15 Creating a Sample Class in Python
Click here to view code image
from cassandra.cluster import Cluster
class SampleApp(object):
cluster = None
session = None
Connecting
When connecting to the cluster, we need to specify only a single node. The driver
will automatically query for information about the cluster and build a connection
to each of the nodes in the cluster. Listing 9.16 shows how to connect to a cluster
and print out information about the connections to the cluster.
Listing 9.16 Using Python to Connect to a Cluster
Click here to view code image
 
 
Search WWH ::




Custom Search