{"id":156,"date":"2024-01-02T17:18:52","date_gmt":"2024-01-02T17:18:52","guid":{"rendered":"https:\/\/feellikelearning.com\/en\/?p=156"},"modified":"2024-01-02T17:18:53","modified_gmt":"2024-01-02T17:18:53","slug":"examples-of-interacting-with-cassandra-or-scylladb-using-python","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/","title":{"rendered":"Examples of Interacting with Cassandra or ScyllaDB using Python"},"content":{"rendered":"\n<p>To interact with Cassandra or ScyllaDB using Python, you can use the <code>cassandra-driver<\/code> library, which works for both databases.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install cassandra-driver<\/code><\/pre>\n\n\n\n<p>The following example demonstrates how to connect to a Cassandra or ScyllaDB cluster, create a keyspace, create a table, and perform basic CRUD (Create, Read, Update, Delete) operations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from cassandra.cluster import Cluster\n\n# Connect to the Cassandra or ScyllaDB cluster\ncluster = Cluster(&#91;'127.0.0.1'])  # Replace with your actual cluster address\nsession = cluster.connect()\n\n# Create a keyspace\nkeyspace_query = \"CREATE KEYSPACE IF NOT EXISTS my_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}\"\nsession.execute(keyspace_query)\n\n# Switch to the keyspace\nsession.set_keyspace('my_keyspace')\n\n# Create a table\ntable_query = \"CREATE TABLE IF NOT EXISTS my_table (id UUID PRIMARY KEY, name TEXT, age INT)\"\nsession.execute(table_query)\n\n# Insert data\ninsert_query = \"INSERT INTO my_table (id, name, age) VALUES (uuid(), 'John Doe', 30)\"\nsession.execute(insert_query)\n\n# Query data\nselect_query = \"SELECT * FROM my_table\"\nresult = session.execute(select_query)\n\nfor row in result:\n    print(f\"ID: {row.id}, Name: {row.name}, Age: {row.age}\")\n\n# Update data\nupdate_query = \"UPDATE my_table SET age = 31 WHERE name = 'John Doe'\"\nsession.execute(update_query)\n\n# Query data after update\nresult = session.execute(select_query)\n\nfor row in result:\n    print(f\"ID: {row.id}, Name: {row.name}, Age: {row.age}\")\n\n# Delete data\ndelete_query = \"DELETE FROM my_table WHERE name = 'John Doe'\"\nsession.execute(delete_query)\n\n# Query data after delete\nresult = session.execute(select_query)\n\nfor row in result:\n    print(f\"ID: {row.id}, Name: {row.name}, Age: {row.age}\")\n\n# Close the session and cluster connection\nsession.shutdown()\ncluster.shutdown()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To interact with Cassandra or ScyllaDB using Python, you can use the cassandra-driver library, which works for both databases. The following example demonstrates how to connect to a Cassandra or ScyllaDB cluster, create a keyspace, create a table, and perform basic CRUD (Create, Read, Update, Delete) operations.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"To interact with Cassandra or ScyllaDB using Python, you can use the cassandra-driver library, which works for both databases. The following example demonstrates how to connect to a Cassandra or ScyllaDB cluster, create a keyspace, create a table, and perform basic CRUD (Create, Read, Update, Delete) operations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-02T17:18:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-02T17:18:53+00:00\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/\",\"url\":\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/\",\"name\":\"Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/en\/#website\"},\"datePublished\":\"2024-01-02T17:18:52+00:00\",\"dateModified\":\"2024-01-02T17:18:53+00:00\",\"author\":{\"@id\":\"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/1ec5aac313d6de20215fe2b8e176b8a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Examples of Interacting with Cassandra or ScyllaDB using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/en\/#website\",\"url\":\"https:\/\/feellikelearning.com\/en\/\",\"name\":\"Feel Like Learning\",\"description\":\"keep curiosity alive\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/1ec5aac313d6de20215fe2b8e176b8a7\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/36aec9d519f02362e3e89b0716ae640d08701f57e818830f3f197db5fbc1ae20?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/36aec9d519f02362e3e89b0716ae640d08701f57e818830f3f197db5fbc1ae20?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"sameAs\":[\"http:\/\/feellikelearning.com\/en\"],\"url\":\"https:\/\/feellikelearning.com\/en\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/","og_locale":"en_US","og_type":"article","og_title":"Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning","og_description":"To interact with Cassandra or ScyllaDB using Python, you can use the cassandra-driver library, which works for both databases. The following example demonstrates how to connect to a Cassandra or ScyllaDB cluster, create a keyspace, create a table, and perform basic CRUD (Create, Read, Update, Delete) operations.","og_url":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/","og_site_name":"Feel Like Learning","article_published_time":"2024-01-02T17:18:52+00:00","article_modified_time":"2024-01-02T17:18:53+00:00","author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/","url":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/","name":"Examples of Interacting with Cassandra or ScyllaDB using Python - Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/en\/#website"},"datePublished":"2024-01-02T17:18:52+00:00","dateModified":"2024-01-02T17:18:53+00:00","author":{"@id":"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/1ec5aac313d6de20215fe2b8e176b8a7"},"breadcrumb":{"@id":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/en\/index.php\/2024\/01\/02\/examples-of-interacting-with-cassandra-or-scylladb-using-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/en\/"},{"@type":"ListItem","position":2,"name":"Examples of Interacting with Cassandra or ScyllaDB using Python"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/en\/#website","url":"https:\/\/feellikelearning.com\/en\/","name":"Feel Like Learning","description":"keep curiosity alive","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/1ec5aac313d6de20215fe2b8e176b8a7","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/36aec9d519f02362e3e89b0716ae640d08701f57e818830f3f197db5fbc1ae20?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/36aec9d519f02362e3e89b0716ae640d08701f57e818830f3f197db5fbc1ae20?s=96&d=mm&r=g","caption":"feellikelearning"},"sameAs":["http:\/\/feellikelearning.com\/en"],"url":"https:\/\/feellikelearning.com\/en\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":1,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/posts\/156\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/en\/index.php\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}