Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
cassandra.protocol
- Protocol Features¶Native protocol version 4+ allows for a custom payload to be sent between clients and custom query handlers. The payload is specified as a string:binary_type dict holding custom key/value pairs.
By default these are ignored by the server. They can be useful for servers implementing a custom QueryHandler.
See Session.execute()
, :Session.execute_async()
, ResponseFuture.custom_payload
.
_ProtocolHander handles encoding and decoding messages.
This class can be specialized to compose Handlers which implement alternative
result decoding or type deserialization. Class definitions are passed to cassandra.cluster.Cluster
on initialization.
Contracted class methods are _ProtocolHandler.encode_message()
and _ProtocolHandler.decode_message()
.
Encodes a message using the specified frame parameters, and compressor
msg – the message, typically of cassandra.protocol._MessageType, generated by the driver
stream_id – protocol stream id for the frame header
protocol_version – version for the frame header, and used encoding contents
compressor – optional compression function to be used on the body
Decodes a native protocol message body
protocol_version – version to use decoding contents
user_type_map – map[keyspace name] = map[type name] = custom type to instantiate when deserializing this type
stream_id – native protocol stream id from the frame header
flags – native protocol flags bitmap from the header
opcode – native protocol opcode from the header
body – frame body
decompressor – optional decompression function to inflate the body
a message decoded from the body and frame attributes
When python-driver is compiled with Cython, it uses a Cython-based deserialization path
to deserialize messages. By default, the driver will use a Cython-based parser that returns
lists of rows similar to the pure-Python version. In addition, there are two additional
ProtocolHandler classes that can be used to deserialize response messages: LazyProtocolHandler
and NumpyProtocolHandler
. They can be used as follows:
from cassandra.protocol import NumpyProtocolHandler, LazyProtocolHandler
from cassandra.query import tuple_factory
s.client_protocol_handler = LazyProtocolHandler # for a result iterator
s.row_factory = tuple_factory #required for Numpy results
s.client_protocol_handler = NumpyProtocolHandler # for a dict of NumPy arrays as result
These protocol handlers comprise different parsers, and return results as described below:
ProtocolHandler: this default implementation is a drop-in replacement for the pure-Python version. The rows are all parsed upfront, before results are returned.
LazyProtocolHandler: near drop-in replacement for the above, except that it returns an iterator over rows, lazily decoded into the default row format (this is more efficient since all decoded results are not materialized at once)
NumpyProtocolHander: deserializes results directly into NumPy arrays. This facilitates efficient integration with analysis toolkits such as Pandas.
Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
cassandra
- Exceptions and Enumscassandra.cluster
- Clusters and Sessionscassandra.policies
- Load balancing and Failure Handling Policiescassandra.auth
- Authenticationcassandra.metadata
- Schema and Ring Topologycassandra.metrics
- Performance Metricscassandra.query
- Prepared Statements, Batch Statements, Tracing, and Row Factoriescassandra.pool
- Hosts and Connection Poolscassandra.protocol
- Protocol Featurescassandra.encoder
- Encoders for non-prepared Statementscassandra.decoder
- Data Return Formatscassandra.concurrent
- Utilities for Concurrent Statement Executioncassandra.connection
- Low Level Connection Infocassandra.util
- Utilitiescassandra.timestamps
- Timestamp Generationcassandra.io.asyncioreactor
- asyncio
Event Loopcassandra.io.asyncorereactor
- asyncore
Event Loopcassandra.io.eventletreactor
- eventlet
-compatible Connectioncassandra.io.libevreactor
- libev
Event Loopcassandra.io.geventreactor
- gevent
-compatible Event Loopcassandra.io.twistedreactor
- Twisted Event Loopcassandra.cqlengine.models
- Table models for object mappingcassandra.cqlengine.columns
- Column types for object mapping modelscassandra.cqlengine.query
- Query and filter model objectscassandra.cqlengine.connection
- Connection management for cqlenginecassandra.cqlengine.management
- Schema management for cqlenginecassandra.cqlengine.usertype
- Model classes for User Defined Types