Peter McCurdy, 11 June 2009
I recently needed to parse some SQL in a Python program, so I started looking for a suitable module. It then turns out that there are about ten million different such modules, and nobody ever seems to particularly compare them much. My criteria were that it had to be reasonably powerful (SQL is tricky to parse), reasonably integrated with Python (separate compilation steps would be a pain, and a separate grammar file isn’t ideal), and ideally not have a totally hideous syntax.
I started with the promising-sounding python-sqlparse module, but it turns out that it doesn’t actually do much parsing of the SQL – it’ll split multiple SQL statements up well enough, but doesn’t give much in the way of further details. This left me looking at the surprisingly large number of different Python parsing modules. Since I couldn’t find anyone else comparing any of these, I figured I might save some people some time in the future and publish my impressions.
Note: this is all highly biased. Your needs may not match mine, I haven’t yet actually written any programs using any of these, and all my information is gleaned from a superficial look at the various project websites. In other words, reasonable people could differ on these interpretations, and I may be totally off-base on a few.