@@ -136,13 +136,27 @@ def close(self):
136136
137137
138138class Session (object ):
139- """ Logical session carried out over an established TCP connection.
140- Sessions should generally be constructed using the :meth:`.Driver.session`
141- method.
139+ """ A `Session` is a logical context for transactional units of work.
140+ It typically wraps a TCP connection and should generally be constructed
141+ using the :meth:`.Driver.session` method.
142+
143+ Sessions are not thread safe and can recycle connections via a
144+ :class:`.Driver` connection pool. As such, they should be considered
145+ lightweight and disposable.
146+
147+ Typically, Session instances will be created and destroyed within a
148+ `with` context. For example::
149+
150+ with driver.session() as session:
151+ result = session.run("MATCH (a:Person) RETURN a.name")
152+ # do something with the result...
153+
142154 """
143155
156+ #: The current :class:`.Transaction` instance, if any.
144157 transaction = None
145158
159+ #: The bookmark received from completion of the last :class:`.Transaction`.
146160 last_bookmark = None
147161
148162 def __del__ (self ):
@@ -155,7 +169,8 @@ def __exit__(self, exc_type, exc_value, traceback):
155169 self .close ()
156170
157171 def close (self ):
158- """ Close the session.
172+ """ Close the session. This will release any borrowed resources,
173+ such as connections, and will roll back any outstanding transactions.
159174 """
160175 if self .transaction :
161176 try :
@@ -164,14 +179,16 @@ def close(self):
164179 pass
165180
166181 def closed (self ):
167- """ Return true if the session is closed, false otherwise.
182+ """ Indicator for whether or not this session has been closed.
183+
184+ :return: :const:`True` if closed, :const:`False` otherwise.
168185 """
169186
170187 def run (self , statement , parameters = None , ** kwparameters ):
171188 """ Run a parameterised Cypher statement. If an explicit transaction
172189 has been created, the statement will be executed within that
173190 transactional context. Otherwise, this will take place within an
174- auto-commit transaction.
191+ * auto-commit transaction* .
175192
176193 :param statement: Cypher statement to execute
177194 :param parameters: dictionary of parameters
@@ -180,14 +197,16 @@ def run(self, statement, parameters=None, **kwparameters):
180197 """
181198
182199 def fetch (self ):
183- """ Fetch the next message if available and return
184- the number of messages fetched.
200+ """ Fetch the next message if available.
201+
202+ :return: The number of messages fetched (zero or one)
185203 """
186204 return 0
187205
188206 def sync (self ):
189- """ Full send and receive. Return the total number
190- of records received.
207+ """ Carry out a full send and receive.
208+
209+ :return: Total number of records received
191210 """
192211 return 0
193212
@@ -197,6 +216,7 @@ def begin_transaction(self, bookmark=None):
197216 :param bookmark: a bookmark to which the server should
198217 synchronise before beginning the transaction
199218 :return: new :class:`.Transaction` instance.
219+ :raise: :class:`.TransactionError` if a transaction is already open
200220 """
201221 if self .transaction :
202222 raise TransactionError ("Explicit transaction already open" )
@@ -208,11 +228,20 @@ def clear_transaction():
208228 return self .transaction
209229
210230 def commit_transaction (self ):
231+ """ Commit the current transaction.
232+
233+ :return: the bookmark returned from the server, if any
234+ :raise: :class:`.TransactionError` if no transaction is currently open
235+ """
211236 if not self .transaction :
212237 raise TransactionError ("No transaction to commit" )
213238 self .transaction = None
214239
215240 def rollback_transaction (self ):
241+ """ Rollback the current transaction.
242+
243+ :raise: :class:`.TransactionError` if no transaction is currently open
244+ """
216245 if not self .transaction :
217246 raise TransactionError ("No transaction to rollback" )
218247 self .transaction = None
0 commit comments