Skip to main content

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

Project description

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

|Build Status| |Coverage| |Version|

Quick Links
***********

- `Example Code`_
- `Supported Python Versions`_
- `Documentation <http://tinydb.readthedocs.org/>`_
- `Changelog <https://tinydb.readthedocs.io/en/latest/changelog.html>`_
- `Extensions <https://tinydb.readthedocs.io/en/latest/extensions.html>`_
- `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 1200 lines of code (with about 40%
documentation) and 1000 lines of tests. For comparison: Buzhug_ has about 2500
lines of code (w/o tests), CodernityDB_ has about 7000 lines of code
(w/o 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 <http://api.mongodb.org/python/current/>`_) nor any dependencies
from PyPI.

- **works on Python 2.7 and 3.3 – 3.6 and PyPy:** 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
<https://tinydb.readthedocs.io/>`_. You can also discuss everything related
to TinyDB like general development, extensions or showcase your TinyDB-based
projects on the `discussion forum <http://forum.m-siemens.de/.>`_.

Supported Python Versions
*************************

TinyDB has been tested with Python 2.7, 3.3 - 3.6 and PyPy.

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 <= 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}]

>>> # 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 <https://github.com/msiemens/tinydb/>`_ on Github,
create a new branch off the `master` branch and start making your changes
(known as `GitHub Flow <https://guides.github.com/introduction/flow/index.html>`_)
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:: http://img.shields.io/travis/msiemens/tinydb.svg?style=flat-square
:target: https://travis-ci.org/msiemens/tinydb
.. |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: http://labs.codernity.com/codernitydb/
.. _MongoDB: http://mongodb.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinydb-3.13.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinydb-3.13.0-py2.py3-none-any.whl (17.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file tinydb-3.13.0.tar.gz.

File metadata

  • Download URL: tinydb-3.13.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for tinydb-3.13.0.tar.gz
Algorithm Hash digest
SHA256 a05c4c81e6e867c4f8a2e51c5236d0d897019aa5e9296f5947455b0bdd3c519d
MD5 2824877e9ecfd9db5b64fdf079819358
BLAKE2b-256 b2b7c88e4900d542e41b92213c8eeb927e5e65c2806feb045428883165ea19ff

See more details on using hashes here.

File details

Details for the file tinydb-3.13.0-py2.py3-none-any.whl.

File metadata

  • Download URL: tinydb-3.13.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for tinydb-3.13.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 260b1f69168a24518af63f0270c72dc026476607016a0105aef6a966d8d2fbdc
MD5 a4e5b06f8ffee4090f309d294d6afe2e
BLAKE2b-256 d7f90e871cbf0da678cf1780609dc6aef26a5ed544c86733fc1ceaf134fce52c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page