from mako import lexer, codegen
lexer = lexer.Lexer('${foo}', '')
node = lexer.parse()
compiler = lambda : None
compiler.reserved_names = set()
identifiers = codegen._Identifiers(compiler, node)
Mako Template Variable Names