def insert_dict(self, value_dict, commit=False):
<EOL>for key in value_dict.keys():<EOL><INDENT>if key not in self.columns:<EOL><INDENT>raise ValueError("<STR_LIT>" % key)<EOL><DEDENT><DEDENT>insert_cols = []<EOL>value_set = []<EOL>for col in self.columns:<EOL><INDENT>if col in value_dict:<EOL><INDENT>insert_cols.append(col)<EOL>value_set.append(value_dict[col])<EOL><DEDENT><DEDENT>placeholders = '<STR_LIT:U+002CU+0020>'.join(["<STR_LIT>" % x for x in range(<NUM_LIT:1>, len(value_set) + <NUM_LIT:1>)])<EOL>query = self._assemble_with_columns('''<STR_LIT>''' + self.table + '''<STR_LIT>''' + placeholders + '''<STR_LIT>''' + self.pk + '''<STR_LIT:U+0020>''', insert_cols, *value_set)<EOL>result = self._execute(query, commit=commit)<EOL>if len(result) > <NUM_LIT:0>:<EOL><INDENT>if hasattr(result[<NUM_LIT:0>], self.pk):<EOL><INDENT>return getattr(result[<NUM_LIT:0>], self.pk)<EOL><DEDENT>else:<EOL><INDENT>return result[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
Execute an INSERT statement using a python dict

:value_dict:    A dictionary representing all the columns(keys) and 
    values that should be part of the INSERT statement
:commit:        Whether to automatically commit the transaction
:returns:       Psycopg2 result