Skip to main content
https://raw.githubusercontent.com/msiemens/tinydb/master/artwork/logo.png

Build Status Coverage Version

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

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

>>> 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 <= 30))
[{'name': 'John', 'age': 22}]

>>> # 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

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

Using Middlewares

>>> 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 ☺

Release files for tinydb 4.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tinydb 4.9.0
File Size Uploaded
tinydb-4.9.0.tar.gz 32.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tinydb 4.9.0
File Interpreter ABI Platform
tinydb-4.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.7 kB

Release files / tinydb-4.9.0.tar.gz

Download URL tinydb-4.9.0.tar.gz
Size 32.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6928b1fa785186bda7952a0ba05aaeedc883ede565ca9c7d608de44e5e75de70
BLAKE2b-256 checksum
How to use checksums
01e9d30dd8b1b88a75ec3e464eb81feee514ccf97f50bd306d198959e6733210
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / tinydb-4.9.0-py3-none-any.whl

Download URL tinydb-4.9.0-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
111f1f680978a1b7c534d698dd1d76739ff31c74c27fd26a111140b51d8b35d6
BLAKE2b-256 checksum
How to use checksums
54ef321cb77b49bc26f36ed1c85d55cd8e80f8f81e5e183b769abf67386c257a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

4.9.0 This release

2 release files

4.8.2

2 release files

4.8.1

2 release files

4.8.0

2 release files

4.7.1

2 release files

4.7.0

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.2

2 release files

4.5.1

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.15.2

2 release files

3.15.1

2 release files

3.15.0

2 release files

3.14.2

2 release files

3.14.1

2 release files

3.13.0

2 release files

3.12.2

2 release files

3.11.1

2 release files

3.11.0

2 release files

3.10.0

2 release files

3.9.0

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.0

1 release file

3.6.0

1 release file

3.5.0

1 release file

3.4.1

1 release file

3.4.0

1 release file

3.3.1

1 release file

3.3.0

1 release file

3.2.3

1 release file

3.2.2

1 release file

3.2.1

1 release file

3.2.0

1 release file

3.1.3

1 release file

3.1.2

1 release file

3.1.1

1 release file

3.1.0

1 release file

3.0.0

1 release file

2.4

1 release file

2.3.2

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.2

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

2 release files

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page