You could use PyParsing. http://pyparsing.sourceforge.net/ People don't normally parse SQL unless they are building a query engine itself. Perhaps it is something else that you want? Could you elaborate the task?