TinyDB is a lightweight, document-oriented NoSQL database for Python, optimized for simplicity and happiness. It stores data in human-readable JSON files and is designed for small applications that don't require a full-featured database server. Currently in maintenance mode (v4.8.2), it focuses on bugfixes and community-contributed features, with new releases for minor updates and patches.
pip install tinydbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a TinyDB database, insert, query, update, and delete documents using `TinyDB` and `Query` objects. It saves data to a local JSON file.
Consult the TinyDB v4.0 upgrade guide for a full list of changes and adapt code accordingly. Ensure Python 3.8+ is used.
Update query methods to the new syntax. If using `SmartCacheTable` or advanced serialization, install `tinydb-smartcache` or `tinydb-serialization` respectively.
For document fields that might conflict with future query operation names, use dictionary-style access: `Query()['field_name']` instead of `Query().field_name`.
For multi-process/multi-thread scenarios, consider using `tinyrecord` (an external library) or ensuring proper locking mechanisms are implemented outside TinyDB to prevent race conditions.
For inserting multiple documents, use `db.insert_multiple()` with a list of documents to improve performance significantly.
pip install tinydb
from tinydb import TinyDB, Query
db.get(Query().name == 'Alice')
db.update({'age': 31}, Query().name == 'Alice')db.insert_multiple([{'name': 'Alice'}, {'name': 'Bob'}])No dependency data recorded yet.