There's quite a neat little library with an impressive amount of functionality for interacting with Keepass, called "File::KeePass;".
Here's a copy of the script itself: https://gist.github.com/kjbweb/38508fd92669101ec1fca4bea62bc...
It works on Mac's too, so I've been told.