Skip to content

Commit 24e6334

Browse files
committed
Installation and Getting Started doc improvements
1 parent d6124b6 commit 24e6334

2 files changed

Lines changed: 42 additions & 13 deletions

File tree

docs/getting_started.rst

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ The simplest way to create a :class:`~.Cluster` is like this:
1616
1717
from cassandra.cluster import Cluster
1818
19-
cluster = Cluster(['10.1.1.3', '10.1.1.4', '10.1.1.5'])
19+
cluster = Cluster()
20+
21+
This will attempt to connection to a Cassandra instance on your
22+
local machine (127.0.0.1). You can also specify a list of IP
23+
addresses for nodes in your cluster:
24+
25+
.. code-block:: python
26+
27+
from cassandra.cluster import Cluster
28+
29+
cluster = Cluster(['192.168.0.1', '192.168.0.2'])
2030
2131
The set of IP addresses we pass to the :class:`~.Cluster` is simply
2232
an initial set of contact points. After the driver connects to one
@@ -33,7 +43,7 @@ behavior in some other way, this is the place to do it:
3343
from cassandra.polices import DCAwareRoundRobinPolicy
3444
3545
cluster = Cluster(
36-
contact_points=['10.1.1.3', '10.1.1.4', '10.1.1.5'],
46+
['10.1.1.3', '10.1.1.4', '10.1.1.5'],
3747
load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='US_EAST'),
3848
port=9042)
3949
@@ -42,15 +52,19 @@ You can find a more complete list of options in the :class:`~.Cluster` documenta
4252

4353
Instantiating a :class:`~.Cluster` does not actually connect us to any nodes.
4454
To establish connections and begin executing queries we need a
45-
:class:`~.Session`, which is created by calling :meth:`.Cluster.connect()`.
55+
:class:`~.Session`, which is created by calling :meth:`.Cluster.connect()`:
56+
57+
.. code-block:: python
58+
59+
cluster = Cluster()
60+
session = cluster.connect()
61+
4662
The :meth:`~.Cluster.connect()` method takes an optional ``keyspace`` argument
4763
which sets the default keyspace for all queries made through that :class:`~.Session`:
4864

4965
.. code-block:: python
5066
51-
from cassandra.cluster import Cluster
52-
53-
cluster = Cluster(['10.1.1.3', '10.1.1.4', '10.1.1.5'])
67+
cluster = Cluster()
5468
session = cluster.connect('mykeyspace')
5569
5670
@@ -82,7 +96,14 @@ By default, each row in the result set will be a
8296
`namedtuple <http://docs.python.org/2/library/collections.html#collections.namedtuple>`_.
8397
Each row will have a matching attribute for each column defined in the schema,
8498
such as ``name``, ``age``, and so on. You can also treat them as normal tuples
85-
by unpacking them or accessing fields by position:
99+
by unpacking them or accessing fields by position. The following three
100+
examples are equivalent:
101+
102+
.. code-block:: python
103+
104+
rows = session.execute('SELECT name, age, email FROM users')
105+
for row in rows:
106+
print row.name, row.age, row.email
86107
87108
.. code-block:: python
88109
@@ -93,9 +114,8 @@ by unpacking them or accessing fields by position:
93114
.. code-block:: python
94115
95116
rows = session.execute('SELECT name, age, email FROM users')
96-
names = [row[0] for row in rows]
97-
ages = [row[1] for row in rows]
98-
emails = [row[2] for row in rows]
117+
for row in row:
118+
print row[0], row[1], row[2]
99119
100120
If you prefer another result format, such as a ``dict`` per row, you
101121
can change the :attr:`~.Session.row_factory` attribute.

docs/installation.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ Once the dependencies are installed, simply run::
3232

3333
python setup.py install
3434

35-
(Optional) Non-python Dependencies
36-
----------------------------------
35+
Verifying your Installation
36+
---------------------------
37+
To check if the installation was successful, you can run:
38+
39+
python -c 'import cassandra; print cassandra.__version__'
40+
41+
It should print something like "2.0.0".
42+
43+
(*Optional*) Non-python Dependencies
44+
------------------------------------
3745
The driver has several **optional** features that have non-Python dependencies.
3846

3947
C Extensions
@@ -113,4 +121,5 @@ just run ``apt-get install python-snappy``.)
113121

114122
Setting SSL
115123
-----------
116-
Andrew Mussey has published a thorough guide on `Using SSL with the DataStax Python driver <http://blog.amussey.com/post/64036730812/cassandra-2-0-client-server-ssl-with-datastax-python>`_.
124+
Andrew Mussey has published a thorough guide on
125+
`Using SSL with the DataStax Python driver <http://blog.amussey.com/post/64036730812/cassandra-2-0-client-server-ssl-with-datastax-python>`_.

0 commit comments

Comments
 (0)