Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

12/12/2019

Reading time:N/A min

TerbiumLabs/flask-cassandra

by TerbiumLabs

Flask-Cassandra provides an application-level connection to an Apache Cassandra database. This connection can be used to interact with a Cassandra cluster.Flask-Cassandra requires both Flask and the Datastax Python Driver for Apache Cassandra to be installed. This driver will be installed automatically when installing via pip or when running setup.py install.InstallationThe easiest way to use the extension is to install it from PyPI using pip:$ pip install flask-cassandraYou can also install the extension directly from source.$ python setup.py installUseThis is an example flask app that reads from a Cassandra cluster.from flask import Flaskfrom flask_cassandra import CassandraClusterapp = Flask(__name__)cassandra = CassandraCluster()app.config['CASSANDRA_NODES'] = ['cassandra-c1.terbiumlabs.com'] # can be a string or list of nodes@app.route("/cassandra_test")def cassandra_test(): session = cassandra.connect() session.set_keyspace("monty_python") cql = "SELECT * FROM sketches LIMIT 1" r = session.execute(cql) return str(r[0])if __name__ == '__main__': app.run()ContributionsIf you would like to extend the functionality of the extension, pull requests are most welcome.

Illustration Image

Flask-Cassandra provides an application-level connection to an Apache Cassandra database. This connection can be used to interact with a Cassandra cluster.

Flask-Cassandra requires both Flask and the Datastax Python Driver for Apache Cassandra to be installed. This driver will be installed automatically when installing via pip or when running setup.py install.

Installation

The easiest way to use the extension is to install it from PyPI using pip:

$ pip install flask-cassandra

You can also install the extension directly from source.

$ python setup.py install

Use

This is an example flask app that reads from a Cassandra cluster.

from flask import Flask
from flask_cassandra import CassandraCluster
app = Flask(__name__)
cassandra = CassandraCluster()
app.config['CASSANDRA_NODES'] = ['cassandra-c1.terbiumlabs.com']  # can be a string or list of nodes
@app.route("/cassandra_test")
def cassandra_test():
    session = cassandra.connect()
    session.set_keyspace("monty_python")
    cql = "SELECT * FROM sketches LIMIT 1"
    r = session.execute(cql)
    return str(r[0])
if __name__ == '__main__':
    app.run()

Contributions

If you would like to extend the functionality of the extension, pull requests are most welcome.

Related Articles

node
python
astra

GitHub - Anant/Cassandra.Api: Open Source Application for DataStax Astra

Anant

3/7/2024

cassandra
python

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

python