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 0x104f150d0>

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 0x103f599a0>

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 0x105bbfe00>
# 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 0x105bc65d0>
session.execute("INSERT INTO case_insensitive (Capital, Letters, Everywhere) VALUES (1, 'Tesla', 'Model S');")
<cassandra.cluster.ResultSet at 0x104f9fce0>
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 0x105b87ad0>
# 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 0x104f71880>
# 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 0x105fc1cd0>
# 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 0x105f38ce0>
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 0x105bbe180>
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('57546900-a9e5-11f0-8612-ddf39791f163'), company='Tesla', model='Model S', price=21000.0)
Datetime: 2025-10-15 16:38:12.624000
Row(id=UUID('5753f3d0-a9e5-11f0-8612-ddf39791f163'), company='Tesla', model='Model S', price=20000.0)
Datetime: 2025-10-15 16:38:12.621000
Row(id=UUID('57549010-a9e5-11f0-8612-ddf39791f163'), company='Oldsmobile', model='Model 6C', price=135000.0)
Datetime: 2025-10-15 16:38:12.625000

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': 1760551200, 'main': {'temp': 295.58, 'feels_like': 295.65, 'temp_min': 293.93, 'temp_max': 295.58, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 999, 'humidity': 68, 'temp_kf': 1.65}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 59}, 'wind': {'speed': 5.07, 'deg': 294, 'gust': 6.15}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-15 18:00:00'}, {'dt': 1760562000, 'main': {'temp': 293.63, 'feels_like': 293.72, 'temp_min': 292.24, 'temp_max': 293.63, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 76, 'temp_kf': 1.39}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 84}, 'wind': {'speed': 1.03, 'deg': 174, 'gust': 1.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-15 21:00:00'}, {'dt': 1760572800, 'main': {'temp': 292.3, 'feels_like': 292.36, 'temp_min': 292.3, 'temp_max': 292.3, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.82, 'deg': 85, 'gust': 1.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 00:00:00'}, {'dt': 1760583600, 'main': {'temp': 291.66, 'feels_like': 291.58, 'temp_min': 291.66, 'temp_max': 291.66, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 95}, 'wind': {'speed': 0.84, 'deg': 348, 'gust': 1.06}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 03:00:00'}, {'dt': 1760594400, 'main': {'temp': 291.57, 'feels_like': 291.48, 'temp_min': 291.57, 'temp_max': 291.57, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 88}, 'wind': {'speed': 1.13, 'deg': 140, 'gust': 0.77}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 06:00:00'}, {'dt': 1760605200, 'main': {'temp': 292.63, 'feels_like': 292.57, 'temp_min': 292.63, 'temp_max': 292.63, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 79}, 'wind': {'speed': 3.25, 'deg': 158, 'gust': 2.44}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 09:00:00'}, {'dt': 1760616000, 'main': {'temp': 295.26, 'feels_like': 295.12, 'temp_min': 295.26, 'temp_max': 295.26, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 89}, 'wind': {'speed': 2.59, 'deg': 220, 'gust': 1.42}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 12:00:00'}, {'dt': 1760626800, 'main': {'temp': 294.73, 'feels_like': 294.64, 'temp_min': 294.73, 'temp_max': 294.73, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 995, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 89}, 'wind': {'speed': 4.65, 'deg': 268, 'gust': 4.73}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 15:00:00'}, {'dt': 1760637600, 'main': {'temp': 294.47, 'feels_like': 294.35, 'temp_min': 294.47, 'temp_max': 294.47, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 995, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 90}, 'wind': {'speed': 4.19, 'deg': 280, 'gust': 5.79}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 18:00:00'}, {'dt': 1760648400, 'main': {'temp': 292.47, 'feels_like': 292.52, 'temp_min': 292.47, 'temp_max': 292.47, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.02, 'deg': 116, 'gust': 3.65}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 21:00:00'}, {'dt': 1760659200, 'main': {'temp': 291.36, 'feels_like': 291.61, 'temp_min': 291.36, 'temp_max': 291.36, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 91, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.19, 'deg': 117, 'gust': 4.56}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 00:00:00'}, {'dt': 1760670000, 'main': {'temp': 290.9, 'feels_like': 291.08, 'temp_min': 290.9, 'temp_max': 290.9, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 90, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.53, 'deg': 96, 'gust': 1.07}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 03:00:00'}, {'dt': 1760680800, 'main': {'temp': 290.8, 'feels_like': 290.89, 'temp_min': 290.8, 'temp_max': 290.8, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 97}, 'wind': {'speed': 2.05, 'deg': 167, 'gust': 2.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 06:00:00'}, {'dt': 1760691600, 'main': {'temp': 292.06, 'feels_like': 292.1, 'temp_min': 292.06, 'temp_max': 292.06, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 0.52, 'deg': 137, 'gust': 0.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 09:00:00'}, {'dt': 1760702400, 'main': {'temp': 294.29, 'feels_like': 294.31, 'temp_min': 294.29, 'temp_max': 294.29, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 71, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 86}, 'wind': {'speed': 4.53, 'deg': 249, 'gust': 3.09}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 12:00:00'}, {'dt': 1760713200, 'main': {'temp': 295.1, 'feels_like': 295.1, 'temp_min': 295.1, 'temp_max': 295.1, 'pressure': 1010, 'sea_level': 1010, 'grnd_level': 994, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 98}, 'wind': {'speed': 4.76, 'deg': 274, 'gust': 4.66}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 15:00:00'}, {'dt': 1760724000, 'main': {'temp': 294.48, 'feels_like': 294.47, 'temp_min': 294.48, 'temp_max': 294.48, 'pressure': 1010, 'sea_level': 1010, 'grnd_level': 994, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 2.36, 'deg': 286, 'gust': 4.35}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 18:00:00'}, {'dt': 1760734800, 'main': {'temp': 292.17, 'feels_like': 292.35, 'temp_min': 292.17, 'temp_max': 292.17, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.32, 'deg': 121, 'gust': 3.42}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 21:00:00'}, {'dt': 1760745600, 'main': {'temp': 291.79, 'feels_like': 291.9, 'temp_min': 291.79, 'temp_max': 291.79, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.41, 'deg': 110, 'gust': 4.99}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 00:00:00'}, {'dt': 1760756400, 'main': {'temp': 292.28, 'feels_like': 292.29, 'temp_min': 292.28, 'temp_max': 292.28, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 99}, 'wind': {'speed': 1.81, 'deg': 135, 'gust': 1.8}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 03:00:00'}, {'dt': 1760767200, 'main': {'temp': 290.92, 'feels_like': 291.02, 'temp_min': 290.92, 'temp_max': 290.92, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 98}, 'wind': {'speed': 1.66, 'deg': 305, 'gust': 1.66}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 06:00:00'}, {'dt': 1760778000, 'main': {'temp': 293, 'feels_like': 293.05, 'temp_min': 293, 'temp_max': 293, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 80}, 'wind': {'speed': 1.49, 'deg': 243, 'gust': 1.21}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 09:00:00'}, {'dt': 1760788800, 'main': {'temp': 294.5, 'feels_like': 294.57, 'temp_min': 294.5, 'temp_max': 294.5, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 46}, 'wind': {'speed': 3.43, 'deg': 250, 'gust': 2.72}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 12:00:00'}, {'dt': 1760799600, 'main': {'temp': 295.21, 'feels_like': 295.27, 'temp_min': 295.21, 'temp_max': 295.21, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 47}, 'wind': {'speed': 4.74, 'deg': 268, 'gust': 4.53}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 15:00:00'}, {'dt': 1760810400, 'main': {'temp': 294.86, 'feels_like': 294.86, 'temp_min': 294.86, 'temp_max': 294.86, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 65}, 'wind': {'speed': 1.88, 'deg': 246, 'gust': 2.77}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 18:00:00'}, {'dt': 1760821200, 'main': {'temp': 292.66, 'feels_like': 292.78, 'temp_min': 292.66, 'temp_max': 292.66, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 81, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 76}, 'wind': {'speed': 3.03, 'deg': 116, 'gust': 3.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 21:00:00'}, {'dt': 1760832000, 'main': {'temp': 291.74, 'feels_like': 291.85, 'temp_min': 291.74, 'temp_max': 291.74, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 43}, 'wind': {'speed': 4.4, 'deg': 96, 'gust': 4.34}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 00:00:00'}, {'dt': 1760842800, 'main': {'temp': 291.48, 'feels_like': 291.43, 'temp_min': 291.48, 'temp_max': 291.48, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 32}, 'wind': {'speed': 2.17, 'deg': 88, 'gust': 2.12}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 03:00:00'}, {'dt': 1760853600, 'main': {'temp': 291, 'feels_like': 291.01, 'temp_min': 291, 'temp_max': 291, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 30}, 'wind': {'speed': 1.28, 'deg': 345, 'gust': 1.65}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 06:00:00'}, {'dt': 1760864400, 'main': {'temp': 292.99, 'feels_like': 292.96, 'temp_min': 292.99, 'temp_max': 292.99, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 2.19, 'deg': 255, 'gust': 1.75}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 09:00:00'}, {'dt': 1760875200, 'main': {'temp': 294.7, 'feels_like': 294.66, 'temp_min': 294.7, 'temp_max': 294.7, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 4.34, 'deg': 248, 'gust': 2.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 12:00:00'}, {'dt': 1760886000, 'main': {'temp': 297.25, 'feels_like': 297.2, 'temp_min': 297.25, 'temp_max': 297.25, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 996, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 5.17, 'deg': 280, 'gust': 5.67}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 15:00:00'}, {'dt': 1760896800, 'main': {'temp': 295.58, 'feels_like': 295.47, 'temp_min': 295.58, 'temp_max': 295.58, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 7}, 'wind': {'speed': 3.39, 'deg': 318, 'gust': 6.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 18:00:00'}, {'dt': 1760907600, 'main': {'temp': 292.56, 'feels_like': 292.59, 'temp_min': 292.56, 'temp_max': 292.56, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.07, 'deg': 112, 'gust': 2.9}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 21:00:00'}, {'dt': 1760918400, 'main': {'temp': 291.53, 'feels_like': 291.59, 'temp_min': 291.53, 'temp_max': 291.53, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 4.3, 'deg': 99, 'gust': 4.03}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 00:00:00'}, {'dt': 1760929200, 'main': {'temp': 291.28, 'feels_like': 291.19, 'temp_min': 291.28, 'temp_max': 291.28, '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': 5}, 'wind': {'speed': 0.92, 'deg': 72, 'gust': 1.81}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 03:00:00'}, {'dt': 1760940000, 'main': {'temp': 290.69, 'feels_like': 290.69, 'temp_min': 290.69, 'temp_max': 290.69, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 7}, 'wind': {'speed': 1.11, 'deg': 262, 'gust': 1.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 06:00:00'}, {'dt': 1760950800, 'main': {'temp': 292.7, 'feels_like': 292.64, 'temp_min': 292.7, 'temp_max': 292.7, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 63}, 'wind': {'speed': 1.69, 'deg': 246, 'gust': 1.47}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 09:00:00'}, {'dt': 1760961600, 'main': {'temp': 294.16, 'feels_like': 294.12, 'temp_min': 294.16, 'temp_max': 294.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 35}, 'wind': {'speed': 3.76, 'deg': 245, 'gust': 2.44}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 12:00:00'}, {'dt': 1760972400, 'main': {'temp': 295.47, 'feels_like': 295.43, 'temp_min': 295.47, 'temp_max': 295.47, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 64, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 4}, 'wind': {'speed': 3.88, 'deg': 256, 'gust': 3.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 15:00:00'}], 'city': {'id': 2561668, 'name': 'Agadir', 'coord': {'lat': 30.4202, 'lon': -9.5982}, 'country': 'MA', 'population': 698310, 'timezone': 3600, 'sunrise': 1760510425, 'sunset': 1760551652}}"

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 0x105fc2de0>

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 0x104f9fdd0>
# Query the data
forecast_rows = session.execute("SELECT * FROM forecast_table;")
print(forecast_rows.one()) # <- only one row
Row(city_id=2561668, dt=1760551200, forecast=b"{'cod': '200', 'message': 0, 'cnt': 40, 'list': [{'dt': 1760551200, 'main': {'temp': 295.58, 'feels_like': 295.65, 'temp_min': 293.93, 'temp_max': 295.58, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 999, 'humidity': 68, 'temp_kf': 1.65}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 59}, 'wind': {'speed': 5.07, 'deg': 294, 'gust': 6.15}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-15 18:00:00'}, {'dt': 1760562000, 'main': {'temp': 293.63, 'feels_like': 293.72, 'temp_min': 292.24, 'temp_max': 293.63, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 1000, 'humidity': 76, 'temp_kf': 1.39}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 84}, 'wind': {'speed': 1.03, 'deg': 174, 'gust': 1.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-15 21:00:00'}, {'dt': 1760572800, 'main': {'temp': 292.3, 'feels_like': 292.36, 'temp_min': 292.3, 'temp_max': 292.3, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.82, 'deg': 85, 'gust': 1.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 00:00:00'}, {'dt': 1760583600, 'main': {'temp': 291.66, 'feels_like': 291.58, 'temp_min': 291.66, 'temp_max': 291.66, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 95}, 'wind': {'speed': 0.84, 'deg': 348, 'gust': 1.06}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 03:00:00'}, {'dt': 1760594400, 'main': {'temp': 291.57, 'feels_like': 291.48, 'temp_min': 291.57, 'temp_max': 291.57, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 88}, 'wind': {'speed': 1.13, 'deg': 140, 'gust': 0.77}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 06:00:00'}, {'dt': 1760605200, 'main': {'temp': 292.63, 'feels_like': 292.57, 'temp_min': 292.63, 'temp_max': 292.63, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 79}, 'wind': {'speed': 3.25, 'deg': 158, 'gust': 2.44}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 09:00:00'}, {'dt': 1760616000, 'main': {'temp': 295.26, 'feels_like': 295.12, 'temp_min': 295.26, 'temp_max': 295.26, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 89}, 'wind': {'speed': 2.59, 'deg': 220, 'gust': 1.42}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 12:00:00'}, {'dt': 1760626800, 'main': {'temp': 294.73, 'feels_like': 294.64, 'temp_min': 294.73, 'temp_max': 294.73, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 995, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 89}, 'wind': {'speed': 4.65, 'deg': 268, 'gust': 4.73}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 15:00:00'}, {'dt': 1760637600, 'main': {'temp': 294.47, 'feels_like': 294.35, 'temp_min': 294.47, 'temp_max': 294.47, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 995, 'humidity': 65, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 90}, 'wind': {'speed': 4.19, 'deg': 280, 'gust': 5.79}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-16 18:00:00'}, {'dt': 1760648400, 'main': {'temp': 292.47, 'feels_like': 292.52, 'temp_min': 292.47, 'temp_max': 292.47, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.02, 'deg': 116, 'gust': 3.65}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-16 21:00:00'}, {'dt': 1760659200, 'main': {'temp': 291.36, 'feels_like': 291.61, 'temp_min': 291.36, 'temp_max': 291.36, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 91, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.19, 'deg': 117, 'gust': 4.56}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 00:00:00'}, {'dt': 1760670000, 'main': {'temp': 290.9, 'feels_like': 291.08, 'temp_min': 290.9, 'temp_max': 290.9, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 90, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.53, 'deg': 96, 'gust': 1.07}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 03:00:00'}, {'dt': 1760680800, 'main': {'temp': 290.8, 'feels_like': 290.89, 'temp_min': 290.8, 'temp_max': 290.8, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 97}, 'wind': {'speed': 2.05, 'deg': 167, 'gust': 2.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 06:00:00'}, {'dt': 1760691600, 'main': {'temp': 292.06, 'feels_like': 292.1, 'temp_min': 292.06, 'temp_max': 292.06, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 0.52, 'deg': 137, 'gust': 0.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 09:00:00'}, {'dt': 1760702400, 'main': {'temp': 294.29, 'feels_like': 294.31, 'temp_min': 294.29, 'temp_max': 294.29, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 71, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 86}, 'wind': {'speed': 4.53, 'deg': 249, 'gust': 3.09}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 12:00:00'}, {'dt': 1760713200, 'main': {'temp': 295.1, 'feels_like': 295.1, 'temp_min': 295.1, 'temp_max': 295.1, 'pressure': 1010, 'sea_level': 1010, 'grnd_level': 994, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 98}, 'wind': {'speed': 4.76, 'deg': 274, 'gust': 4.66}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 15:00:00'}, {'dt': 1760724000, 'main': {'temp': 294.48, 'feels_like': 294.47, 'temp_min': 294.48, 'temp_max': 294.48, 'pressure': 1010, 'sea_level': 1010, 'grnd_level': 994, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 2.36, 'deg': 286, 'gust': 4.35}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-17 18:00:00'}, {'dt': 1760734800, 'main': {'temp': 292.17, 'feels_like': 292.35, 'temp_min': 292.17, 'temp_max': 292.17, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.32, 'deg': 121, 'gust': 3.42}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-17 21:00:00'}, {'dt': 1760745600, 'main': {'temp': 291.79, 'feels_like': 291.9, 'temp_min': 291.79, 'temp_max': 291.79, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 4.41, 'deg': 110, 'gust': 4.99}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 00:00:00'}, {'dt': 1760756400, 'main': {'temp': 292.28, 'feels_like': 292.29, 'temp_min': 292.28, 'temp_max': 292.28, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 99}, 'wind': {'speed': 1.81, 'deg': 135, 'gust': 1.8}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 03:00:00'}, {'dt': 1760767200, 'main': {'temp': 290.92, 'feels_like': 291.02, 'temp_min': 290.92, 'temp_max': 290.92, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 996, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 98}, 'wind': {'speed': 1.66, 'deg': 305, 'gust': 1.66}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 06:00:00'}, {'dt': 1760778000, 'main': {'temp': 293, 'feels_like': 293.05, 'temp_min': 293, 'temp_max': 293, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 80}, 'wind': {'speed': 1.49, 'deg': 243, 'gust': 1.21}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 09:00:00'}, {'dt': 1760788800, 'main': {'temp': 294.5, 'feels_like': 294.57, 'temp_min': 294.5, 'temp_max': 294.5, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 46}, 'wind': {'speed': 3.43, 'deg': 250, 'gust': 2.72}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 12:00:00'}, {'dt': 1760799600, 'main': {'temp': 295.21, 'feels_like': 295.27, 'temp_min': 295.21, 'temp_max': 295.21, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 47}, 'wind': {'speed': 4.74, 'deg': 268, 'gust': 4.53}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 15:00:00'}, {'dt': 1760810400, 'main': {'temp': 294.86, 'feels_like': 294.86, 'temp_min': 294.86, 'temp_max': 294.86, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 68, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 65}, 'wind': {'speed': 1.88, 'deg': 246, 'gust': 2.77}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-18 18:00:00'}, {'dt': 1760821200, 'main': {'temp': 292.66, 'feels_like': 292.78, 'temp_min': 292.66, 'temp_max': 292.66, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 998, 'humidity': 81, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 76}, 'wind': {'speed': 3.03, 'deg': 116, 'gust': 3.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-18 21:00:00'}, {'dt': 1760832000, 'main': {'temp': 291.74, 'feels_like': 291.85, 'temp_min': 291.74, 'temp_max': 291.74, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 43}, 'wind': {'speed': 4.4, 'deg': 96, 'gust': 4.34}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 00:00:00'}, {'dt': 1760842800, 'main': {'temp': 291.48, 'feels_like': 291.43, 'temp_min': 291.48, 'temp_max': 291.48, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 79, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 32}, 'wind': {'speed': 2.17, 'deg': 88, 'gust': 2.12}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 03:00:00'}, {'dt': 1760853600, 'main': {'temp': 291, 'feels_like': 291.01, 'temp_min': 291, 'temp_max': 291, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 30}, 'wind': {'speed': 1.28, 'deg': 345, 'gust': 1.65}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 06:00:00'}, {'dt': 1760864400, 'main': {'temp': 292.99, 'feels_like': 292.96, 'temp_min': 292.99, 'temp_max': 292.99, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 999, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 2.19, 'deg': 255, 'gust': 1.75}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 09:00:00'}, {'dt': 1760875200, 'main': {'temp': 294.7, 'feels_like': 294.66, 'temp_min': 294.7, 'temp_max': 294.7, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 4.34, 'deg': 248, 'gust': 2.85}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 12:00:00'}, {'dt': 1760886000, 'main': {'temp': 297.25, 'feels_like': 297.2, 'temp_min': 297.25, 'temp_max': 297.25, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 996, 'humidity': 57, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 5.17, 'deg': 280, 'gust': 5.67}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 15:00:00'}, {'dt': 1760896800, 'main': {'temp': 295.58, 'feels_like': 295.47, 'temp_min': 295.58, 'temp_max': 295.58, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 61, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 7}, 'wind': {'speed': 3.39, 'deg': 318, 'gust': 6.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-19 18:00:00'}, {'dt': 1760907600, 'main': {'temp': 292.56, 'feels_like': 292.59, 'temp_min': 292.56, 'temp_max': 292.56, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 3.07, 'deg': 112, 'gust': 2.9}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-19 21:00:00'}, {'dt': 1760918400, 'main': {'temp': 291.53, 'feels_like': 291.59, 'temp_min': 291.53, 'temp_max': 291.53, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 83, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 1}, 'wind': {'speed': 4.3, 'deg': 99, 'gust': 4.03}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 00:00:00'}, {'dt': 1760929200, 'main': {'temp': 291.28, 'feels_like': 291.19, 'temp_min': 291.28, 'temp_max': 291.28, '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': 5}, 'wind': {'speed': 0.92, 'deg': 72, 'gust': 1.81}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 03:00:00'}, {'dt': 1760940000, 'main': {'temp': 290.69, 'feels_like': 290.69, 'temp_min': 290.69, 'temp_max': 290.69, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 997, 'humidity': 84, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 7}, 'wind': {'speed': 1.11, 'deg': 262, 'gust': 1.43}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-10-20 06:00:00'}, {'dt': 1760950800, 'main': {'temp': 292.7, 'feels_like': 292.64, 'temp_min': 292.7, 'temp_max': 292.7, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 998, 'humidity': 74, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 63}, 'wind': {'speed': 1.69, 'deg': 246, 'gust': 1.47}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 09:00:00'}, {'dt': 1760961600, 'main': {'temp': 294.16, 'feels_like': 294.12, 'temp_min': 294.16, 'temp_max': 294.16, 'pressure': 1014, 'sea_level': 1014, 'grnd_level': 997, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 35}, 'wind': {'speed': 3.76, 'deg': 245, 'gust': 2.44}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 12:00:00'}, {'dt': 1760972400, 'main': {'temp': 295.47, 'feels_like': 295.43, 'temp_min': 295.47, 'temp_max': 295.47, 'pressure': 1012, 'sea_level': 1012, 'grnd_level': 995, 'humidity': 64, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 4}, 'wind': {'speed': 3.88, 'deg': 256, 'gust': 3.37}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-10-20 15:00:00'}], 'city': {'id': 2561668, 'name': 'Agadir', 'coord': {'lat': 30.4202, 'lon': -9.5982}, 'country': 'MA', 'population': 698310, 'timezone': 3600, 'sunrise': 1760510425, 'sunset': 1760551652}}")