PyFlex is a lexical analyzer generator (also known as scanner generator) for Python, written in Python. Take as a base Jflex.