Package: micropython-tinydb
Quick LinksExample CodeSupported Python VersionsDocumentationChangelogExtensionsContributingIntroductionThis is the Micropython port of TinyDB.
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:LikeMongoDB, you can store any document
(represented asdict) 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.5+, PyPy and Micropython: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 theTinyDB docs. You can also discuss everything related
to TinyDB like general development, extensions or showcase your TinyDB-based
projects on thediscussion forum.Supported Python VersionsTinyDB has been tested with Python 3.5 - 3.8, PyPy and Micropython.Example Code>>>fromtinydbimportTinyDB,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}]>>># 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>>>fromtinydb.storagesimportJSONStorage>>>fromtinydb.middlewaresimportCachingMiddleware>>>db=TinyDB('/path/to/db.json',storage=CachingMiddleware(JSONStorage))What is different in this portBecaused Micropython does not have collections.abc.Mapping I had to remove support for custom documents
until I figure out a way to implement them without inheriting from Mapping.For the same reason, invalid dict insertions can no longer be detected.Other than these everything else works.ContributingWhether reporting bugs, discussing improvements and new ideas or writing
extensions: Contributions to TinyDB are welcome! Here’s how to get started:Check for open issues or open a fresh issue to start a discussion around
a feature idea or a bugForkthe repositoryon Github,
create a new branch off themasterbranch and start making your changes
(known asGitHub Flow)Write a test which shows that the bug was fixed or that the feature works
as expectedSend a pull request and bug the maintainer until it gets merged and
published â˜º