Python and Apache Cassandr for Beginners

 

Learn how to connect Python to Cassandra and insert data with the Datastax ODBC driver, and use the Astra web console to query data.


Getting Started with Python

Installing Python

python --version
Python 3.8.2

Installing Python Dependencies

cassandra-driver==3.25.0
numpy==1.19.3
astrapy==0.0.2
simplejson==3.17.2
pip install -r requirements.txt

What is Cassandra?

Setting up a Cassandra database

Using astrapy to generate JSON and insert to Astra

Setting up connection from Python to Astra using a driver

How to create a Cassandra Table in Astra

git clone git@github.com:andyadamides/python-cassandra-intro.git
if __name__ == “__main__”:
main()
def main():
“””The main routine.”””
session = getDBSession()
generateDataEntrypoint(session)
session.execute(insert_query, [device_id, t_id, value_ts, t_pub_ts, round(random.choice(readings),2)])
python main.py
Processing:130483SuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccessProcessing:176990SuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccessSuccess
select * from cassandra_pythondemo.demo_readings;

Conclusion



Comments

Popular posts from this blog

Flutter for Single-Page Scrollable Websites with Navigator 2.0

A Data Science Portfolio is More Valuable than a Resume

Better File Storage in Oracle Cloud