tokyo.dbmdbm compatible interface to tokyo.cabinet.

New in version 0.5.0.

Platforms: POSIX

exception tokyo.dbm.error
Raised when an error specific to tokyo.dbm happens.
tokyo.dbm.whichdb(filename)
This function attempts to guess which of the 4 database types available — TCHDB, TCBDB, TCFDB or TCTDB — should be used to open a given file. Returns the type, raises error if filename is not a Tokyo Cabinet file or if its type is unknown.
tokyo.dbm.open(filename[, flag="r"[, mode=0o666]])

Open the database file filename and return a corresponding object. If the database file already exists, whichdb() is used to determine its type; if it does not exist, open() will try to deduce the database type from the filename extension; if this doesn’t work, TCHDB will be used.

The optional flag argument can be:

Value Meaning
'r' Open existing database for reading only (default)
'w' Open existing database for reading and writing
'c' Open database for reading and writing, creating it if it doesn’t exist
'n' Always create a new, empty database, open for reading and writing

The optional mode argument is the Unix mode of the file. It defaults to octal 0o666 (and will be modified by the prevailing umask).

The tokyo.dbm database types are wrappers for their corresponding tokyo.cabinet type. In addition to their counterparts methods and attributes, they implement collections.MutableMapping and should behave, for all intents and purposes, like dict.

class tokyo.dbm.TCHDB
Wrapper for tokyo.cabinet.HDB.
class tokyo.dbm.TCBDB

Wrapper for tokyo.cabinet.BDB.

get(key[, default=None[, duplicate=False]])
Return the value for key if key is in the database, else default. If default is not given, it defaults to None, so that this method never raises a KeyError. If key has duplicates and duplicate is False (default), return the value of the first record. If duplicate is True this method returns a tuple of all the values corresponding to key.
class tokyo.dbm.TCFDB
Wrapper for tokyo.cabinet.FDB.
class tokyo.dbm.TCTDB
Wrapper for tokyo.cabinet.TDB.

Previous topic

Table Database — TDB

Next topic

tokyo.tyrant — Python Tokyo Tyrant interface.

This Page