I highly recommend @lrose 's first suggestion over the second. The first one allows your scripting to be much easier as well and lets you write in the pythonic way of trying to do something and then failing gracefully. The second way you have a race condition and could have two clients who both check for a redundant record, both don’t see one, and then both insert, leaving you with a redundant record.
Check out this post - Insert into database only if the entry doesn't exist - #2 by bkarabinchak.psi