database – btree database

Classes

class database.DataBase(filename='/var/upy.db')

Opens (or creates if does not exist) a database from a file. If the btree module does not exist, or the initialization fails, a fallback database (backed by a dictionary) is created.

close()

Closes the database and frees all the resources. When the database is not needed any more, do not forget to call this method to prevent data corruption. No further calls are possible after the invocation of this method.

__contains__(key):

Check whether the key is in the database.

clean():

Remove all entries from the database.

add(key, value):

Add the key-value pair to the database. The value must be a bytes-like object.

remove(key):

Removes the key from the database. Returns True if the key was present in the database and has been removed. Otherwise, returns False.

get(key)

Return the value associated with the key.

pop(key)

The combination of get(key) with the following remove(key).

get_str(key)

Return the value for the key as a string.

contains(key)

The same as key in self

empty()

Checks if the database is empty.