This is the full documentation for the entire liteDB API.
Database¶
-
class
litedb.Database(abc.ABC)¶ Databaseprovides a standard base class that allliteDBinstances 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
ValuesViewof 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
Tablethat corresponds to the given class type.
-
MemoryDatabase¶
-
class
litedb.MemoryDatabase(litedb.Database)¶ MemoryDatabaseis an in-memory implementation ofDatabase. 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)¶ DiskDatabaseis a persistent implementation ofDatabasethat resides on the filesystem.-
__init__(directory: str[, config=Config()])¶ Parameters: directory (str) – Valid filesystem path. The path on disk where
DiskDatabasewill write to. If data is already present in this location, it will be loaded into this database.Parameters: config (Config) – A Configinstance.Allows the user to specify a custom paging configuration in order to maximize performance.
-
modified¶ Returns
Trueif 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)¶ Tableprovides a standard base class which allliteDBtables 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)¶ MemoryTableis an in-memory implementation ofTable.Note
You will not ever need to instantiate this class!
PersistentTable¶
-
class
litedb.PersistentTable(litedb.Table)¶ PersistentTableis a persistent implementation ofTable.Note
You will not ever need to instantiate this class!
-
modified¶
Returns
Trueif 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¶ Configallows customization of theDiskDatabasepaging system.Warning
Once you have defined a custom configuration for a
DiskDatabaseinstance, 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.
-