API Reference

aiodbm.error = (<class 'dbm.error'>, <class 'OSError'>)

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

A tuple containing the exceptions that can be raised by each of the supported modules, with a unique exception also named dbm.error as the first item — the latter is used when dbm.error is raised.

Example usage:

try:
    async with open("example.dbm", "c") as db:
        ...
except aiodbm.error as ex:
    print(f"Error when trying to open the database: {ex}")
aiodbm.open(file: str | Path, *args, **kwargs) Database

Create and return a proxy to a DBM database.

Parameters:

file – filename for the DBM database

Returns:

DBM database proxy object

Usage A:

async with open("example.dbm", "c") as db:
    ...

Usage B:

db = await open("example.dbm", "c"):
...
await db.close()
async aiodbm.whichdb(filename: str | Path) str | None

Return the name of the DBM implementation, which can be used for opening the given file.

Or if the file can not be read return None. Or if the file is not in a known DBM format, return an empty string.

class aiodbm.Database

A DBM database.

Not that some methods are available on GDBM only. You can check if your database is GDBM with is_gdbm().

async close() None

Complete queued operations and close the database.

async delete(key: str | bytes) None

Delete given key.

async exists(key: str | bytes) bool

Return True when the given key exists, else False.

async firstkey() bytes

Return the first key for looping over all keys. GDBM only.

async get(key: str | bytes, default: bytes | None = None) bytes | None

Get the value of key. If the key does not exist, return default.

property is_gdbm: bool

Return True if this is a GDBM database.

async keys() List[bytes]

Return existing keys.

async keys_iterator() AsyncGenerator[bytes, None]

Return all keys as async generator. GDBM only.

In contrast to keys() this method will not load the full list of keys into memory, but instead fetch keys one after the other.

Note that the order of keys is implementation specific and can not be relied on.

Usage example:

async for key in db.keys_iterator():
    print(key)
async nextkey(key: str | bytes) bytes | None

Return the next key, when looping over all keys. Or return None, when the end of the loop has been reached. GDBM only.

async reorganize() None

Reorganize the database. GDBM only.

async set(key: str | bytes, value: str | bytes) None

Set key to hold the value. If key already holds a value, it is overwritten.

async setdefault(key: str | bytes, default: bytes) bytes

Set key to hold the default value, if it does not yet exist. Or return current value of existing key.

async sync() None

When the database has been opened in fast mode, this method forces any unwritten data to be written to the disk. GDBM only.