Search code examples
pythonpython-3.xapiberkeley-dbberkeley-db-xml

Is there a python binding to the Berkeley DB XML database?


I'm trying to migrate some perl code to python and it uses Sleeypcat::DbXml 'simple' to get read access to a .dbxml file, creates a XmlManager, calls createQueryContext, openContainer and query to get an XmlValue. I have found https://pypi.org/project/berkeleydb/ to support the Berkeley DB in general, but it has no mention of this XML layer. Is there an existing API I can use in python 3?


Solution

  • Berkeley dbxml does come with a Pyhon bindings. I ended up having to make modifications to the SWIG interface files to get it to run with Python3. If you are interested in building for a recent Python, you will need to make some modifications to the Python interface file. Specifically, you have to

    • redefine PYSTR_* macros to use unicode strings
    • make changes to the initialization code to return the module
    • update the Python 3 iterator code to use __next__ via a %rename pragma
    • potentially add code for missing objects an changed interfaces, e.g. I added an XmlResultsIterator, and added som code to XmlManager to let me reindex containers.

    You then need to regenerate the swig interface and recompile the module. I don't know StackOverflow's policy on posting patches, but if it's allowed I'd be happy to post the patches that I created for dbxml 6.1.4 and Python 3.9 for you. Getting it all compiled is a little bit of work, but very doable.