Try this, it's the safest way:
import ast
ast.literal_eval("{'x':1, 'y':2}")
=> {'y': 2, 'x': 1}
All the solutions based in eval() are dangerous, malicious code could be injected inside the string and get executed.
According to the documentation the expression gets evaluated safely. Also, according to the source code, literal_eval parses the string to a python AST (source tree), and returns only if it is a literal. The code is never executed, only parsed, so there is no reason for it to be a security risk.