From 25347659143d1d761f4af68e5e7a3974a1a9fe92 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 4 Jan 2026 21:53:00 +0000 Subject: [PATCH 01/10] Initial Commit --- tinydb/README.md | 24 +++++++++++++ tinydb/countries_file.csv | 4 +++ tinydb/create.py | 26 ++++++++++++++ tinydb/delete.py | 21 +++++++++++ tinydb/read.py | 14 ++++++++ tinydb/ten_countries.json | 74 +++++++++++++++++++++++++++++++++++++++ tinydb/update.py | 30 ++++++++++++++++ 7 files changed, 193 insertions(+) create mode 100644 tinydb/README.md create mode 100644 tinydb/countries_file.csv create mode 100644 tinydb/create.py create mode 100644 tinydb/delete.py create mode 100644 tinydb/read.py create mode 100644 tinydb/ten_countries.json create mode 100644 tinydb/update.py diff --git a/tinydb/README.md b/tinydb/README.md new file mode 100644 index 0000000000..95c5f61879 --- /dev/null +++ b/tinydb/README.md @@ -0,0 +1,24 @@ +This file contains the downloadable code from the RealPython tutorial: \[TinyDB: A Lightweight JSON Database for Small Projects](https://realpython.com/tinydb-lightweight-json-database-small-projects/) + + + + + +create.py - File containing all code from the CREATE section of the tutorial. + +read.py - File containing all code from the READ section of the tutorial. + +update.py - File containing all code from the UPDATE section of the tutorial. + +delete.py - File containing all code from the DELETE section of the tutorial. + + + +countries\_file.csv - File containing csv data to be converted to TinyDB documents. + +ten\_countries.json - File containing an existing JSON object representing ten TinyDB records in a countries table. + + + +README.md - This file + diff --git a/tinydb/countries_file.csv b/tinydb/countries_file.csv new file mode 100644 index 0000000000..99d7b3fcc7 --- /dev/null +++ b/tinydb/countries_file.csv @@ -0,0 +1,4 @@ +location,population,continent +Argentina,45929925,South America +Switzerland,8990428,Europe +Mozambique,36147236,Africa diff --git a/tinydb/create.py b/tinydb/create.py new file mode 100644 index 0000000000..497b4c6c4a --- /dev/null +++ b/tinydb/create.py @@ -0,0 +1,26 @@ +from csv import DictReader +from pprint import pprint + +from tinydb import TinyDB + +with TinyDB("countries.json", indent=4) as countries: + countries_table = countries.table(name="countries") + + countries_table.insert( + {"location": "Vatican City", "population": 501} + ) + + countries_table.insert_multiple( + [ + {"location": "India", "population": 1_417_492_000}, + {"location": "China", "population": 1_408_280_000}, + ] + ) + + with open("countries_file.csv", "r") as csv_source: + reader = DictReader(csv_source) + + for row in reader: + countries_table.insert(row) + + pprint(countries_table.get(doc_ids=[3, 4])) diff --git a/tinydb/delete.py b/tinydb/delete.py new file mode 100644 index 0000000000..e97ab51890 --- /dev/null +++ b/tinydb/delete.py @@ -0,0 +1,21 @@ +from tinydb import TinyDB, where + +countries_db = TinyDB("ten_countries.json") +countries_tb = countries_db.table(name="countries") + +len(countries_tb) + +countries_tb.remove(doc_ids=[3, 5, 7]) + +len(countries_tb) + +countries_tb.remove(where("population") < 300_000_000) + +countries_tb.truncate() +len(countries_tb) + +countries_db.tables() + +countries_db.drop_table(name="countries") + +countries_db.tables() diff --git a/tinydb/read.py b/tinydb/read.py new file mode 100644 index 0000000000..9999a37079 --- /dev/null +++ b/tinydb/read.py @@ -0,0 +1,14 @@ +from pprint import pprint +from tinydb import Query, TinyDB + +countries_db = TinyDB("ten_countries.json") +countries_tb = countries_db.table(name="countries") + +query = Query() +query_def = (query.population > 220_000_000) & ( + query.population < 250_000_000 +) + +pprint(countries_tb.search(query_def)) + +pprint(countries_tb.search(query["% of world"] >= 17)) diff --git a/tinydb/ten_countries.json b/tinydb/ten_countries.json new file mode 100644 index 0000000000..09096bf005 --- /dev/null +++ b/tinydb/ten_countries.json @@ -0,0 +1,74 @@ +{ + "countries": { + "1": { + "location": "India", + "population": 1417492000, + "% of world": 17.3, + "date": "1 Jul 2025", + "source": "Official projection" + }, + "2": { + "location": "China", + "population": 1408280000, + "% of world": 17.2, + "date": "31 Dec 2024", + "source": "Official estimate" + }, + "3": { + "location": "United States", + "population": 340110988, + "% of world": 4.1, + "date": "1 Jul 2024", + "source": "Official estimate" + }, + "4": { + "location": "Indonesia", + "population": 284438782, + "% of world": 3.5, + "date": "30 Jun 2025", + "source": "National annual projection" + }, + "5": { + "location": "Pakistan", + "population": 241499431, + "% of world": 2.9, + "date": "1 Mar 2023", + "source": "2023 Census result" + }, + "6": { + "location": "Nigeria", + "population": 223800000, + "% of world": 2.7, + "date": "1 Jul 2023", + "source": "Official projection" + }, + "7": { + "location": "Brazil", + "population": 213421037, + "% of world": 2.6, + "date": "1 Jul 2025", + "source": "Unknown" + }, + "8": { + "location": "Bangladesh", + "population": 169828911, + "% of world": 2.1, + "date": "14 Jun 2022", + "source": "2022 Census result" + }, + "9": { + "location": "Russia", + "population": 146028325, + "% of world": 1.8, + "date": "1 Jan 2025", + "source": "???" + }, + "10": { + "location": "Mexico", + "population": 0, + "% of world": 1.6, + "date": "30 Jun 2025", + "source": "???" + } + } +} \ No newline at end of file diff --git a/tinydb/update.py b/tinydb/update.py new file mode 100644 index 0000000000..155a683738 --- /dev/null +++ b/tinydb/update.py @@ -0,0 +1,30 @@ +from pprint import pprint +from tinydb import TinyDB, where + +with TinyDB("ten_countries.json") as countries_db: + countries_tb = countries_db.table(name="countries") + countries_tb.update( + {"population": 130_575_786}, where("location") == "Mexico" + ) + countries_tb.update( + {"source": "National quarterly update"}, + where("location") == "Mexico", + ) + pprint(countries_tb.search(where("location") == "Mexico")) + + countries_tb.update_multiple( + [ + ( + {"population": 130_575_786}, + where("location") == "Mexico", + ), + ( + {"source": "National quarterly update"}, + where("location") == "Mexico", + ), + ] + ) + + countries_tb.update( + {"source": "Official estimate"}, doc_ids=[7, 9] + ) From 497360e68f9b332c5fca418a749a721284ca0309 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 4 Jan 2026 22:05:41 +0000 Subject: [PATCH 02/10] update after isort --- tinydb/pyproject.toml | 21 +++++++++++++++++++++ tinydb/read.py | 1 + tinydb/update.py | 4 +++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tinydb/pyproject.toml diff --git a/tinydb/pyproject.toml b/tinydb/pyproject.toml new file mode 100644 index 0000000000..b0e704544f --- /dev/null +++ b/tinydb/pyproject.toml @@ -0,0 +1,21 @@ +[tool.black] +line-length = 70 +target-version = ["py312"] +exclude = ''' +/( + \.git + | venv + | migrations + | node_modules +)/ +''' + + +[tool.ruff] +target-version = "py312" +exclude = [".git", "venv", "migrations", "node_modules"] +line-length = 70 + +[tool.ruff.lint] +select = ["E", "F", "I", "RUF100"] +ignore = ["E501"] # Line length is handled by Black \ No newline at end of file diff --git a/tinydb/read.py b/tinydb/read.py index 9999a37079..b5aa007e9c 100644 --- a/tinydb/read.py +++ b/tinydb/read.py @@ -1,4 +1,5 @@ from pprint import pprint + from tinydb import Query, TinyDB countries_db = TinyDB("ten_countries.json") diff --git a/tinydb/update.py b/tinydb/update.py index 155a683738..68d1729ae9 100644 --- a/tinydb/update.py +++ b/tinydb/update.py @@ -1,10 +1,12 @@ from pprint import pprint + from tinydb import TinyDB, where with TinyDB("ten_countries.json") as countries_db: countries_tb = countries_db.table(name="countries") countries_tb.update( - {"population": 130_575_786}, where("location") == "Mexico" + {"population": 130_575_786}, + where("location") == "Mexico", ) countries_tb.update( {"source": "National quarterly update"}, From 39e5b009e337c58181cb9e720623e0012d5e4f72 Mon Sep 17 00:00:00 2001 From: martin-martin Date: Fri, 30 Jan 2026 18:13:16 +0100 Subject: [PATCH 03/10] Update pyproject.toml file --- tinydb/pyproject.toml | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tinydb/pyproject.toml b/tinydb/pyproject.toml index b0e704544f..c7d8e958ca 100644 --- a/tinydb/pyproject.toml +++ b/tinydb/pyproject.toml @@ -1,21 +1,5 @@ -[tool.black] -line-length = 70 -target-version = ["py312"] -exclude = ''' -/( - \.git - | venv - | migrations - | node_modules -)/ -''' - - -[tool.ruff] -target-version = "py312" -exclude = [".git", "venv", "migrations", "node_modules"] -line-length = 70 - -[tool.ruff.lint] -select = ["E", "F", "I", "RUF100"] -ignore = ["E501"] # Line length is handled by Black \ No newline at end of file +[project] +name = "tinydb" +version = "0.1.0" +requires-python = ">=3.13" +dependencies = ["tinydb"] From 92fe1a2bb2a2a4d6c04de83d8a50bb887e0ef13d Mon Sep 17 00:00:00 2001 From: martin-martin Date: Fri, 30 Jan 2026 18:15:36 +0100 Subject: [PATCH 04/10] Update README --- tinydb/README.md | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/tinydb/README.md b/tinydb/README.md index 95c5f61879..a39fe5bfe9 100644 --- a/tinydb/README.md +++ b/tinydb/README.md @@ -1,24 +1,13 @@ -This file contains the downloadable code from the RealPython tutorial: \[TinyDB: A Lightweight JSON Database for Small Projects](https://realpython.com/tinydb-lightweight-json-database-small-projects/) +# TinyDB Tutorial Code (Real Python) +This repository contains the downloadable code for the Real Python tutorial: [TinyDB: A Lightweight JSON Database for Small Projects](https://realpython.com/tinydb-python/) +## Contents - - -create.py - File containing all code from the CREATE section of the tutorial. - -read.py - File containing all code from the READ section of the tutorial. - -update.py - File containing all code from the UPDATE section of the tutorial. - -delete.py - File containing all code from the DELETE section of the tutorial. - - - -countries\_file.csv - File containing csv data to be converted to TinyDB documents. - -ten\_countries.json - File containing an existing JSON object representing ten TinyDB records in a countries table. - - - -README.md - This file - +- `create.py` — All code from the **CREATE** section of the tutorial +- `read.py` — All code from the **READ** section of the tutorial +- `update.py` — All code from the **UPDATE** section of the tutorial +- `delete.py` — All code from the **DELETE** section of the tutorial +- `countries_file.csv` — CSV data used to create TinyDB documents +- `ten_countries.json` — Sample JSON file containing data for ten countries +- `README.md` — This file \ No newline at end of file From c3abf3e338cce0111b54e61c8e8a08b37b442246 Mon Sep 17 00:00:00 2001 From: martin-martin Date: Fri, 30 Jan 2026 18:17:44 +0100 Subject: [PATCH 05/10] Ruff format --- tinydb/create.py | 4 +--- tinydb/read.py | 4 +--- tinydb/update.py | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tinydb/create.py b/tinydb/create.py index 497b4c6c4a..240608f7be 100644 --- a/tinydb/create.py +++ b/tinydb/create.py @@ -6,9 +6,7 @@ with TinyDB("countries.json", indent=4) as countries: countries_table = countries.table(name="countries") - countries_table.insert( - {"location": "Vatican City", "population": 501} - ) + countries_table.insert({"location": "Vatican City", "population": 501}) countries_table.insert_multiple( [ diff --git a/tinydb/read.py b/tinydb/read.py index b5aa007e9c..fb85758d81 100644 --- a/tinydb/read.py +++ b/tinydb/read.py @@ -6,9 +6,7 @@ countries_tb = countries_db.table(name="countries") query = Query() -query_def = (query.population > 220_000_000) & ( - query.population < 250_000_000 -) +query_def = (query.population > 220_000_000) & (query.population < 250_000_000) pprint(countries_tb.search(query_def)) diff --git a/tinydb/update.py b/tinydb/update.py index 68d1729ae9..59e0cd2ae0 100644 --- a/tinydb/update.py +++ b/tinydb/update.py @@ -27,6 +27,4 @@ ] ) - countries_tb.update( - {"source": "Official estimate"}, doc_ids=[7, 9] - ) + countries_tb.update({"source": "Official estimate"}, doc_ids=[7, 9]) From 51fb932fcbdec063b25dc45af370e8220b6669be Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 1 Feb 2026 15:35:21 +0000 Subject: [PATCH 06/10] Post TR2 -Attempt 1 --- tinydb/README.md | 12 +++++++---- tinydb/{create.py => create_db.py} | 7 +++---- tinydb/delete.py | 19 +++++++++--------- tinydb/pyproject.toml | 21 -------------------- tinydb/read.py | 14 +++++++------ tinydb/update.py | 32 ------------------------------ tinydb/update_db.py | 20 +++++++++++++++++++ tinydb/update_db_v2.py | 16 +++++++++++++++ tinydb/update_db_v3.py | 5 +++++ 9 files changed, 70 insertions(+), 76 deletions(-) rename tinydb/{create.py => create_db.py} (73%) delete mode 100644 tinydb/pyproject.toml delete mode 100644 tinydb/update.py create mode 100644 tinydb/update_db.py create mode 100644 tinydb/update_db_v2.py create mode 100644 tinydb/update_db_v3.py diff --git a/tinydb/README.md b/tinydb/README.md index 95c5f61879..5890d02ad5 100644 --- a/tinydb/README.md +++ b/tinydb/README.md @@ -4,13 +4,17 @@ This file contains the downloadable code from the RealPython tutorial: \[TinyDB: -create.py - File containing all code from the CREATE section of the tutorial. +create\_db.py - SCRIPT file containing code from the CREATE section of the tutorial. -read.py - File containing all code from the READ section of the tutorial. +read.py - REPL code file containing code from the READ section of the tutorial. -update.py - File containing all code from the UPDATE section of the tutorial. +update\_db.py - SCRIPT file containing code from the UPDATE section of the tutorial. -delete.py - File containing all code from the DELETE section of the tutorial. +update\_db\_v2.py - SCRIPT file containing code from the UPDATE section of the tutorial. + +update\_db\_v3.py - SCRIPT file containing code from the UPDATE section of the tutorial. + +delete.py - REPL code file containing code from the DELETE section of the tutorial. diff --git a/tinydb/create.py b/tinydb/create_db.py similarity index 73% rename from tinydb/create.py rename to tinydb/create_db.py index 497b4c6c4a..9d2e653f46 100644 --- a/tinydb/create.py +++ b/tinydb/create_db.py @@ -1,10 +1,9 @@ from csv import DictReader -from pprint import pprint from tinydb import TinyDB -with TinyDB("countries.json", indent=4) as countries: - countries_table = countries.table(name="countries") +with TinyDB("countries.json", indent=4) as countries_db: + countries_table = countries_db.table(name="countries") countries_table.insert( {"location": "Vatican City", "population": 501} @@ -21,6 +20,6 @@ reader = DictReader(csv_source) for row in reader: + row["population"] = int(row["population"]) countries_table.insert(row) - pprint(countries_table.get(doc_ids=[3, 4])) diff --git a/tinydb/delete.py b/tinydb/delete.py index e97ab51890..32b5db167d 100644 --- a/tinydb/delete.py +++ b/tinydb/delete.py @@ -1,21 +1,22 @@ +# REPL code + from tinydb import TinyDB, where countries_db = TinyDB("ten_countries.json") -countries_tb = countries_db.table(name="countries") - -len(countries_tb) +countries_table = countries_db.table(name="countries") +len(countries_table) -countries_tb.remove(doc_ids=[3, 5, 7]) +countries_table.remove(doc_ids=[3, 5, 7]) -len(countries_tb) +len(countries_table) -countries_tb.remove(where("population") < 300_000_000) +countries_table.remove(where("population") < 300_000_000) +len(countries_table) -countries_tb.truncate() -len(countries_tb) +countries_table.truncate() +len(countries_table) countries_db.tables() countries_db.drop_table(name="countries") - countries_db.tables() diff --git a/tinydb/pyproject.toml b/tinydb/pyproject.toml deleted file mode 100644 index b0e704544f..0000000000 --- a/tinydb/pyproject.toml +++ /dev/null @@ -1,21 +0,0 @@ -[tool.black] -line-length = 70 -target-version = ["py312"] -exclude = ''' -/( - \.git - | venv - | migrations - | node_modules -)/ -''' - - -[tool.ruff] -target-version = "py312" -exclude = [".git", "venv", "migrations", "node_modules"] -line-length = 70 - -[tool.ruff.lint] -select = ["E", "F", "I", "RUF100"] -ignore = ["E501"] # Line length is handled by Black \ No newline at end of file diff --git a/tinydb/read.py b/tinydb/read.py index b5aa007e9c..d7ca3d81d5 100644 --- a/tinydb/read.py +++ b/tinydb/read.py @@ -1,15 +1,17 @@ +# REPL Code + from pprint import pprint from tinydb import Query, TinyDB countries_db = TinyDB("ten_countries.json") -countries_tb = countries_db.table(name="countries") - +countries_table = countries_db.table(name="countries") query = Query() query_def = (query.population > 220_000_000) & ( query.population < 250_000_000 ) - -pprint(countries_tb.search(query_def)) - -pprint(countries_tb.search(query["% of world"] >= 17)) +pprint(countries_table.search(query_def)) +pprint(countries_table.search(query_def)) +pprint(countries_table.search(query["% of world"] >= 17)) +pprint(countries_table.get(doc_ids=[9, 10])) +countries_db.close() \ No newline at end of file diff --git a/tinydb/update.py b/tinydb/update.py deleted file mode 100644 index 68d1729ae9..0000000000 --- a/tinydb/update.py +++ /dev/null @@ -1,32 +0,0 @@ -from pprint import pprint - -from tinydb import TinyDB, where - -with TinyDB("ten_countries.json") as countries_db: - countries_tb = countries_db.table(name="countries") - countries_tb.update( - {"population": 130_575_786}, - where("location") == "Mexico", - ) - countries_tb.update( - {"source": "National quarterly update"}, - where("location") == "Mexico", - ) - pprint(countries_tb.search(where("location") == "Mexico")) - - countries_tb.update_multiple( - [ - ( - {"population": 130_575_786}, - where("location") == "Mexico", - ), - ( - {"source": "National quarterly update"}, - where("location") == "Mexico", - ), - ] - ) - - countries_tb.update( - {"source": "Official estimate"}, doc_ids=[7, 9] - ) diff --git a/tinydb/update_db.py b/tinydb/update_db.py new file mode 100644 index 0000000000..9aa45645f8 --- /dev/null +++ b/tinydb/update_db.py @@ -0,0 +1,20 @@ +from tinydb import TinyDB, where + +with TinyDB("ten_countries.json") as countries_db: + countries_table = countries_db.table(name="countries") + + countries_table.update( + {"population": 130_575_786}, where("location") == "Mexico" + ) + + countries_table.update( + {"source": "National quarterly update"}, + where("location") == "Mexico", + ) + +# REPL code. +# from pprint import pprint +# from tinydb import TinyDB, where +# with TinyDB("ten_countries.json") as countries_db: +# countries_table = countries_db.table(name="countries") +# pprint(countries_table.search(where("location") == "Mexico")) \ No newline at end of file diff --git a/tinydb/update_db_v2.py b/tinydb/update_db_v2.py new file mode 100644 index 0000000000..2ef5068eb7 --- /dev/null +++ b/tinydb/update_db_v2.py @@ -0,0 +1,16 @@ +from tinydb import TinyDB, where + +with TinyDB("ten_countries.json") as countries_db: + countries_table = countries_db.table(name="countries") + countries_table.update_multiple( + [ + ( + {"population": 130_575_786}, + where("location") == "Mexico", + ), + ( + {"source": "National quarterly update"}, + where("location") == "Mexico", + ), + ] + ) \ No newline at end of file diff --git a/tinydb/update_db_v3.py b/tinydb/update_db_v3.py new file mode 100644 index 0000000000..4c83ec6eb0 --- /dev/null +++ b/tinydb/update_db_v3.py @@ -0,0 +1,5 @@ +from tinydb import TinyDB + +with TinyDB("ten_countries.json") as countries_db: + countries_table = countries_db.table(name="countries") + countries_table.update({"source": "Official estimate"}, doc_ids=[7, 9]) \ No newline at end of file From 09eb38269e9b917b9e291fc7957b5912965b6272 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 1 Feb 2026 16:13:20 +0000 Subject: [PATCH 07/10] Post TR2 Attempt 3 --- tinydb/pyproject.toml | 21 --------------------- tinydb/update_db_v3.py | 4 +++- 2 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 tinydb/pyproject.toml diff --git a/tinydb/pyproject.toml b/tinydb/pyproject.toml deleted file mode 100644 index b0e704544f..0000000000 --- a/tinydb/pyproject.toml +++ /dev/null @@ -1,21 +0,0 @@ -[tool.black] -line-length = 70 -target-version = ["py312"] -exclude = ''' -/( - \.git - | venv - | migrations - | node_modules -)/ -''' - - -[tool.ruff] -target-version = "py312" -exclude = [".git", "venv", "migrations", "node_modules"] -line-length = 70 - -[tool.ruff.lint] -select = ["E", "F", "I", "RUF100"] -ignore = ["E501"] # Line length is handled by Black \ No newline at end of file diff --git a/tinydb/update_db_v3.py b/tinydb/update_db_v3.py index 32311bfcb0..1c54b60e0d 100644 --- a/tinydb/update_db_v3.py +++ b/tinydb/update_db_v3.py @@ -2,4 +2,6 @@ with TinyDB("ten_countries.json") as countries_db: countries_table = countries_db.table(name="countries") - countries_table.update({"source": "Official estimate"}, doc_ids=[7, 9]) + countries_table.update( + {"source": "Official estimate"}, doc_ids=[7, 9] + ) From 5bb5ae4e1acadd208601e778bc714525e87a5be4 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 1 Feb 2026 16:31:53 +0000 Subject: [PATCH 08/10] Post TR2 Attempt 4 --- tinydb/create_db.py | 2 +- tinydb/read.py | 2 +- tinydb/update_db_v3.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tinydb/create_db.py b/tinydb/create_db.py index b1bdc11b19..a8edd50d4c 100644 --- a/tinydb/create_db.py +++ b/tinydb/create_db.py @@ -21,4 +21,4 @@ for row in reader: row["population"] = int(row["population"]) - countries_table.insert(row) + countries_table.insert(row) \ No newline at end of file diff --git a/tinydb/read.py b/tinydb/read.py index d86b0d06d4..d7ca3d81d5 100644 --- a/tinydb/read.py +++ b/tinydb/read.py @@ -14,4 +14,4 @@ pprint(countries_table.search(query_def)) pprint(countries_table.search(query["% of world"] >= 17)) pprint(countries_table.get(doc_ids=[9, 10])) -countries_db.close() +countries_db.close() \ No newline at end of file diff --git a/tinydb/update_db_v3.py b/tinydb/update_db_v3.py index 1c54b60e0d..a7fc3dcd08 100644 --- a/tinydb/update_db_v3.py +++ b/tinydb/update_db_v3.py @@ -3,5 +3,5 @@ with TinyDB("ten_countries.json") as countries_db: countries_table = countries_db.table(name="countries") countries_table.update( - {"source": "Official estimate"}, doc_ids=[7, 9] + {"source": "Official estimate"}, doc_ids=[7, 9] ) From 7a3e7968d2a4c20ee8257f8d4d34119ef02bc065 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 1 Feb 2026 16:35:36 +0000 Subject: [PATCH 09/10] Post TR2 Attempt 5 --- tinydb/create_db.py | 6 ++---- tinydb/read.py | 6 ++---- tinydb/update_db_v3.py | 4 +--- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tinydb/create_db.py b/tinydb/create_db.py index a8edd50d4c..8674508eb4 100644 --- a/tinydb/create_db.py +++ b/tinydb/create_db.py @@ -5,9 +5,7 @@ with TinyDB("countries.json", indent=4) as countries_db: countries_table = countries_db.table(name="countries") - countries_table.insert( - {"location": "Vatican City", "population": 501} - ) + countries_table.insert({"location": "Vatican City", "population": 501}) countries_table.insert_multiple( [ @@ -21,4 +19,4 @@ for row in reader: row["population"] = int(row["population"]) - countries_table.insert(row) \ No newline at end of file + countries_table.insert(row) diff --git a/tinydb/read.py b/tinydb/read.py index d7ca3d81d5..1616edc30c 100644 --- a/tinydb/read.py +++ b/tinydb/read.py @@ -7,11 +7,9 @@ countries_db = TinyDB("ten_countries.json") countries_table = countries_db.table(name="countries") query = Query() -query_def = (query.population > 220_000_000) & ( - query.population < 250_000_000 -) +query_def = (query.population > 220_000_000) & (query.population < 250_000_000) pprint(countries_table.search(query_def)) pprint(countries_table.search(query_def)) pprint(countries_table.search(query["% of world"] >= 17)) pprint(countries_table.get(doc_ids=[9, 10])) -countries_db.close() \ No newline at end of file +countries_db.close() diff --git a/tinydb/update_db_v3.py b/tinydb/update_db_v3.py index a7fc3dcd08..32311bfcb0 100644 --- a/tinydb/update_db_v3.py +++ b/tinydb/update_db_v3.py @@ -2,6 +2,4 @@ with TinyDB("ten_countries.json") as countries_db: countries_table = countries_db.table(name="countries") - countries_table.update( - {"source": "Official estimate"}, doc_ids=[7, 9] - ) + countries_table.update({"source": "Official estimate"}, doc_ids=[7, 9]) From cfbb354041b3a90d9d9a70f27a5f3069a5fcc396 Mon Sep 17 00:00:00 2001 From: eyrei123 Date: Sun, 1 Feb 2026 16:43:56 +0000 Subject: [PATCH 10/10] Post TR2 Attempt 6 --- tinydb/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tinydb/README.md diff --git a/tinydb/README.md b/tinydb/README.md new file mode 100644 index 0000000000..52492b1ebc --- /dev/null +++ b/tinydb/README.md @@ -0,0 +1,40 @@ +# TinyDB Tutorial Code (Real Python) + +This repository contains the downloadable code for the Real Python tutorial: [TinyDB: A Lightweight JSON Database for Small Projects](https://realpython.com/tinydb-python/) + +## Contents + +<<<<<<< HEAD + + +create\_db.py - SCRIPT file containing code from the CREATE section of the tutorial. + +read.py - REPL code file containing code from the READ section of the tutorial. + +update\_db.py - SCRIPT file containing code from the UPDATE section of the tutorial. + +update\_db\_v2.py - SCRIPT file containing code from the UPDATE section of the tutorial. + +update\_db\_v3.py - SCRIPT file containing code from the UPDATE section of the tutorial. + +delete.py - REPL code file containing code from the DELETE section of the tutorial. + + + +countries\_file.csv - File containing csv data to be converted to TinyDB documents. + +ten\_countries.json - File containing an existing JSON object representing ten TinyDB records in a countries table. + + + +README.md - This file + +======= +- `create.py` — All code from the **CREATE** section of the tutorial +- `read.py` — All code from the **READ** section of the tutorial +- `update.py` — All code from the **UPDATE** section of the tutorial +- `delete.py` — All code from the **DELETE** section of the tutorial +- `countries_file.csv` — CSV data used to create TinyDB documents +- `ten_countries.json` — Sample JSON file containing data for ten countries +- `README.md` — This file +>>>>>>> df2997f1b3bd2e296717c85dfa9ec8a08aaa2087