Created
September 4, 2019 08:28
-
-
Save giasuddin90/a8312e6bd1d1720eed3c297e381247e7 to your computer and use it in GitHub Desktop.
python Cassandra connection by using python Cassandra driver and cqlengine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'giasuddin' | |
| from cassandra.cqlengine.connection import setup | |
| from cassandra.cluster import Cluster | |
| from cassandra.auth import PlainTextAuthProvider | |
| from cassandra.query import dict_factory | |
| from cassandra.cqlengine import connection | |
| from cassandra.policies import RoundRobinPolicy | |
| def connect(keyspace = "test_keyspace"): | |
| """ | |
| python cassandra connection by using python cassandra driver and cqlengine. | |
| """ | |
| auth_provider = PlainTextAuthProvider(username="cassandra", password="cassandra") | |
| if connection.session is not None: | |
| print('\n Already connected ') | |
| else: | |
| print('\n New connection established ......................\n') | |
| setup(["127.0.0.1"], keyspace, auth_provider=auth_provider, protocol_version=4, load_balancing_policy=RoundRobinPolicy()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment