10

I would like to use the dbm module on my Windows machine, but it is currently only supported on Unix. http://docs.python.org/library/dbm.html

Does anyone know of a similar module with similar syntax or a workaround to get dmb functional on windows? Being able to access a database written to the hard drive much like how I code to access a dictionary would be great. Thank you for your help!

2

4 Answers 4

5

Actually, after more googling around, I found this:

http://docs.python.org/library/anydbm.html#module-anydbm

I've tried this on windows and it seems to be working fine =)

Sign up to request clarification or add additional context in comments.

4 Comments

If you're benchmarking with Python 2 on Windows, you're in for a treat when you switch to Python 3, as dbm falls back to dumbdbm, which is Python's own self-proclaimedly lame dbm implementation, whereas on Python 2 it supports the much faster Berkeley DB. To avoid dumbdbm on Py3/Win, I've used both LMDB and semidbm, and ended up writing my own workaround, Petite
docs.python.org/3/library/anydbm.html: 404 Not Found. Did they remove it? How to use gnu dbm on windows?
5

2025 Update

As of Python 3.13, the standard dbm module uses sqilte as its backend -

This module uses the standard library sqlite3 module to provide an SQLite backend for the dbm module. The files created by dbm.sqlite3 can thus be opened by sqlite3, or any other SQLite browser, including the SQLite CLI.

This presumably means a consistent improved performance across platforms.

Original Answer

If Python 3 is of relevance, I'd go for an external k-v solution, as dumbdbm is no joy.

Some pure Python options:

  • semidbm - A faster alternative to dumbdbm, Python standard library only, pip and go. The one I'd go for if I want to ensure portability and availability to users.

  • PickleDB - Uses json to serialize data. Standrad library only, I haven't benchmarked but I suspect it's slower than semidbm because of the serialization overhead.

  • Petite DB - My own simple workaround using Python's zipfile module. Basic testing in the books but it's not production ready.

There are also Python wrappers to LMDB, UnQLite and SQLite4 LSM, all of which support Windows, though the SQLite4 bindings weren't tested.

The latter two are by Charles Leifer, who is both savvy with k-v stores and an avid Python developer (see Peewee).

As far as LMDB, I've tried it for a while. No complaints, but it uses a transactional model, where you can't use it dictionary-style like with other dbm's, unless you subclass/compose/submit a pull request etc. Also, it explicitly doesn't utilize compression (see also) which was something I was interested in.

So LMDB just didn't quite fit my specific needs. It does seem to be highly capable, the bindings worked fine, and installing them was untroublesome (pip worked for me, had no need to install LMDB seperately or any nuisance to that effect).

Comments

3

I think anydbm on Windows will only load dumbdbm, since all the other modules appear to be Unix only. According to the Python documentation...

"The dumbdbm module is intended as a last resort fallback for the anydbm module when no more robust module is available. The dumbdbm module is not written for speed and is not nearly as heavily used as the other database modules."

Comments

3

Based on the following test on a Windows 7 system using Python 2.7.2 it appears that dbhash is supported on Windows instalations.

import os

import anydbm

import whichdb

file = os.curdir + '/testdbm'   # define a test file name in the current directory

d = anydbm.open(file, 'c')      # create a new database using the test file name

db_type = whichdb.whichdb(file) # get the dbm database type

print(db_type)                  # display the result

'dbhash'

1 Comment

This answer is obsolete. dbhash was removed in Python 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.