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

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

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 0x104e1b980>
# 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 0x104e21e20>
session.execute("INSERT INTO case_insensitive (Capital, Letters, Everywhere) VALUES (1, 'Tesla', 'Model S');")
<cassandra.cluster.ResultSet at 0x104e18e00>
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 0x104e306b0>
# 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 (4, 'Volkswagen', 'ID.4');")
<ResponseFuture: query='<SimpleStatement query="INSERT INTO my_first_table (ind, company, model) VALUES (4, 'Volkswagen', 'ID.4');", 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=1, company='Tesla', model='Model S')
Row(ind=2, company='Tesla', model='Model 3')
Row(ind=4, company='Volkswagen', model='ID.4')
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 0x104e72930>
# 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 0x104e30f50>
# 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 0x1046e3980>
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 0x1058caea0>
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('e5f13990-8a55-11f0-9786-e764fe77f234'), company='Oldsmobile', model='Model 6C', price=135000.0)
Datetime: 2025-09-05 12:43:18.313000
Row(id=UUID('e5f09d50-8a55-11f0-9786-e764fe77f234'), company='Tesla', model='Model S', price=20000.0)
Datetime: 2025-09-05 12:43:18.309000
Row(id=UUID('e5f0eb70-8a55-11f0-9786-e764fe77f234'), company='Tesla', model='Model S', price=21000.0)
Datetime: 2025-09-05 12:43:18.311000

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': 1756825200, 'main': {'temp': 290.55, 'feels_like': 290.46, 'temp_min': 290.55, 'temp_max': 291.43, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 81, 'temp_kf': -0.88}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 75}, 'wind': {'speed': 2.27, 'deg': 128, 'gust': 2.71}, 'visibility': 10000, 'pop': 0.28, 'rain': {'3h': 0.21}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-02 15:00:00'}, {'dt': 1756836000, 'main': {'temp': 289.91, 'feels_like': 289.78, 'temp_min': 288.63, 'temp_max': 289.91, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 82, 'temp_kf': 1.28}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 83}, 'wind': {'speed': 1.64, 'deg': 120, 'gust': 1.46}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-02 18:00:00'}, {'dt': 1756846800, 'main': {'temp': 289.82, 'feels_like': 289.61, 'temp_min': 289.45, 'temp_max': 289.82, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 79, 'temp_kf': 0.37}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 92}, 'wind': {'speed': 2, 'deg': 117, 'gust': 1.9}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-02 21:00:00'}, {'dt': 1756857600, 'main': {'temp': 286.85, 'feels_like': 286.42, 'temp_min': 286.85, 'temp_max': 286.85, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 81}, 'wind': {'speed': 2.45, 'deg': 108, 'gust': 2.35}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 00:00:00'}, {'dt': 1756868400, 'main': {'temp': 286.11, 'feels_like': 285.6, 'temp_min': 286.11, 'temp_max': 286.11, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 97}, 'wind': {'speed': 2.61, 'deg': 113, 'gust': 2.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 03:00:00'}, {'dt': 1756879200, 'main': {'temp': 288.14, 'feels_like': 287.78, 'temp_min': 288.14, 'temp_max': 288.14, 'pressure': 1006, 'sea_level': 1006, 'grnd_level': 957, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 2.62, 'deg': 69, 'gust': 3.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 06:00:00'}, {'dt': 1756890000, 'main': {'temp': 287.6, 'feels_like': 287.56, 'temp_min': 287.6, 'temp_max': 287.6, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 94, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.12, 'deg': 63, 'gust': 3.28}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 2.29}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 09:00:00'}, {'dt': 1756900800, 'main': {'temp': 287.91, 'feels_like': 287.92, 'temp_min': 287.91, 'temp_max': 287.91, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 95, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.07, 'deg': 70, 'gust': 3.13}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 3.6}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 12:00:00'}, {'dt': 1756911600, 'main': {'temp': 287.9, 'feels_like': 287.91, 'temp_min': 287.9, 'temp_max': 287.9, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 953, 'humidity': 95, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.59, 'deg': 108, 'gust': 1.53}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 3.22}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 15:00:00'}, {'dt': 1756922400, 'main': {'temp': 287.82, 'feels_like': 287.77, 'temp_min': 287.82, 'temp_max': 287.82, 'pressure': 1004, 'sea_level': 1004, 'grnd_level': 954, 'humidity': 93, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.15, 'deg': 244, 'gust': 1.27}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 0.88}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 18:00:00'}, {'dt': 1756933200, 'main': {'temp': 285.54, 'feels_like': 285.21, 'temp_min': 285.54, 'temp_max': 285.54, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 91, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 26}, 'wind': {'speed': 2.16, 'deg': 85, 'gust': 2.14}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 21:00:00'}, {'dt': 1756944000, 'main': {'temp': 284.88, 'feels_like': 284.43, 'temp_min': 284.88, 'temp_max': 284.88, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 89, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 40}, 'wind': {'speed': 2.55, 'deg': 89, 'gust': 2.34}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 00:00:00'}, {'dt': 1756954800, 'main': {'temp': 284.77, 'feels_like': 284.29, 'temp_min': 284.77, 'temp_max': 284.77, 'pressure': 1004, 'sea_level': 1004, 'grnd_level': 954, 'humidity': 88, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 40}, 'wind': {'speed': 3.33, 'deg': 86, 'gust': 2.8}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 03:00:00'}, {'dt': 1756965600, 'main': {'temp': 286.75, 'feels_like': 286.41, 'temp_min': 286.75, 'temp_max': 286.75, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 71}, 'wind': {'speed': 3.54, 'deg': 83, 'gust': 4.74}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 06:00:00'}, {'dt': 1756976400, 'main': {'temp': 290.27, 'feels_like': 289.89, 'temp_min': 290.27, 'temp_max': 290.27, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 71, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.49, 'deg': 90, 'gust': 4.06}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 09:00:00'}, {'dt': 1756987200, 'main': {'temp': 291.75, 'feels_like': 291.47, 'temp_min': 291.75, 'temp_max': 291.75, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 87}, 'wind': {'speed': 3.04, 'deg': 116, 'gust': 5.38}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 12:00:00'}, {'dt': 1756998000, 'main': {'temp': 290.61, 'feels_like': 290.45, 'temp_min': 290.61, 'temp_max': 290.61, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.92, 'deg': 78, 'gust': 3.01}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 15:00:00'}, {'dt': 1757008800, 'main': {'temp': 290.58, 'feels_like': 290.39, 'temp_min': 290.58, 'temp_max': 290.58, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.61, 'deg': 128, 'gust': 2.58}, 'visibility': 10000, 'pop': 0.27, 'rain': {'3h': 0.44}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 18:00:00'}, {'dt': 1757019600, 'main': {'temp': 288.55, 'feels_like': 288.57, 'temp_min': 288.55, 'temp_max': 288.55, 'pressure': 1006, 'sea_level': 1006, 'grnd_level': 957, 'humidity': 93, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10n'}], 'clouds': {'all': 94}, 'wind': {'speed': 1.37, 'deg': 197, 'gust': 1.34}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 1.36}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 21:00:00'}, {'dt': 1757030400, 'main': {'temp': 287.58, 'feels_like': 287.35, 'temp_min': 287.58, 'temp_max': 287.58, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10n'}], 'clouds': {'all': 95}, 'wind': {'speed': 0.73, 'deg': 214, 'gust': 0.71}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 0.36}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 00:00:00'}, {'dt': 1757041200, 'main': {'temp': 287.84, 'feels_like': 287.61, 'temp_min': 287.84, 'temp_max': 287.84, 'pressure': 1009, 'sea_level': 1009, 'grnd_level': 960, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.25, 'deg': 333, 'gust': 0.33}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 03:00:00'}, {'dt': 1757052000, 'main': {'temp': 287.89, 'feels_like': 287.77, 'temp_min': 287.89, 'temp_max': 287.89, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 961, 'humidity': 90, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.65, 'deg': 274, 'gust': 0.63}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.28}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 06:00:00'}, {'dt': 1757062800, 'main': {'temp': 288.74, 'feels_like': 288.63, 'temp_min': 288.74, 'temp_max': 288.74, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 963, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 92}, 'wind': {'speed': 2.49, 'deg': 251, 'gust': 2.62}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.2}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 09:00:00'}, {'dt': 1757073600, 'main': {'temp': 289.18, 'feels_like': 288.98, 'temp_min': 289.18, 'temp_max': 289.18, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 965, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 96}, 'wind': {'speed': 1.47, 'deg': 253, 'gust': 1.83}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.12}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 12:00:00'}, {'dt': 1757084400, 'main': {'temp': 290.91, 'feels_like': 290.62, 'temp_min': 290.91, 'temp_max': 290.91, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 965, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 48}, 'wind': {'speed': 0.95, 'deg': 258, 'gust': 1.2}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 15:00:00'}, {'dt': 1757095200, 'main': {'temp': 286.93, 'feels_like': 286.66, 'temp_min': 286.93, 'temp_max': 286.93, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 966, 'humidity': 88, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 60}, 'wind': {'speed': 0.99, 'deg': 3, 'gust': 0.98}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 18:00:00'}, {'dt': 1757106000, 'main': {'temp': 287.01, 'feels_like': 286.72, 'temp_min': 287.01, 'temp_max': 287.01, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 967, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.83, 'deg': 94, 'gust': 1.87}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 21:00:00'}, {'dt': 1757116800, 'main': {'temp': 286.55, 'feels_like': 286.22, 'temp_min': 286.55, 'temp_max': 286.55, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 968, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.16, 'deg': 281, 'gust': 0.3}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 00:00:00'}, {'dt': 1757127600, 'main': {'temp': 286.62, 'feels_like': 286.58, 'temp_min': 286.62, 'temp_max': 286.62, 'pressure': 1020, 'sea_level': 1020, 'grnd_level': 970, 'humidity': 98, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.65, 'deg': 275, 'gust': 1.77}, 'visibility': 3389, 'pop': 1, 'rain': {'3h': 4.52}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 03:00:00'}, {'dt': 1757138400, 'main': {'temp': 286.71, 'feels_like': 286.63, 'temp_min': 286.71, 'temp_max': 286.71, 'pressure': 1023, 'sea_level': 1023, 'grnd_level': 972, 'humidity': 96, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.47, 'deg': 259, 'gust': 2.88}, 'visibility': 3188, 'pop': 1, 'rain': {'3h': 2.57}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 06:00:00'}, {'dt': 1757149200, 'main': {'temp': 288.57, 'feels_like': 288.26, 'temp_min': 288.57, 'temp_max': 288.57, 'pressure': 1024, 'sea_level': 1024, 'grnd_level': 974, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 94}, 'wind': {'speed': 1.94, 'deg': 265, 'gust': 2.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 09:00:00'}, {'dt': 1757160000, 'main': {'temp': 290.47, 'feels_like': 290.01, 'temp_min': 290.47, 'temp_max': 290.47, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 974, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 72}, 'wind': {'speed': 1.48, 'deg': 254, 'gust': 1.58}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 12:00:00'}, {'dt': 1757170800, 'main': {'temp': 290.87, 'feels_like': 290.34, 'temp_min': 290.87, 'temp_max': 290.87, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 975, 'humidity': 63, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 45}, 'wind': {'speed': 1.91, 'deg': 259, 'gust': 1.45}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 15:00:00'}, {'dt': 1757181600, 'main': {'temp': 286.35, 'feels_like': 285.87, 'temp_min': 286.35, 'temp_max': 286.35, 'pressure': 1026, 'sea_level': 1026, 'grnd_level': 975, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 35}, 'wind': {'speed': 1.3, 'deg': 241, 'gust': 1.01}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 18:00:00'}, {'dt': 1757192400, 'main': {'temp': 284.78, 'feels_like': 284.24, 'temp_min': 284.78, 'temp_max': 284.78, 'pressure': 1026, 'sea_level': 1026, 'grnd_level': 976, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.56, 'deg': 115, 'gust': 0.74}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 21:00:00'}, {'dt': 1757203200, 'main': {'temp': 284.12, 'feels_like': 283.49, 'temp_min': 284.12, 'temp_max': 284.12, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.31, 'deg': 88, 'gust': 1.36}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-07 00:00:00'}, {'dt': 1757214000, 'main': {'temp': 283.64, 'feels_like': 282.96, 'temp_min': 283.64, 'temp_max': 283.64, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.6, 'deg': 79, 'gust': 1.71}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-07 03:00:00'}, {'dt': 1757224800, 'main': {'temp': 286.62, 'feels_like': 286.03, 'temp_min': 286.62, 'temp_max': 286.62, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.42, 'deg': 72, 'gust': 1.56}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 06:00:00'}, {'dt': 1757235600, 'main': {'temp': 290.13, 'feels_like': 289.53, 'temp_min': 290.13, 'temp_max': 290.13, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 975, 'humidity': 63, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 7}, 'wind': {'speed': 1.33, 'deg': 50, 'gust': 1.73}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 09:00:00'}, {'dt': 1757246400, 'main': {'temp': 293.02, 'feels_like': 292.34, 'temp_min': 293.02, 'temp_max': 293.02, 'pressure': 1024, 'sea_level': 1024, 'grnd_level': 974, 'humidity': 49, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 4}, 'wind': {'speed': 1.2, 'deg': 38, 'gust': 1.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 12:00:00'}], 'city': {'id': 3145614, 'name': 'Mo i Rana', 'coord': {'lat': 66.3128, 'lon': 14.1428}, 'country': 'NO', 'population': 17853, 'timezone': 7200, 'sunrise': 1756784463, 'sunset': 1756837537}}"

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

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 0x102ea8680>
# Query the data
forecast_rows = session.execute("SELECT * FROM forecast_table;")
print(forecast_rows.one()) # <- only one row
Row(city_id=3145614, dt=1756825200, forecast=b"{'cod': '200', 'message': 0, 'cnt': 40, 'list': [{'dt': 1756825200, 'main': {'temp': 290.55, 'feels_like': 290.46, 'temp_min': 290.55, 'temp_max': 291.43, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 81, 'temp_kf': -0.88}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 75}, 'wind': {'speed': 2.27, 'deg': 128, 'gust': 2.71}, 'visibility': 10000, 'pop': 0.28, 'rain': {'3h': 0.21}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-02 15:00:00'}, {'dt': 1756836000, 'main': {'temp': 289.91, 'feels_like': 289.78, 'temp_min': 288.63, 'temp_max': 289.91, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 82, 'temp_kf': 1.28}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 83}, 'wind': {'speed': 1.64, 'deg': 120, 'gust': 1.46}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-02 18:00:00'}, {'dt': 1756846800, 'main': {'temp': 289.82, 'feels_like': 289.61, 'temp_min': 289.45, 'temp_max': 289.82, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 79, 'temp_kf': 0.37}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 92}, 'wind': {'speed': 2, 'deg': 117, 'gust': 1.9}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-02 21:00:00'}, {'dt': 1756857600, 'main': {'temp': 286.85, 'feels_like': 286.42, 'temp_min': 286.85, 'temp_max': 286.85, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04n'}], 'clouds': {'all': 81}, 'wind': {'speed': 2.45, 'deg': 108, 'gust': 2.35}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 00:00:00'}, {'dt': 1756868400, 'main': {'temp': 286.11, 'feels_like': 285.6, 'temp_min': 286.11, 'temp_max': 286.11, 'pressure': 1007, 'sea_level': 1007, 'grnd_level': 958, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 97}, 'wind': {'speed': 2.61, 'deg': 113, 'gust': 2.62}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 03:00:00'}, {'dt': 1756879200, 'main': {'temp': 288.14, 'feels_like': 287.78, 'temp_min': 288.14, 'temp_max': 288.14, 'pressure': 1006, 'sea_level': 1006, 'grnd_level': 957, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 99}, 'wind': {'speed': 2.62, 'deg': 69, 'gust': 3.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 06:00:00'}, {'dt': 1756890000, 'main': {'temp': 287.6, 'feels_like': 287.56, 'temp_min': 287.6, 'temp_max': 287.6, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 94, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.12, 'deg': 63, 'gust': 3.28}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 2.29}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 09:00:00'}, {'dt': 1756900800, 'main': {'temp': 287.91, 'feels_like': 287.92, 'temp_min': 287.91, 'temp_max': 287.91, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 95, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.07, 'deg': 70, 'gust': 3.13}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 3.6}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 12:00:00'}, {'dt': 1756911600, 'main': {'temp': 287.9, 'feels_like': 287.91, 'temp_min': 287.9, 'temp_max': 287.9, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 953, 'humidity': 95, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.59, 'deg': 108, 'gust': 1.53}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 3.22}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 15:00:00'}, {'dt': 1756922400, 'main': {'temp': 287.82, 'feels_like': 287.77, 'temp_min': 287.82, 'temp_max': 287.82, 'pressure': 1004, 'sea_level': 1004, 'grnd_level': 954, 'humidity': 93, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.15, 'deg': 244, 'gust': 1.27}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 0.88}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-03 18:00:00'}, {'dt': 1756933200, 'main': {'temp': 285.54, 'feels_like': 285.21, 'temp_min': 285.54, 'temp_max': 285.54, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 91, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 26}, 'wind': {'speed': 2.16, 'deg': 85, 'gust': 2.14}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-03 21:00:00'}, {'dt': 1756944000, 'main': {'temp': 284.88, 'feels_like': 284.43, 'temp_min': 284.88, 'temp_max': 284.88, 'pressure': 1005, 'sea_level': 1005, 'grnd_level': 955, 'humidity': 89, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 40}, 'wind': {'speed': 2.55, 'deg': 89, 'gust': 2.34}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 00:00:00'}, {'dt': 1756954800, 'main': {'temp': 284.77, 'feels_like': 284.29, 'temp_min': 284.77, 'temp_max': 284.77, 'pressure': 1004, 'sea_level': 1004, 'grnd_level': 954, 'humidity': 88, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'clouds': {'all': 40}, 'wind': {'speed': 3.33, 'deg': 86, 'gust': 2.8}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 03:00:00'}, {'dt': 1756965600, 'main': {'temp': 286.75, 'feels_like': 286.41, 'temp_min': 286.75, 'temp_max': 286.75, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 71}, 'wind': {'speed': 3.54, 'deg': 83, 'gust': 4.74}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 06:00:00'}, {'dt': 1756976400, 'main': {'temp': 290.27, 'feels_like': 289.89, 'temp_min': 290.27, 'temp_max': 290.27, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 71, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 3.49, 'deg': 90, 'gust': 4.06}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 09:00:00'}, {'dt': 1756987200, 'main': {'temp': 291.75, 'feels_like': 291.47, 'temp_min': 291.75, 'temp_max': 291.75, 'pressure': 1002, 'sea_level': 1002, 'grnd_level': 953, 'humidity': 69, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 87}, 'wind': {'speed': 3.04, 'deg': 116, 'gust': 5.38}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 12:00:00'}, {'dt': 1756998000, 'main': {'temp': 290.61, 'feels_like': 290.45, 'temp_min': 290.61, 'temp_max': 290.61, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 78, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.92, 'deg': 78, 'gust': 3.01}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 15:00:00'}, {'dt': 1757008800, 'main': {'temp': 290.58, 'feels_like': 290.39, 'temp_min': 290.58, 'temp_max': 290.58, 'pressure': 1003, 'sea_level': 1003, 'grnd_level': 954, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.61, 'deg': 128, 'gust': 2.58}, 'visibility': 10000, 'pop': 0.27, 'rain': {'3h': 0.44}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-04 18:00:00'}, {'dt': 1757019600, 'main': {'temp': 288.55, 'feels_like': 288.57, 'temp_min': 288.55, 'temp_max': 288.55, 'pressure': 1006, 'sea_level': 1006, 'grnd_level': 957, 'humidity': 93, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10n'}], 'clouds': {'all': 94}, 'wind': {'speed': 1.37, 'deg': 197, 'gust': 1.34}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 1.36}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-04 21:00:00'}, {'dt': 1757030400, 'main': {'temp': 287.58, 'feels_like': 287.35, 'temp_min': 287.58, 'temp_max': 287.58, 'pressure': 1008, 'sea_level': 1008, 'grnd_level': 959, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10n'}], 'clouds': {'all': 95}, 'wind': {'speed': 0.73, 'deg': 214, 'gust': 0.71}, 'visibility': 10000, 'pop': 1, 'rain': {'3h': 0.36}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 00:00:00'}, {'dt': 1757041200, 'main': {'temp': 287.84, 'feels_like': 287.61, 'temp_min': 287.84, 'temp_max': 287.84, 'pressure': 1009, 'sea_level': 1009, 'grnd_level': 960, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.25, 'deg': 333, 'gust': 0.33}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 03:00:00'}, {'dt': 1757052000, 'main': {'temp': 287.89, 'feels_like': 287.77, 'temp_min': 287.89, 'temp_max': 287.89, 'pressure': 1011, 'sea_level': 1011, 'grnd_level': 961, 'humidity': 90, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.65, 'deg': 274, 'gust': 0.63}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.28}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 06:00:00'}, {'dt': 1757062800, 'main': {'temp': 288.74, 'feels_like': 288.63, 'temp_min': 288.74, 'temp_max': 288.74, 'pressure': 1013, 'sea_level': 1013, 'grnd_level': 963, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 92}, 'wind': {'speed': 2.49, 'deg': 251, 'gust': 2.62}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.2}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 09:00:00'}, {'dt': 1757073600, 'main': {'temp': 289.18, 'feels_like': 288.98, 'temp_min': 289.18, 'temp_max': 289.18, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 965, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 96}, 'wind': {'speed': 1.47, 'deg': 253, 'gust': 1.83}, 'visibility': 10000, 'pop': 0.2, 'rain': {'3h': 0.12}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 12:00:00'}, {'dt': 1757084400, 'main': {'temp': 290.91, 'feels_like': 290.62, 'temp_min': 290.91, 'temp_max': 290.91, 'pressure': 1015, 'sea_level': 1015, 'grnd_level': 965, 'humidity': 72, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 48}, 'wind': {'speed': 0.95, 'deg': 258, 'gust': 1.2}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 15:00:00'}, {'dt': 1757095200, 'main': {'temp': 286.93, 'feels_like': 286.66, 'temp_min': 286.93, 'temp_max': 286.93, 'pressure': 1016, 'sea_level': 1016, 'grnd_level': 966, 'humidity': 88, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 60}, 'wind': {'speed': 0.99, 'deg': 3, 'gust': 0.98}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-05 18:00:00'}, {'dt': 1757106000, 'main': {'temp': 287.01, 'feels_like': 286.72, 'temp_min': 287.01, 'temp_max': 287.01, 'pressure': 1017, 'sea_level': 1017, 'grnd_level': 967, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.83, 'deg': 94, 'gust': 1.87}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-05 21:00:00'}, {'dt': 1757116800, 'main': {'temp': 286.55, 'feels_like': 286.22, 'temp_min': 286.55, 'temp_max': 286.55, 'pressure': 1018, 'sea_level': 1018, 'grnd_level': 968, 'humidity': 87, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04n'}], 'clouds': {'all': 100}, 'wind': {'speed': 0.16, 'deg': 281, 'gust': 0.3}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 00:00:00'}, {'dt': 1757127600, 'main': {'temp': 286.62, 'feels_like': 286.58, 'temp_min': 286.62, 'temp_max': 286.62, 'pressure': 1020, 'sea_level': 1020, 'grnd_level': 970, 'humidity': 98, 'temp_kf': 0}, 'weather': [{'id': 501, 'main': 'Rain', 'description': 'moderate rain', 'icon': '10n'}], 'clouds': {'all': 100}, 'wind': {'speed': 1.65, 'deg': 275, 'gust': 1.77}, 'visibility': 3389, 'pop': 1, 'rain': {'3h': 4.52}, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 03:00:00'}, {'dt': 1757138400, 'main': {'temp': 286.71, 'feels_like': 286.63, 'temp_min': 286.71, 'temp_max': 286.71, 'pressure': 1023, 'sea_level': 1023, 'grnd_level': 972, 'humidity': 96, 'temp_kf': 0}, 'weather': [{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'}], 'clouds': {'all': 100}, 'wind': {'speed': 2.47, 'deg': 259, 'gust': 2.88}, 'visibility': 3188, 'pop': 1, 'rain': {'3h': 2.57}, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 06:00:00'}, {'dt': 1757149200, 'main': {'temp': 288.57, 'feels_like': 288.26, 'temp_min': 288.57, 'temp_max': 288.57, 'pressure': 1024, 'sea_level': 1024, 'grnd_level': 974, 'humidity': 80, 'temp_kf': 0}, 'weather': [{'id': 804, 'main': 'Clouds', 'description': 'overcast clouds', 'icon': '04d'}], 'clouds': {'all': 94}, 'wind': {'speed': 1.94, 'deg': 265, 'gust': 2.22}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 09:00:00'}, {'dt': 1757160000, 'main': {'temp': 290.47, 'feels_like': 290.01, 'temp_min': 290.47, 'temp_max': 290.47, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 974, 'humidity': 67, 'temp_kf': 0}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'clouds': {'all': 72}, 'wind': {'speed': 1.48, 'deg': 254, 'gust': 1.58}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 12:00:00'}, {'dt': 1757170800, 'main': {'temp': 290.87, 'feels_like': 290.34, 'temp_min': 290.87, 'temp_max': 290.87, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 975, 'humidity': 63, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 45}, 'wind': {'speed': 1.91, 'deg': 259, 'gust': 1.45}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 15:00:00'}, {'dt': 1757181600, 'main': {'temp': 286.35, 'feels_like': 285.87, 'temp_min': 286.35, 'temp_max': 286.35, 'pressure': 1026, 'sea_level': 1026, 'grnd_level': 975, 'humidity': 82, 'temp_kf': 0}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03d'}], 'clouds': {'all': 35}, 'wind': {'speed': 1.3, 'deg': 241, 'gust': 1.01}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-06 18:00:00'}, {'dt': 1757192400, 'main': {'temp': 284.78, 'feels_like': 284.24, 'temp_min': 284.78, 'temp_max': 284.78, 'pressure': 1026, 'sea_level': 1026, 'grnd_level': 976, 'humidity': 86, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 0.56, 'deg': 115, 'gust': 0.74}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-06 21:00:00'}, {'dt': 1757203200, 'main': {'temp': 284.12, 'feels_like': 283.49, 'temp_min': 284.12, 'temp_max': 284.12, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 0}, 'wind': {'speed': 1.31, 'deg': 88, 'gust': 1.36}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-07 00:00:00'}, {'dt': 1757214000, 'main': {'temp': 283.64, 'feels_like': 282.96, 'temp_min': 283.64, 'temp_max': 283.64, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 85, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.6, 'deg': 79, 'gust': 1.71}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'n'}, 'dt_txt': '2025-09-07 03:00:00'}, {'dt': 1757224800, 'main': {'temp': 286.62, 'feels_like': 286.03, 'temp_min': 286.62, 'temp_max': 286.62, 'pressure': 1027, 'sea_level': 1027, 'grnd_level': 976, 'humidity': 77, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 6}, 'wind': {'speed': 1.42, 'deg': 72, 'gust': 1.56}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 06:00:00'}, {'dt': 1757235600, 'main': {'temp': 290.13, 'feels_like': 289.53, 'temp_min': 290.13, 'temp_max': 290.13, 'pressure': 1025, 'sea_level': 1025, 'grnd_level': 975, 'humidity': 63, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 7}, 'wind': {'speed': 1.33, 'deg': 50, 'gust': 1.73}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 09:00:00'}, {'dt': 1757246400, 'main': {'temp': 293.02, 'feels_like': 292.34, 'temp_min': 293.02, 'temp_max': 293.02, 'pressure': 1024, 'sea_level': 1024, 'grnd_level': 974, 'humidity': 49, 'temp_kf': 0}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'clouds': {'all': 4}, 'wind': {'speed': 1.2, 'deg': 38, 'gust': 1.7}, 'visibility': 10000, 'pop': 0, 'sys': {'pod': 'd'}, 'dt_txt': '2025-09-07 12:00:00'}], 'city': {'id': 3145614, 'name': 'Mo i Rana', 'coord': {'lat': 66.3128, 'lon': 14.1428}, 'country': 'NO', 'population': 17853, 'timezone': 7200, 'sunrise': 1756784463, 'sunset': 1756837537}}")