This is the full documentation for the entire liteDB API.

Database

class litedb.Database(abc.ABC)

Database provides a standard base class that all liteDB instances should implement.

__len__()

The number of items in this database.

__iter__()

Allows iteration over all of the class types in this database.

__repr__()

Print a summary of all the tables in this database.

tables

Returns a ValuesView of the tables in this database.

insert(item: object)
Parameters:item (object) – A Python object.

Inserts and indexes the given item.

select(cls)
Parameters:cls (class) – A Python class definition, such as Decimal.

Returns a Table that corresponds to the given class type.

MemoryDatabase

class litedb.MemoryDatabase(litedb.Database)

MemoryDatabase is an in-memory implementation of Database. All items are stored in memory, and are discarded when the database is no longer referenced in the script.

DiskDatabase

class litedb.DiskDatabase(litedb.Database)

DiskDatabase is a persistent implementation of Database that resides on the filesystem.

__init__(directory: str[, config=Config()])
Parameters:directory (str) – Valid filesystem path.

The path on disk where DiskDatabase will write to. If data is already present in this location, it will be loaded into this database.

Parameters:config (Config) – A Config instance.

Allows the user to specify a custom paging configuration in order to maximize performance.

modified

Returns True if there are changes to this database that have not yet been synchronized.

commit()

Synchronizes all cached items to disk for the entire database.

Table

class litedb.Table(abc.ABC)

Table provides a standard base class which all liteDB tables should implement.

__len__()

The number of items in this table.

__iter__()

Allows iteration over all of the items in this table.

__repr__()

Prints out useful information about this table.

indexes

Returns a list of valid index names for this class type.

retrieve(**kwargs)
Parameters:kwargs – Keyword arguments that describe item indexes.

Returns a generator of items that conform to the index constraints laid out by the keyword arguments. See the data retrieval section for more information on this.

delete(**kwargs)
Parameters:kwargs – Keyword arguments that describe item indexes.

Removes all items in this table that conform to the index constraints laid out by the keyword arguments. See the data removal section for more information on this.

clear()

Removes all items from this table.

MemoryTable

class litedb.MemoryTable(litedb.Table)

MemoryTable is an in-memory implementation of Table.

Note

You will not ever need to instantiate this class!

PersistentTable

class litedb.PersistentTable(litedb.Table)

PersistentTable is a persistent implementation of Table.

Note

You will not ever need to instantiate this class!

modified

Returns True if there are changes to this table that have not yet been synchronized.

commit()

Synchronizes this table’s in-memory item/index cache to disk.

Config

class litedb.Config

Config allows customization of the DiskDatabase paging system.

Warning

Once you have defined a custom configuration for a DiskDatabase instance, it is recommended that you do not change it!

__init__(page_size: int = 512, page_cache: int = 512)
Parameters:page_size (int) – Number of items to store in each page

A higher page size means there is less overhead manipulating pages, but large sizes can also result in more memory usage. The recommended default is 512.

Parameters:page_cache (in) – Number of item pages to retain in memory.

A higher item page count means fewer I/O calls, but also more memory usage. The recommended default is 512.