Skip to main content

a base class to tinydb

Project description

TinyDB base

I use TinyDB ... a lot and very often and i seem to be writing the same functions over and over. The idea behind the small project to provide a way for devs to easily create a data modal around tinydb without the need to build a base class.

How to install

the easiest way is to install through your dependency manager pip install tinyDbBase or if using pipenv install tinyDbBase.

How do i use this thing


This allows you to interact with Tinydb and both the root object and a table in the same object.

    from tinydb_base import Factory

    db = Factory('myData.json', 'myTable')
    db.db # equliervent to `TinyDB`.
    db.tbl # equliervent to `TinyDB.Table`.

    db.close() # closes the database file.


the idea is to import the base class and then derives into your own class. the idea is that you can simply create your data layer by creating a class that will work out what needs and just work.

    from tinydb_base import DatabaseBase

    class MyTable(DatabaseBase):

        def __init__(self, file='ds.json', table=__name__, requiredKeys=['title']):
            super().__init__(file=file, table=table, requiredKeys=requiredKeys)

    MyTable().create({'title': 'foobar'})

This will enable to accesses the base class, you can add your own custom functions. the will use the namespaces of the file within the project, but you can override this easily at an instance. another cool feature is that required keys this is key that must be present in every row which can also be changed.


Method Name attr Description
create dict this adds a new row to the database.
createMultiple list of dicts this added multiple rows
readAll returns a list obj
readById id this gets a row by the id
removeById id this removes a row by id


this works exactly the same way as DatabaseBase but by providing a salt you can encrypt using Fernet, it is suggested that you define your own salt

from tinydb_base.cryptography import DatabaseBaseSercure

class Diary(DatabaseBaseSercure):

    def __init__(self, file='ds.json', table=__name__, requiredKeys=['title'], salt='salt'):
        super().__init__(file=file, table=table, requiredKeys=requiredKeys, salt=salt)

obj = Diary(salt='thisisasalt')


this is a very simple interface that sets and gets values based on a tag. this can be used for things like settings. if the tag dose did not exist the class will raise tinydb_base.exceptions.RowNotFound_Exception

from tinydb_base.getSet import GetSet

class Settings(GetSet):

    def __init__(self, file: str = 'ds.json', table: str = __name__):

Settings().set('foo', 'bar')

Project details

Download files

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

Files for tinydb-baseClass, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size tinydb_baseClass-0.1.1-py3-none-any.whl (7.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size tinydb-baseClass-0.1.1.tar.gz (14.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page