There is already function in code that make the same thing: 
openstack.common.importutils.try_import()