Cassandra#

  • A production grade NoSQL database.

  • Can be distributed across servers, nodes, etc.

  • Replication of database is supported for high degree of redundancy and speed.

  • Uses CQL, a subset of SQL for querying.

  • Works seamlesly together with Spark and its corresponding distributed structure.

  • Installation of Cassandra is explained in the Installation chapter.

Spinning up a local Cassandra instance#

In a terminal, first time:
docker run --name my_cassandra -p 9042:9042 cassandra:latest
… and later:
docker start my_cassandra

… or in Docker Desktop:

  • Run the cassandra docker image with optional settings, opening 9042 port and setting a name.

  • Later, simply run the container with the name you chose.

https://github.com/khliland/IND320/blob/main/D2Dbook/images/Docker_images.png?raw=TRUE https://github.com/khliland/IND320/blob/main/D2Dbook/images/Docker_containers.png?raw=TRUE

Connect to the Cassandra cluster from Python.#

# Connecting to Cassandra
from cassandra.cluster import Cluster
cluster = Cluster(['localhost'], port=9042)
session = cluster.connect()

Keyspace#

  • In Cassandra database tables are stored in keyspaces (basically a distributed database).

  • These have parameters controlling their distribution on nodes/servers and redundancy.

  • We will use the simplest form locally.

# Set up new keyspace (first time only)
#                                              name of keyspace                        replication strategy           replication factor
session.execute("CREATE KEYSPACE IF NOT EXISTS my_first_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };")
<cassandra.cluster.ResultSet at 0x111d5dca0>

Create a table#

  • IF NOT EXISTS makes sure we do not overwrite existing tables

# Create a new table (first time only)
session.set_keyspace('my_first_keyspace')
session.execute("DROP TABLE IF EXISTS my_first_keyspace.my_first_table;") # Starting from scratch every time
session.execute("CREATE TABLE IF NOT EXISTS my_first_table (ind int PRIMARY KEY, company text, model text);")
<cassandra.cluster.ResultSet at 0x11273ea50>

Inserting and reading data#

# Insert some data (ind is the primary key, must be unique)
session.execute("INSERT INTO my_first_table (ind, company, model) VALUES (1, 'Tesla', 'Model S');")
session.execute("INSERT INTO my_first_table (ind, company, model) VALUES (2, 'Tesla', 'Model 3');")
session.execute("INSERT INTO my_first_table (ind, company, model) VALUES (3, 'Polestar', '3');")
<cassandra.cluster.ResultSet at 0x11273f8c0>
# Query the data
rows = session.execute("SELECT * FROM my_first_table;")
for i in rows:
    print(i)
Row(ind=1, company='Tesla', model='Model S')
Row(ind=2, company='Tesla', model='Model 3')
Row(ind=3, company='Polestar', model='3')

Case sensitivity#

  • Cassandra is by default case insensitive in column names.

  • To use column names with capital letters, use double quotation marks both when creating tables and when inserting data.

  • The effect of insensitivity may be surprising.

    • Look carefully at the use of quotation marks and error message below.

session.set_keyspace('my_first_keyspace')
session.execute("DROP TABLE IF EXISTS my_first_keyspace.case_insensitive;") # Starting from scratch every time
session.execute("CREATE TABLE IF NOT EXISTS case_insensitive (Capital int PRIMARY KEY, Letters text, Everywhere text);")
session.execute("DROP TABLE IF EXISTS my_first_keyspace.case_sensitive;") # Starting from scratch every time
session.execute("CREATE TABLE IF NOT EXISTS case_sensitive (\"Capital\" int PRIMARY KEY, \"Letters\" text, \"Everywhere\" text);")
<cassandra.cluster.ResultSet at 0x1127486b0>
session.execute("INSERT INTO case_insensitive (Capital, Letters, Everywhere) VALUES (1, 'Tesla', 'Model S');")
<cassandra.cluster.ResultSet at 0x11273de50>
session.execute("INSERT INTO case_sensitive (Capital, Letters, Everywhere) VALUES (1, 'Tesla', 'Model S');")
---------------------------------------------------------------------------
InvalidRequest                            Traceback (most recent call last)
Cell In[8], line 1
----> 1 session.execute("INSERT INTO case_sensitive (Capital, Letters, Everywhere) VALUES (1, 'Tesla', 'Model S');")

File ~/miniforge3/envs/ind320_25/lib/python3.12/site-packages/cassandra/cluster.py:2677, in Session.execute(self, query, parameters, timeout, trace, custom_payload, execution_profile, paging_state, host, execute_as)
   2634 def execute(self, query, parameters=None, timeout=_NOT_SET, trace=False,
   2635             custom_payload=None, execution_profile=EXEC_PROFILE_DEFAULT,
   2636             paging_state=None, host=None, execute_as=None):
   2637     """
   2638     Execute the given query and synchronously wait for the response.
   2639 
   (...)   2674     on a DSE cluster.
   2675     """
-> 2677     return self.execute_async(query, parameters, trace, custom_payload, timeout, execution_profile, paging_state, host, execute_as).result()

File ~/miniforge3/envs/ind320_25/lib/python3.12/site-packages/cassandra/cluster.py:4956, in ResponseFuture.result(self)
   4954     return ResultSet(self, self._final_result)
   4955 else:
-> 4956     raise self._final_exception

InvalidRequest: Error from server: code=2200 [Invalid query] message="Undefined column name capital in table my_first_keyspace.case_sensitive"
session.execute("INSERT INTO case_sensitive (\"Capital\", \"Letters\", \"Everywhere\") VALUES (1, 'Tesla', 'Model S');")
<cassandra.cluster.ResultSet at 0x112975a00>
# Query the data
rows = session.execute("SELECT * FROM case_insensitive;")
for i in rows:
    print(i)
rows = session.execute("SELECT * FROM case_sensitive;")
for i in rows:
    print(i)
Row(capital=1, everywhere='Model S', letters='Tesla')
Row(Capital=1, Everywhere='Model S', Letters='Tesla')

Asyncronous writing#

  • If your application is very data intensive, waiting for a response is not productive.

  • Writing asyncronously sends the data but does not pause for reply.

session.execute_async("INSERT INTO my_first_table (ind, company, model) VALUES (5, 'Volkswagen', 'ID.3');")
<ResponseFuture: query='<SimpleStatement query="INSERT INTO my_first_table (ind, company, model) VALUES (5, 'Volkswagen', 'ID.3');", consistency=Not Set>' request_id=63 result=(no result yet) exception=None coordinator_host=None>
# Query the data
rows = session.execute("SELECT * FROM my_first_table;")
for i in rows:
    print(i)
Row(ind=5, company='Volkswagen', model='ID.3')
Row(ind=1, company='Tesla', model='Model S')
Row(ind=2, company='Tesla', model='Model 3')
Row(ind=3, company='Polestar', model='3')
# More specific query
prepared_statement = session.prepare("SELECT * FROM my_first_table WHERE company=? ALLOW FILTERING;")
teslas = session.execute(prepared_statement, ['Tesla'])
for i in teslas:
    print(i)
Row(ind=1, company='Tesla', model='Model S')
Row(ind=2, company='Tesla', model='Model 3')

Cassandra filtering#

Cassandra is inherently a distributed production database. Selecting as above may require downloading all data from a node, then filtering based on the WHERE part (only PRIMARY KEYs are centrally known). Solutions:

  • If the table is small or most of the data will satisfy the query, add ALLOW FILTERING at the end of the query (not recommended if not known).

  • Or make sure the WHERE clause points to one of the keys (see below).

# Create a new table (observe keys)
session.execute("DROP TABLE IF EXISTS my_first_keyspace.car_table;")
session.execute("CREATE TABLE IF NOT EXISTS car_table (company text, model text, PRIMARY KEY(company, model));")
<cassandra.cluster.ResultSet at 0x111d81a60>
# Insert some data (combination of company and model must be unique)
session.execute("INSERT INTO car_table (company, model) VALUES ('Tesla', 'Model S');")
session.execute("INSERT INTO car_table (company, model) VALUES ('Tesla', 'Model 3');")
session.execute("INSERT INTO car_table (company, model) VALUES ('Polestar', '3');")
session.execute("INSERT INTO car_table (company, model) VALUES ('Volkswagen', 'ID.4');")
<cassandra.cluster.ResultSet at 0x112758da0>
# More specific query now works
prepared_statement = session.prepare("SELECT * FROM car_table WHERE company=?;")
teslas = session.execute(prepared_statement, ['Tesla'])
for i in teslas:
    print(i)
Row(company='Tesla', model='Model 3')
Row(company='Tesla', model='Model S')

Partitions#

  • Cassandra databases are usually replicated over different nodes.

  • Data is stored in partitions (subsets) which have local copys.

  • The primary key, e.g., PRIMARY KEY(company, model), is used in partitioning.

    • The first part, e.g., company, is most important.

    • All cars from a company will be located together, aiming for quicker queries.

Unique IDs#

  • In MySQL one could use the attribute AUTO_INCREMENT on integer IDs to automatically make a new unique index when inserting data.

  • This would cause unreasonable overhead in a distributed database.

  • UUIDs are used instead.

    • Universally Unique Identifiers are typically 128-bit random bit sequences with extremely low probability of duplication.

    • Cassandra uses a timeuuid type to combine a timestamp and uuid in one.

# Create a new table (first time only)
session.set_keyspace('my_first_keyspace')
session.execute("DROP TABLE IF EXISTS my_first_keyspace.table_with_uuid;")
session.execute("CREATE TABLE IF NOT EXISTS table_with_uuid (id timeuuid PRIMARY KEY, company text, model text, price float);")
<cassandra.cluster.ResultSet at 0x11216b5f0>
session.execute("INSERT INTO table_with_uuid (id, company, model, price) VALUES (now(), 'Tesla', 'Model S', 20000.0);")
session.execute("INSERT INTO table_with_uuid (id, company, model, price) VALUES (now(), 'Tesla', 'Model S', 21000.0);")
session.execute("INSERT INTO table_with_uuid (id, company, model, price) VALUES (now(), 'Oldsmobile', 'Model 6C', 135000.0);")
<cassandra.cluster.ResultSet at 0x112974260>
from cassandra.util import datetime_from_uuid1

# Query the data
rows = session.execute("SELECT * FROM table_with_uuid;")
for i in rows:
    print(i)
    # Extract the timestamp from Cassandra's timeuuid
    print("Datetime:", datetime_from_uuid1(i.id))
Row(id=UUID('b2a46ae0-bf1a-11f0-bea5-d1179fc4fe74'), company='Tesla', model='Model S', price=21000.0)
Datetime: 2025-11-11 16:23:03.566000
Row(id=UUID('b2a3f5b0-bf1a-11f0-bea5-d1179fc4fe74'), company='Tesla', model='Model S', price=20000.0)
Datetime: 2025-11-11 16:23:03.563000
Row(id=UUID('b2a4e010-bf1a-11f0-bea5-d1179fc4fe74'), company='Oldsmobile', model='Model 6C', price=135000.0)
Datetime: 2025-11-11 16:23:03.569000

JSON in Cassandra#

Read previously saved JSON file forecast.json to memory#

import json
with open('../3_APIs/downloads/forecast.json', 'r') as f:
    forecast = json.load(f)
# Inspect JSON file
forecast.__str__()
"{'cod': '200', 'message': 0, 'cnt': 40, 'list': [{'dt': 1762376400, 'main': {'temp': 294.4, 'feels_like': 294.3, 'temp_min': 293.81, 'temp_max': 294.4, 'pressure': 1019, 'sea_level': 1019, 'grnd_level': 1002, 'humidity': 66, 'temp_kf': 0.59}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.79, 'deg': 323, 'gust': 3.28}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-05 21:00:00'}, {'dt': 1762387200, 'main': {'temp': 293.98, 'feels_like': 293.87, 'temp_min': 293.15, 'temp_max': 293.98, 'pressure': 1019, 'sea_level': 1019, 'grnd_level': 1001, 'humidity': 67, 'temp_kf': 0.83}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.09, 'deg': 96, 'gust': 1.91}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 00:00:00'}, {'dt': 1762398000, 'main': {'temp': 292.75, 'feels_like': 292.59, 'temp_min': 291.93, 'temp_max': 292.75, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 1000, 'humidity': 70, 'temp_kf': 0.82}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.95, 'deg': 79, 'gust': 1.76}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 03:00:00'}, {'dt': 1762408800, 'main': {'temp': 291.19, 'feels_like': 291.14, 'temp_min': 291.19, 'temp_max': 291.19, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 17}, 'wind': {'speed': 2.32, 'deg': 110, 'gust': 1.79}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 06:00:00'}, {'dt': 1762419600, 'main': {'temp': 292.82, 'feels_like': 292.8, 'temp_min': 292.82, 'temp_max': 292.82, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 1001, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 63}, 'wind': {'speed': 1.7, 'deg': 136, 'gust': 1.28}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 09:00:00'}, {'dt': 1762430400, 'main': {'temp': 294.87, 'feels_like': 294.85, 'temp_min': 294.87, 'temp_max': 294.87, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 54}, 'wind': {'speed': 3.54, 'deg': 269, 'gust': 2.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 12:00:00'}, {'dt': 1762441200, 'main': {'temp': 296.16, 'feels_like': 296, 'temp_min': 296.16, 'temp_max': 296.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 95}, 'wind': {'speed': 4.64, 'deg': 288, 'gust': 4.68}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 15:00:00'}, {'dt': 1762452000, 'main': {'temp': 293.77, 'feels_like': 293.58, 'temp_min': 293.77, 'temp_max': 293.77, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 70}, 'wind': {'speed': 3.89, 'deg': 321, 'gust': 5.6}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 18:00:00'}, {'dt': 1762462800, 'main': {'temp': 291.82, 'feels_like': 291.73, 'temp_min': 291.82, 'temp_max': 291.82, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 48}, 'wind': {'speed': 4.65, 'deg': 106, 'gust': 4.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 21:00:00'}, {'dt': 1762473600, 'main': {'temp': 290.08, 'feels_like': 290.05, 'temp_min': 290.08, 'temp_max': 290.08, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 30}, 'wind': {'speed': 3.9, 'deg': 112, 'gust': 3.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 00:00:00'}, {'dt': 1762484400, 'main': {'temp': 289.5, 'feels_like': 289.36, 'temp_min': 289.5, 'temp_max': 289.5, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 20}, 'wind': {'speed': 2.26, 'deg': 87, 'gust': 2.33}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 03:00:00'}, {'dt': 1762495200, 'main': {'temp': 289.26, 'feels_like': 289.07, 'temp_min': 289.26, 'temp_max': 289.26, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 20}, 'wind': {'speed': 0.83, 'deg': 44, 'gust': 1.69}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 06:00:00'}, {'dt': 1762506000, 'main': {'temp': 290.86, 'feels_like': 290.67, 'temp_min': 290.86, 'temp_max': 290.86, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 74}, 'wind': {'speed': 1.45, 'deg': 168, 'gust': 1.03}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 09:00:00'}, {'dt': 1762516800, 'main': {'temp': 293.06, 'feels_like': 292.78, 'temp_min': 293.06, 'temp_max': 293.06, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 64, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 44}, 'wind': {'speed': 2.92, 'deg': 242, 'gust': 1.88}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 12:00:00'}, {'dt': 1762527600, 'main': {'temp': 294.44, 'feels_like': 294.14, 'temp_min': 294.44, 'temp_max': 294.44, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 58, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 71}, 'wind': {'speed': 2.06, 'deg': 203, 'gust': 2.17}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 15:00:00'}, {'dt': 1762538400, 'main': {'temp': 292.53, 'feels_like': 292.3, 'temp_min': 292.53, 'temp_max': 292.53, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 996, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 43}, 'wind': {'speed': 3.29, 'deg': 130, 'gust': 1.1}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 18:00:00'}, {'dt': 1762549200, 'main': {'temp': 291.41, 'feels_like': 291.2, 'temp_min': 291.41, 'temp_max': 291.41, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.46, 'deg': 129, 'gust': 4.27}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 21:00:00'}, {'dt': 1762560000, 'main': {'temp': 290.21, 'feels_like': 290.01, 'temp_min': 290.21, 'temp_max': 290.21, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.66, 'deg': 148, 'gust': 1.6}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 00:00:00'}, {'dt': 1762570800, 'main': {'temp': 289.96, 'feels_like': 289.6, 'temp_min': 289.96, 'temp_max': 289.96, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.43, 'deg': 237, 'gust': 0.86}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 03:00:00'}, {'dt': 1762581600, 'main': {'temp': 289.68, 'feels_like': 289.4, 'temp_min': 289.68, 'temp_max': 289.68, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.3, 'deg': 245, 'gust': 0.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 06:00:00'}, {'dt': 1762592400, 'main': {'temp': 292.02, 'feels_like': 291.79, 'temp_min': 292.02, 'temp_max': 292.02, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 70, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.67, 'deg': 165, 'gust': 1.92}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 09:00:00'}, {'dt': 1762603200, 'main': {'temp': 294.7, 'feels_like': 294.5, 'temp_min': 294.7, 'temp_max': 294.7, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.2, 'deg': 255, 'gust': 2.58}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 12:00:00'}, {'dt': 1762614000, 'main': {'temp': 295.15, 'feels_like': 294.89, 'temp_min': 295.15, 'temp_max': 295.15, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.77, 'deg': 263, 'gust': 4.25}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 15:00:00'}, {'dt': 1762624800, 'main': {'temp': 291.8, 'feels_like': 291.68, 'temp_min': 291.8, 'temp_max': 291.8, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.12, 'deg': 179, 'gust': 2.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 18:00:00'}, {'dt': 1762635600, 'main': {'temp': 292.1, 'feels_like': 291.85, 'temp_min': 292.1, 'temp_max': 292.1, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.52, 'deg': 112, 'gust': 5.38}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 21:00:00'}, {'dt': 1762646400, 'main': {'temp': 292.54, 'feels_like': 292.1, 'temp_min': 292.54, 'temp_max': 292.54, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 60, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.29, 'deg': 111, 'gust': 4.78}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 00:00:00'}, {'dt': 1762657200, 'main': {'temp': 291.16, 'feels_like': 290.84, 'temp_min': 291.16, 'temp_max': 291.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 70, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 2.38, 'deg': 299, 'gust': 2.49}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 03:00:00'}, {'dt': 1762668000, 'main': {'temp': 290.81, 'feels_like': 290.64, 'temp_min': 290.81, 'temp_max': 290.81, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 2.51, 'deg': 285, 'gust': 2.63}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 06:00:00'}, {'dt': 1762678800, 'main': {'temp': 292.42, 'feels_like': 292.39, 'temp_min': 292.42, 'temp_max': 292.42, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 2.21, 'deg': 243, 'gust': 2.19}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 09:00:00'}, {'dt': 1762689600, 'main': {'temp': 294.11, 'feels_like': 294.06, 'temp_min': 294.11, 'temp_max': 294.11, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 26}, 'wind': {'speed': 2.45, 'deg': 225, 'gust': 2.29}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 12:00:00'}, {'dt': 1762700400, 'main': {'temp': 295.35, 'feels_like': 295.17, 'temp_min': 295.35, 'temp_max': 295.35, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 59, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.9, 'deg': 270, 'gust': 4.52}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 15:00:00'}, {'dt': 1762711200, 'main': {'temp': 293.13, 'feels_like': 292.91, 'temp_min': 293.13, 'temp_max': 293.13, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 66, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 2, 'deg': 244, 'gust': 1.96}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 18:00:00'}, {'dt': 1762722000, 'main': {'temp': 292.32, 'feels_like': 292.22, 'temp_min': 292.32, 'temp_max': 292.32, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.73, 'deg': 136, 'gust': 3.08}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 21:00:00'}, {'dt': 1762732800, 'main': {'temp': 291.81, 'feels_like': 291.69, 'temp_min': 291.81, 'temp_max': 291.81, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.66, 'deg': 122, 'gust': 5.08}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 00:00:00'}, {'dt': 1762743600, 'main': {'temp': 291.21, 'feels_like': 290.98, 'temp_min': 291.21, 'temp_max': 291.21, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 99}, 'wind': {'speed': 0.31, 'deg': 212, 'gust': 1.45}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 03:00:00'}, {'dt': 1762754400, 'main': {'temp': 290.48, 'feels_like': 290.33, 'temp_min': 290.48, 'temp_max': 290.48, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 93}, 'wind': {'speed': 1.9, 'deg': 285, 'gust': 1.72}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 06:00:00'}, {'dt': 1762765200, 'main': {'temp': 292.9, 'feels_like': 292.71, 'temp_min': 292.9, 'temp_max': 292.9, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.83, 'deg': 229, 'gust': 0.87}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 09:00:00'}, {'dt': 1762776000, 'main': {'temp': 294.17, 'feels_like': 293.95, 'temp_min': 294.17, 'temp_max': 294.17, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 62, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 1}, 'wind': {'speed': 3.04, 'deg': 230, 'gust': 0.96}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 12:00:00'}, {'dt': 1762786800, 'main': {'temp': 295.55, 'feels_like': 295.31, 'temp_min': 295.55, 'temp_max': 295.55, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 56, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.41, 'deg': 260, 'gust': 2.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 15:00:00'}, {'dt': 1762797600, 'main': {'temp': 292.58, 'feels_like': 292.46, 'temp_min': 292.58, 'temp_max': 292.58, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 1.01, 'deg': 184, 'gust': 1.63}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 18:00:00'}], 'city': {'id': 2561668, 'name': 'Agadir', 'coord': {'lat': 30.4202, 'lon': -9.5982}, 'country': 'MA', 'population': 698310, 'timezone': 3600, 'sunrise': 1762325761, 'sunset': 1762364876}}"

Raw JSON#

  • A simple, but not very efficient way of storing JSON data is to treat it as a text and save it directly to the database.

  • More efficient, with regard to transfer, is to compress the JSON data to a blob first.

    • Compression is automatic.

# Create a new table which treats the whole JSON as a blob, using the city id and the first dt as keys
session.set_keyspace('my_first_keyspace')
session.execute("DROP TABLE IF EXISTS my_first_keyspace.forecast_table;")
session.execute("CREATE TABLE IF NOT EXISTS forecast_table (city_id int, dt int, forecast blob, PRIMARY KEY(city_id, dt));")
<cassandra.cluster.ResultSet at 0x111600680>

Insert the forecast data into the table as text blob#

session.execute("INSERT INTO forecast_table (city_id, dt, forecast) VALUES (%s, %s, textAsBlob(%s));", (forecast['city']['id'], forecast['list'][0]['dt'], forecast.__str__()))
<cassandra.cluster.ResultSet at 0x11273f770>
# Query the data
forecast_rows = session.execute("SELECT * FROM forecast_table;")
print(forecast_rows.one()) # <- only one row
Row(city_id=2561668, dt=1762376400, forecast=b"{'cod': '200', 'message': 0, 'cnt': 40, 'list': [{'dt': 1762376400, 'main': {'temp': 294.4, 'feels_like': 294.3, 'temp_min': 293.81, 'temp_max': 294.4, 'pressure': 1019, 'sea_level': 1019, 'grnd_level': 1002, 'humidity': 66, 'temp_kf': 0.59}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.79, 'deg': 323, 'gust': 3.28}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-05 21:00:00'}, {'dt': 1762387200, 'main': {'temp': 293.98, 'feels_like': 293.87, 'temp_min': 293.15, 'temp_max': 293.98, 'pressure': 1019, 'sea_level': 1019, 'grnd_level': 1001, 'humidity': 67, 'temp_kf': 0.83}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.09, 'deg': 96, 'gust': 1.91}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 00:00:00'}, {'dt': 1762398000, 'main': {'temp': 292.75, 'feels_like': 292.59, 'temp_min': 291.93, 'temp_max': 292.75, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 1000, 'humidity': 70, 'temp_kf': 0.82}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.95, 'deg': 79, 'gust': 1.76}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 03:00:00'}, {'dt': 1762408800, 'main': {'temp': 291.19, 'feels_like': 291.14, 'temp_min': 291.19, 'temp_max': 291.19, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 17}, 'wind': {'speed': 2.32, 'deg': 110, 'gust': 1.79}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 06:00:00'}, {'dt': 1762419600, 'main': {'temp': 292.82, 'feels_like': 292.8, 'temp_min': 292.82, 'temp_max': 292.82, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 1001, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 63}, 'wind': {'speed': 1.7, 'deg': 136, 'gust': 1.28}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 09:00:00'}, {'dt': 1762430400, 'main': {'temp': 294.87, 'feels_like': 294.85, 'temp_min': 294.87, 'temp_max': 294.87, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 54}, 'wind': {'speed': 3.54, 'deg': 269, 'gust': 2.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 12:00:00'}, {'dt': 1762441200, 'main': {'temp': 296.16, 'feels_like': 296, 'temp_min': 296.16, 'temp_max': 296.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 95}, 'wind': {'speed': 4.64, 'deg': 288, 'gust': 4.68}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-06 15:00:00'}, {'dt': 1762452000, 'main': {'temp': 293.77, 'feels_like': 293.58, 'temp_min': 293.77, 'temp_max': 293.77, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 70}, 'wind': {'speed': 3.89, 'deg': 321, 'gust': 5.6}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 18:00:00'}, {'dt': 1762462800, 'main': {'temp': 291.82, 'feels_like': 291.73, 'temp_min': 291.82, 'temp_max': 291.82, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 48}, 'wind': {'speed': 4.65, 'deg': 106, 'gust': 4.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-06 21:00:00'}, {'dt': 1762473600, 'main': {'temp': 290.08, 'feels_like': 290.05, 'temp_min': 290.08, 'temp_max': 290.08, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 30}, 'wind': {'speed': 3.9, 'deg': 112, 'gust': 3.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 00:00:00'}, {'dt': 1762484400, 'main': {'temp': 289.5, 'feels_like': 289.36, 'temp_min': 289.5, 'temp_max': 289.5, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 20}, 'wind': {'speed': 2.26, 'deg': 87, 'gust': 2.33}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 03:00:00'}, {'dt': 1762495200, 'main': {'temp': 289.26, 'feels_like': 289.07, 'temp_min': 289.26, 'temp_max': 289.26, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 801, 'main': 'Clouds', 'description': 'few clouds', 'icon': '02n'}], 'clouds': {'all': 20}, 'wind': {'speed': 0.83, 'deg': 44, 'gust': 1.69}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 06:00:00'}, {'dt': 1762506000, 'main': {'temp': 290.86, 'feels_like': 290.67, 'temp_min': 290.86, 'temp_max': 290.86, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 74}, 'wind': {'speed': 1.45, 'deg': 168, 'gust': 1.03}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 09:00:00'}, {'dt': 1762516800, 'main': {'temp': 293.06, 'feels_like': 292.78, 'temp_min': 293.06, 'temp_max': 293.06, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 64, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 44}, 'wind': {'speed': 2.92, 'deg': 242, 'gust': 1.88}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 12:00:00'}, {'dt': 1762527600, 'main': {'temp': 294.44, 'feels_like': 294.14, 'temp_min': 294.44, 'temp_max': 294.44, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 58, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 71}, 'wind': {'speed': 2.06, 'deg': 203, 'gust': 2.17}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-07 15:00:00'}, {'dt': 1762538400, 'main': {'temp': 292.53, 'feels_like': 292.3, 'temp_min': 292.53, 'temp_max': 292.53, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 996, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 43}, 'wind': {'speed': 3.29, 'deg': 130, 'gust': 1.1}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 18:00:00'}, {'dt': 1762549200, 'main': {'temp': 291.41, 'feels_like': 291.2, 'temp_min': 291.41, 'temp_max': 291.41, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.46, 'deg': 129, 'gust': 4.27}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-07 21:00:00'}, {'dt': 1762560000, 'main': {'temp': 290.21, 'feels_like': 290.01, 'temp_min': 290.21, 'temp_max': 290.21, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.66, 'deg': 148, 'gust': 1.6}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 00:00:00'}, {'dt': 1762570800, 'main': {'temp': 289.96, 'feels_like': 289.6, 'temp_min': 289.96, 'temp_max': 289.96, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.43, 'deg': 237, 'gust': 0.86}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 03:00:00'}, {'dt': 1762581600, 'main': {'temp': 289.68, 'feels_like': 289.4, 'temp_min': 289.68, 'temp_max': 289.68, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.3, 'deg': 245, 'gust': 0.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 06:00:00'}, {'dt': 1762592400, 'main': {'temp': 292.02, 'feels_like': 291.79, 'temp_min': 292.02, 'temp_max': 292.02, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 70, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.67, 'deg': 165, 'gust': 1.92}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 09:00:00'}, {'dt': 1762603200, 'main': {'temp': 294.7, 'feels_like': 294.5, 'temp_min': 294.7, 'temp_max': 294.7, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.2, 'deg': 255, 'gust': 2.58}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 12:00:00'}, {'dt': 1762614000, 'main': {'temp': 295.15, 'feels_like': 294.89, 'temp_min': 295.15, 'temp_max': 295.15, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.77, 'deg': 263, 'gust': 4.25}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-08 15:00:00'}, {'dt': 1762624800, 'main': {'temp': 291.8, 'feels_like': 291.68, 'temp_min': 291.8, 'temp_max': 291.8, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.12, 'deg': 179, 'gust': 2.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 18:00:00'}, {'dt': 1762635600, 'main': {'temp': 292.1, 'feels_like': 291.85, 'temp_min': 292.1, 'temp_max': 292.1, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.52, 'deg': 112, 'gust': 5.38}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-08 21:00:00'}, {'dt': 1762646400, 'main': {'temp': 292.54, 'feels_like': 292.1, 'temp_min': 292.54, 'temp_max': 292.54, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 60, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 4.29, 'deg': 111, 'gust': 4.78}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 00:00:00'}, {'dt': 1762657200, 'main': {'temp': 291.16, 'feels_like': 290.84, 'temp_min': 291.16, 'temp_max': 291.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 70, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 2.38, 'deg': 299, 'gust': 2.49}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 03:00:00'}, {'dt': 1762668000, 'main': {'temp': 290.81, 'feels_like': 290.64, 'temp_min': 290.81, 'temp_max': 290.81, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 2.51, 'deg': 285, 'gust': 2.63}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 06:00:00'}, {'dt': 1762678800, 'main': {'temp': 292.42, 'feels_like': 292.39, 'temp_min': 292.42, 'temp_max': 292.42, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 76, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 2.21, 'deg': 243, 'gust': 2.19}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 09:00:00'}, {'dt': 1762689600, 'main': {'temp': 294.11, 'feels_like': 294.06, 'temp_min': 294.11, 'temp_max': 294.11, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 26}, 'wind': {'speed': 2.45, 'deg': 225, 'gust': 2.29}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 12:00:00'}, {'dt': 1762700400, 'main': {'temp': 295.35, 'feels_like': 295.17, 'temp_min': 295.35, 'temp_max': 295.35, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 59, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.9, 'deg': 270, 'gust': 4.52}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-09 15:00:00'}, {'dt': 1762711200, 'main': {'temp': 293.13, 'feels_like': 292.91, 'temp_min': 293.13, 'temp_max': 293.13, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 66, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 2, 'deg': 244, 'gust': 1.96}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 18:00:00'}, {'dt': 1762722000, 'main': {'temp': 292.32, 'feels_like': 292.22, 'temp_min': 292.32, 'temp_max': 292.32, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.73, 'deg': 136, 'gust': 3.08}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-09 21:00:00'}, {'dt': 1762732800, 'main': {'temp': 291.81, 'feels_like': 291.69, 'temp_min': 291.81, 'temp_max': 291.81, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 75, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.66, 'deg': 122, 'gust': 5.08}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 00:00:00'}, {'dt': 1762743600, 'main': {'temp': 291.21, 'feels_like': 290.98, 'temp_min': 291.21, 'temp_max': 291.21, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 73, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 99}, 'wind': {'speed': 0.31, 'deg': 212, 'gust': 1.45}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 03:00:00'}, {'dt': 1762754400, 'main': {'temp': 290.48, 'feels_like': 290.33, 'temp_min': 290.48, 'temp_max': 290.48, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 93}, 'wind': {'speed': 1.9, 'deg': 285, 'gust': 1.72}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 06:00:00'}, {'dt': 1762765200, 'main': {'temp': 292.9, 'feels_like': 292.71, 'temp_min': 292.9, 'temp_max': 292.9, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 1000, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 2}, 'wind': {'speed': 1.83, 'deg': 229, 'gust': 0.87}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 09:00:00'}, {'dt': 1762776000, 'main': {'temp': 294.17, 'feels_like': 293.95, 'temp_min': 294.17, 'temp_max': 294.17, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 62, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 1}, 'wind': {'speed': 3.04, 'deg': 230, 'gust': 0.96}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 12:00:00'}, {'dt': 1762786800, 'main': {'temp': 295.55, 'feels_like': 295.31, 'temp_min': 295.55, 'temp_max': 295.55, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 56, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.41, 'deg': 260, 'gust': 2.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-11-10 15:00:00'}, {'dt': 1762797600, 'main': {'temp': 292.58, 'feels_like': 292.46, 'temp_min': 292.58, 'temp_max': 292.58, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 1.01, 'deg': 184, 'gust': 1.63}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-11-10 18:00:00'}], 'city': {'id': 2561668, 'name': 'Agadir', 'coord': {'lat': 30.4202, 'lon': -9.5982}, 'country': 'MA', 'population': 698310, 'timezone': 3600, 'sunrise': 1762325761, 'sunset': 1762364876}}")