tinydb is a free, open source databases project written in Python and released under MIT. It has 7,567 GitHub stars, 629 forks and 13 open issues, and was last pushed yesterday. On this registry it ranks #110 of 203 tracked projects in Databases, with 5 head-to-head comparisons available.

What is tinydb?

TinyDB is a lightweight, document-oriented database written in pure Python that stores records as dictionaries in a local JSON file, aimed at small applications that would be overwhelmed by a SQL database or an external database server.

What it is

TinyDB lives in the Python ecosystem as an embedded database in the literal sense: the database is a library inside the application process, not a service running somewhere else. Documents are ordinary Python dict objects, storage defaults to a JSON file on disk, and the implementation is pure Python with no dependencies from PyPI. The specific thing it replaces is the setup in which a small application has to install, configure, secure, and keep running a database daemon, or reach a remote one through a driver such as PyMongo.

The problem it solves is the mismatch between small applications and server-grade databases. A script, a desktop tool, a prototype, or a test harness that needs to store a few thousand documents does not need a network protocol, a connection pool, or an operations story. TinyDB offers query, tables, and persistence in 1800 lines of source code, about 40 percent of it documentation, backed by 1600 lines of tests and 100 percent coverage. It is tested on Python 3.8 through 3.13 and PyPy3, and released under the MIT licence.

Key capabilities

  • Single-call document storage: db = TinyDB('/path/to/db.json') opens the file, and db.insert({'int': 1, 'char': 'a'}) writes a document into it.
  • A query language built on Query(): field comparisons, logical combination with & and |, negation with ~, and field transformation through User.age.map(lambda x: x + x).
  • Predicate checks through where(...).matches(regex) for regular expressions and where(...).test(your_test_func) for custom Python callables.
  • Multiple tables inside one database, created with db.table('name') and read back through table.all().
  • Pluggable storages and middlewares: JSONStorage is the default, and passing storage=CachingMiddleware(JSONStorage) to the TinyDB constructor changes how storage behaves.
  • Pure Python with no external server and no PyPI dependencies, documented at tinydb.readthedocs.org alongside a changelog and an extensions list.

Who uses it and how

  • Small applications and scripts that need persistence but cannot justify provisioning a database server or a client/server driver.
  • Prototypes and internal tools where the store is a plain db.json file that can be inspected, copied, or handled like any other file.
  • Test and development setups that create an isolated database per run without a container, daemon, or network dependency.
  • Environments pinned to Python 3.8 through 3.13 or PyPy3, or projects that need to change storage behaviour through custom storages and middlewares.

Getting started

TinyDB ships as the pure-Python tinydb package, with no external dependencies and no server to run. The documented entry point is from tinydb import TinyDB, Query followed by db = TinyDB('/path/to/db.json'), and full installation and API guidance lives at tinydb.readthedocs.org.

How it compares

Where MongoDB requires a server and PyMongo requires a driver to reach it, TinyDB runs inside the Python process with neither and pulls nothing from PyPI. Licencing is MIT with no paid tier, self-hosting means installing a package rather than operating a service, and data ownership is immediate because the documents are a file the application already owns.

When to use it — and when not to

Self-hosters operate nothing beyond their own Python environment: no database server, no external dependency, no container. The honest limitation is project status, as TinyDB is in maintenance mode, mature and stable but with no significant new features or architectural changes planned and releases limited mainly to bugfixes and community contributions. Teams that need an active feature roadmap, a client/server architecture, or a database built for heavy multi-process write contention should look elsewhere.

project readme (upstream, from github) — read inline

.. image:: https://raw.githubusercontent.com/msiemens/tinydb/master/artwork/logo.png :height: 150px

|Build Status| |Coverage| |Version|

Quick Links


  • Example Code_
  • Supported Python Versions_
  • Documentation _
  • Changelog _
  • Extensions _
  • Contributing_

Introduction


TinyDB is a lightweight document oriented database optimized for your happiness :) It's written in pure Python and has no external dependencies. The target are small apps that would be blown away by a SQL-DB or an external database server.

TinyDB is:

  • tiny: The current source code has 1800 lines of code (with about 40% documentation) and 1600 lines tests.

  • document oriented: Like MongoDB_, you can store any document (represented as dict) in TinyDB.

  • optimized for your happiness: TinyDB is designed to be simple and fun to use by providing a simple and clean API.

  • written in pure Python: TinyDB neither needs an external server (as e.g. PyMongo _) nor any dependencies from PyPI.

  • works on Python 3.8+ and PyPy3: TinyDB works on all modern versions of Python and PyPy.

  • powerfully extensible: You can easily extend TinyDB by writing new storages or modify the behaviour of storages with Middlewares.

  • 100% test coverage: No explanation needed.

To dive straight into all the details, head over to the TinyDB docs . You can also discuss everything related to TinyDB like general development, extensions or showcase your TinyDB-based projects on the discussion forum .

Supported Python Versions


TinyDB has been tested with Python 3.8 - 3.13 and PyPy3.

Project Status


This project is in maintenance mode. It has reached a mature, stable state where significant new features or architectural changes are not planned. That said, there will still be releases for bugfixes or features contributed by the community. Read more about what this means in particular here _.

Example Code


.. code-block:: python

>>> from tinydb import TinyDB, Query
>>> db = TinyDB('/path/to/db.json')
>>> db.insert({'int': 1, 'char': 'a'})
>>> db.insert({'int': 1, 'char': 'b'})

Query Language

.. code-block:: python

>>> User = Query()
>>> # Search for a field value
>>> db.search(User.name == 'John')
[{'name': 'John', 'age': 22}, {'name': 'John', 'age': 37}]

>>> # Combine two queries with logical and
>>> db.search((User.name == 'John') & (User.age >> # Combine two queries with logical or
>>> db.search((User.name == 'John') | (User.name == 'Bob'))
[{'name': 'John', 'age': 22}, {'name': 'John', 'age': 37}, {'name': 'Bob', 'age': 42}]

>>> # Negate a query with logical not
>>> db.search(~(User.name == 'John'))
[{'name': 'Megan', 'age': 27}, {'name': 'Bob', 'age': 42}]

>>> # Apply transformation to field with `map`
>>> db.search((User.age.map(lambda x: x + x) == 44))
>>> [{'name': 'John', 'age': 22}]

>>> # More possible comparisons:  !=    =
>>> # More possible checks: where(...).matches(regex), where(...).test(your_test_func)

Tables

.. code-block:: python

>>> table = db.table('name')
>>> table.insert({'value': True})
>>> table.all()
[{'value': True}]

Using Middlewares

.. code-block:: python

>>> from tinydb.storages import JSONStorage
>>> from tinydb.middlewares import CachingMiddleware
>>> db = TinyDB('/path/to/db.json', storage=CachingMiddleware(JSONStorage))

Contributing


Whether reporting bugs, discussing improvements and new ideas or writing extensions: Contributions to TinyDB are welcome! Here's how to get started:

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug
  2. Fork the repository _ on Github, create a new branch off the master branch and start making your changes (known as GitHub Flow _)
  3. Write a test which shows that the bug was fixed or that the feature works as expected
  4. Send a pull request and bug the maintainer until it gets merged and published ☺

.. |Build Status| image:: https://img.shields.io/azure-devops/build/msiemens/3e5baa75-12ec-43ac-9728-89823ee8c7e2/2.svg?style=flat-square :target: https://dev.azure.com/msiemens/github/_build?definitionId=2 .. |Coverage| image:: http://img.shields.io/coveralls/msiemens/tinydb.svg?style=flat-square :target: https://coveralls.io/r/msiemens/tinydb .. |Version| image:: http://img.shields.io/pypi/v/tinydb.svg?style=flat-square :target: https://pypi.python.org/pypi/tinydb/ .. _Buzhug: http://buzhug.sourceforge.net/ .. _CodernityDB: https://github.com/perchouli/codernitydb .. _MongoDB: http://mongodb.org/

Frequently asked questions

Is tinydb free to use?

tinydb is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does tinydb do?

TinyDB is a lightweight document oriented database optimized for your happiness :)

What is tinydb written in?

tinydb is primarily written in Python. Its source is publicly available at https://github.com/msiemens/tinydb, and it has 7,567 GitHub stars.