PetDB#

class petdb.PetDB(root: str = None)#

The main class of PetDB.

The PetDB class is responsible for storing and managing this database’s collections.

Collection access is provided by forwarding all unknown method calls and property access operations to the PetDB.collection() method by implementing PetDB.__getattr__() and PetDB.__getitem__().

Parameters:

root – The root path where the folder for storing will be created

classmethod get(root: str = None)#
collection(name: str) PetCollection#

Get access to the specific collection with the given name.

If the collection hasn’t been accessed yet, a new collection instance will be created. Otherwise, the previously created collection instance will be returned.

Parameters:

name – The name of the collection.

Returns:

PetCollection

collections() list[str]#

Get the names of all collections in the database.

Returns:

a list of collections names

drop_collection(name: str)#

Deletes the collection with the given name

Parameters:

name – The name of the collection to delete

drop() None#

Drop all collections from the database. CANNOT BE REVERSED!

reload()#
__getattr__(name: str) PetCollection#

Alias for PetDB.collection()

Returns:

PetCollection

__getitem__(name: str) PetCollection#

Alias for PetDB.collection()

Returns:

PetCollection