API for semidbm

semidbm.db.open(filename, flag='r', mode=438, verify_checksums=False)[source]

Open a semidbm database.

Parameters:
  • filename – The name of the db. Note that for semidbm, this is actually a directory name. The argument is named filename to be compatible with the dbm interface.
  • flag

    Specifies how the db should be opened. flag can be any of these values:

    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
  • mode – Not currently used (provided to be compatible with the dbm interface).
  • verify_checksums – Verify the checksums for each value are correct on every __getitem__ call (defaults to False).
class semidbm.db._SemiDBM(dbdir, renamer, data_loader=None, verify_checksums=False)[source]
Parameters:dbdir – The directory containing the dbm files. If the directory does not exist it will be created.
close(compact=False)[source]

Close the db.

The data is synced to disk and the db is closed. Once the db has been closed, no further reads or writes are allowed.

Parameters:compact – Indicate whether or not to compact the db before closing the db.
compact()[source]

Compact the db to reduce space.

This method will compact the data file and the index file. This is needed because of the append only nature of the index and data files. This method will read the index and data file and write out smaller but equivalent versions of these files.

As a general rule of thumb, the more non read updates you do, the more space you’ll save when you compact.

keys()[source]

Return all they keys in the db.

The keys are returned in an arbitrary order.

sync()[source]

Sync the db to disk.

This will flush any of the existing buffers and fsync the data to disk.

You should call this method to guarantee that the data is written to disk. This method is also called whenever the dbm is close()‘d.