 <p>For basic types like <code>int</code>, <code>NoneType</code>, <code>dict</code> and other simple cases there's a natural "factory" in Python - it is <code>ast.literal_eval</code>.</p> <pre><code>&gt;&gt;&gt; import ast &gt;&gt;&gt; ast.literal_eval('None') is None True &gt;&gt;&gt; ast.literal_eval('{1: 2}') {1: 2} &gt;&gt;&gt; ast.literal_eval('1e6') 1000000.0 </code></pre> <p>So if your data is a superposition of basic types (something json-like for instance), then you can parse it with single <code>ast.literal_eval</code> call. Unlike <code>exec</code> and <code>eval</code>, <code>ast.literal_eval</code> is much safer as you can't run any code with it.</p>